Skip to content

Ab#70785 #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: release-1.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# v1.7.0

## Features

### CLI

- `stores import csv`: supports interactive credential input, as well as input via flags and environmental
variables. [docs](docs/kfutil_stores_import_csv.md)

## Fixes

### CLI

- `stores import csv`: providing a `Password(/StorePassword)` does not crash CLI.
- `stores import csv`: results CSV retains input header ordering.
- `stores import csv`: Handle `BOM` characters in an input CSV file.
- `store-types create`: URL encode `-b` parameter when passed.
- `store-types create`: Initialize logger before fetching store-type definitions.
- `stores rot`: Re-enabled and improved logging.

# v1.6.2

## Fixes
Expand Down
4 changes: 4 additions & 0 deletions cmd/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const (
DebugFuncExit = "exiting: %s"
DebugFuncCall = "calling: %s"
MinHttpTimeout = 3

EnvStoresImportCSVServerUsername = "KFUTIL_CSV_SERVER_USERNAME"
EnvStoresImportCSVServerPassword = "KFUTIL_CSV_SERVER_PASSWORD"
EnvStoresImportCSVStorePassword = "KFUTIL_CSV_STORE_PASSWORD"
)

var ProviderTypeChoices = []string{
Expand Down
28 changes: 17 additions & 11 deletions cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http"
"os"
"path/filepath"
"slices"
"strconv"
"time"

Expand Down Expand Up @@ -132,7 +133,7 @@ func csvToMap(filename string) ([]map[string]string, error) {

// Populate the map with data from the row
for i, column := range header {
rowMap[column] = row[i]
rowMap[column] = stripAllBOMs(row[i])
}

// Append the map to the data slice
Expand Down Expand Up @@ -282,27 +283,32 @@ func logGlobals() {

}

func mapToCSV(data []map[string]string, filename string) error {
file, err := os.Create(filename)
if err != nil {
return err
func mapToCSV(data []map[string]string, filename string, inputHeader []string) error {
file, fErr := os.Create(filename)
if fErr != nil {
return fErr
}
defer file.Close()

writer := csv.NewWriter(file)
defer writer.Flush()

// Write the header using keys from the first map
var header []string
if len(data) > 0 {
var header = inputHeader
if len(header) <= 0 && len(data) > 0 {
for key := range data[0] {
header = append(header, key)
}
if err := writer.Write(header); err != nil {
return err
header = append(header, stripAllBOMs(key))
}
}

errorColFound := slices.Contains(header, "Errors")
if !errorColFound {
header = append(header, "Errors")
}
if hErr := writer.Write(header); hErr != nil {
return hErr
}

// Write map data to CSV
for _, row := range data {
var record []string
Expand Down
Loading
Loading