Skip to content

Commit 99c3394

Browse files
authored
Merge be591a2 into 6cc2538
2 parents 6cc2538 + be591a2 commit 99c3394

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+251
-131
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# v1.7.0
2+
3+
## Features
4+
5+
### CLI
6+
7+
- `stores import csv`: supports interactive credential input, as well as input via flags and environmental
8+
variables. [docs](docs/kfutil_stores_import_csv.md)
9+
10+
## Fixes
11+
12+
### CLI
13+
14+
- `stores import csv`: providing a `Password(/StorePassword)` does not crash CLI.
15+
- `stores import csv`: results CSV retains input header ordering.
16+
117
# v1.6.2
218

319
## Fixes

cmd/constants.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ const (
3434
DebugFuncExit = "exiting: %s"
3535
DebugFuncCall = "calling: %s"
3636
MinHttpTimeout = 3
37+
38+
EnvStoresImportCSVServerUsername = "KFUTIL_CSV_SERVER_USERNAME"
39+
EnvStoresImportCSVServerPassword = "KFUTIL_CSV_SERVER_PASSWORD"
40+
EnvStoresImportCSVStorePassword = "KFUTIL_CSV_STORE_PASSWORD"
3741
)
3842

3943
var ProviderTypeChoices = []string{

cmd/storesBulkOperations.go

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func serializeStoreFromTypeDef(storeTypeName string, input string) (string, erro
9999

100100
var importStoresCmd = &cobra.Command{
101101
Use: "import",
102-
Short: "Import a file with certificate store parameters and create them in keyfactor.",
102+
Short: "Import a file with certificate store definitions and create them in Keyfactor Command.",
103103
Long: `Tools for generating import templates and importing certificate stores`,
104104
}
105105

@@ -109,14 +109,32 @@ var storesCreateFromCSVCmd = &cobra.Command{
109109
Long: `Certificate stores: Will parse a CSV and attempt to create a certificate store for each row with the provided parameters.
110110
'store-type-name' OR 'store-type-id' are required.
111111
'file' is the path to the file to be imported.
112-
'resultspath' is where the import results will be written to.`,
112+
'resultspath' is where the import results will be written to.
113+
*NOTE*: If you do not wish to include credentials in your CSV file they can be provided one of three ways:
114+
- via the --server-username --server-password and --store-password flags
115+
- via environment variables: KFUTIL_CSV_SERVER_USERNAME, KFUTIL_CSV_SERVER_PASSWORD, KFUTIL_CSV_STORE_PASSWORD
116+
- via interactive prompts
117+
`,
113118
RunE: func(cmd *cobra.Command, args []string) error {
114119
// Specific flags
115120
storeTypeName, _ := cmd.Flags().GetString("store-type-name")
116121
storeTypeID, _ := cmd.Flags().GetInt("store-type-id")
117122
filePath, _ := cmd.Flags().GetString("file")
118123
outPath, _ := cmd.Flags().GetString("results-path")
119124
dryRun, _ := cmd.Flags().GetBool("dry-run")
125+
serverUsername, _ := cmd.Flags().GetString("server-username")
126+
serverPassword, _ := cmd.Flags().GetString("server-password")
127+
storePassword, _ := cmd.Flags().GetString("store-password")
128+
129+
if serverUsername == "" {
130+
serverUsername = os.Getenv(EnvStoresImportCSVServerUsername)
131+
}
132+
if serverPassword == "" {
133+
serverPassword = os.Getenv(EnvStoresImportCSVServerPassword)
134+
}
135+
if storePassword == "" {
136+
storePassword = os.Getenv(EnvStoresImportCSVStorePassword)
137+
}
120138

121139
//// Flag Checks
122140
//inputErr := storeTypeIdentifierFlagCheck(cmd)
@@ -259,6 +277,19 @@ var storesCreateFromCSVCmd = &cobra.Command{
259277

260278
errorCount := 0
261279

280+
if !noPrompt {
281+
promptCreds := promptForInteractiveYesNo("Input default credentials to use for certificate stores?")
282+
if promptCreds {
283+
outputResult("NOTE: Credentials provided in file will take precedence over prompts.", outputFormat)
284+
serverUsername = promptForInteractiveParameter("ServerUsername", serverUsername)
285+
log.Debug().Str("serverUsername", serverUsername).Msg("ServerUsername")
286+
serverPassword = promptForInteractivePassword("ServerPassword", serverPassword)
287+
log.Debug().Str("serverPassword", hashSecretValue(serverPassword)).Msg("ServerPassword")
288+
storePassword = promptForInteractivePassword("StorePassword", storePassword)
289+
log.Debug().Str("storePassword", hashSecretValue(storePassword)).Msg("StorePassword")
290+
}
291+
}
292+
262293
log.Info().Msgf("Processing CSV rows from file '%s'", filePath)
263294
for idx, row := range inFile {
264295
log.Debug().Msgf("Processing row '%d'", idx)
@@ -270,7 +301,6 @@ var storesCreateFromCSVCmd = &cobra.Command{
270301
continue
271302
}
272303
reqJson := getJsonForRequest(headerRow, row)
273-
274304
reqJson = formatProperties(reqJson, reqPropertiesForStoreType)
275305

276306
reqJson.Set(intID, "CertStoreType")
@@ -286,7 +316,31 @@ var storesCreateFromCSVCmd = &cobra.Command{
286316
// parse properties
287317
var createStoreReqParameters api.CreateStoreFctArgs
288318
props := unmarshalPropertiesString(reqJson.S("Properties").String())
319+
320+
//check if ServerUsername is present in the properties
321+
_, uOk := props["ServerUsername"]
322+
if !uOk && serverUsername != "" {
323+
props["ServerUsername"] = serverUsername
324+
}
325+
326+
_, pOk := props["ServerPassword"]
327+
if !pOk && serverPassword != "" {
328+
props["ServerPassword"] = serverPassword
329+
}
330+
331+
rowStorePassword := reqJson.S("Password").String()
289332
reqJson.Delete("Properties") // todo: why is this deleting the properties from the request json?
333+
var passwdParams *api.StorePasswordConfig
334+
if rowStorePassword != "" {
335+
reqJson.Delete("Password")
336+
passwdParams = &api.StorePasswordConfig{
337+
Value: &rowStorePassword,
338+
}
339+
} else {
340+
passwdParams = &api.StorePasswordConfig{
341+
Value: &storePassword,
342+
}
343+
}
290344
mJSON := reqJson.String()
291345
conversionError := json.Unmarshal([]byte(mJSON), &createStoreReqParameters)
292346

@@ -299,10 +353,10 @@ var storesCreateFromCSVCmd = &cobra.Command{
299353
return conversionError
300354
}
301355

356+
createStoreReqParameters.Password = passwdParams
302357
createStoreReqParameters.Properties = props
303358
log.Debug().Msgf("Request parameters: %v", createStoreReqParameters)
304359

305-
// make request.
306360
log.Info().Msgf("Calling Command to create store from row '%d'", idx)
307361
res, err := kfClient.CreateStore(&createStoreReqParameters)
308362

@@ -335,6 +389,7 @@ var storesCreateFromCSVCmd = &cobra.Command{
335389
Int("totalSuccess", totalSuccess).Send()
336390

337391
log.Info().Msgf("Writing results to file '%s'", outPath)
392+
338393
//writeCsvFile(outPath, originalMap)
339394
mapToCSV(inputMap, outPath)
340395
log.Info().Int("totalRows", totalRows).
@@ -1111,6 +1166,39 @@ func init() {
11111166
-1,
11121167
"The ID of the cert store type for the stores.",
11131168
)
1169+
storesCreateFromCSVCmd.Flags().StringVarP(
1170+
&storeTypeName,
1171+
"server-username",
1172+
"u",
1173+
"",
1174+
"The username Keyfactor Command will use to use connect to the certificate store host. "+
1175+
"This field can be specified in the CSV file in the column `Properties.ServerUsername`. "+
1176+
"This value can also be sourced from the environmental variable `KFUTIL_CSV_SERVER_USERNAME`. "+
1177+
"*NOTE* a value provided in the CSV file will override any other input value",
1178+
)
1179+
storesCreateFromCSVCmd.Flags().StringVarP(
1180+
&storeTypeName,
1181+
"server-password",
1182+
"p",
1183+
"",
1184+
"The password Keyfactor Command will use to use connect to the certificate store host. "+
1185+
"This field can be specified in the CSV file in the column `Properties.ServerPassword`. "+
1186+
"This value can also be sourced from the environmental variable `KFUTIL_CSV_SERVER_PASSWORD`. "+
1187+
"*NOTE* a value provided in the CSV file will override any other input value",
1188+
)
1189+
storesCreateFromCSVCmd.Flags().StringVarP(
1190+
&storeTypeName,
1191+
"store-password",
1192+
"s",
1193+
"",
1194+
"The credential information Keyfactor Command will use to access the certificates in a specific certificate"+
1195+
" store (the store password). This is different from credential information Keyfactor Command uses to"+
1196+
" access a certificate store host."+
1197+
" This field can be specified in the CSV file in the column `Password`. This value can also be sourced from"+
1198+
" the environmental variable `KFUTIL_CSV_STORE_PASSWORD`. *NOTE* a value provided in the CSV file will"+
1199+
" override any other input value",
1200+
)
1201+
11141202
storesCreateFromCSVCmd.Flags().StringVarP(&file, "file", "f", "", "CSV file containing cert stores to create.")
11151203
storesCreateFromCSVCmd.MarkFlagRequired("file")
11161204
storesCreateFromCSVCmd.Flags().BoolP("dry-run", "d", false, "Do not import, just check for necessary fields.")

docs/kfutil.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ A CLI wrapper around the Keyfactor Platform API.
4646
* [kfutil stores](kfutil_stores.md) - Keyfactor certificate stores APIs and utilities.
4747
* [kfutil version](kfutil_version.md) - Shows version of kfutil
4848

49-
###### Auto generated by spf13/cobra on 12-Dec-2024
49+
###### Auto generated on 27-Apr-2025

docs/kfutil_completion.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ See each sub-command's help for details on how to use the generated script.
4545
* [kfutil completion powershell](kfutil_completion_powershell.md) - Generate the autocompletion script for powershell
4646
* [kfutil completion zsh](kfutil_completion_zsh.md) - Generate the autocompletion script for zsh
4747

48-
###### Auto generated by spf13/cobra on 12-Dec-2024
48+
###### Auto generated on 27-Apr-2025

docs/kfutil_completion_bash.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ kfutil completion bash
6464

6565
* [kfutil completion](kfutil_completion.md) - Generate the autocompletion script for the specified shell
6666

67-
###### Auto generated by spf13/cobra on 12-Dec-2024
67+
###### Auto generated on 27-Apr-2025

docs/kfutil_completion_fish.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ kfutil completion fish [flags]
5555

5656
* [kfutil completion](kfutil_completion.md) - Generate the autocompletion script for the specified shell
5757

58-
###### Auto generated by spf13/cobra on 12-Dec-2024
58+
###### Auto generated on 27-Apr-2025

docs/kfutil_completion_powershell.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ kfutil completion powershell [flags]
5252

5353
* [kfutil completion](kfutil_completion.md) - Generate the autocompletion script for the specified shell
5454

55-
###### Auto generated by spf13/cobra on 12-Dec-2024
55+
###### Auto generated on 27-Apr-2025

docs/kfutil_completion_zsh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ kfutil completion zsh [flags]
6666

6767
* [kfutil completion](kfutil_completion.md) - Generate the autocompletion script for the specified shell
6868

69-
###### Auto generated by spf13/cobra on 12-Dec-2024
69+
###### Auto generated on 27-Apr-2025

docs/kfutil_containers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ A collections of APIs and utilities for interacting with Keyfactor certificate s
4141
* [kfutil containers get](kfutil_containers_get.md) - Get certificate store container by ID or name.
4242
* [kfutil containers list](kfutil_containers_list.md) - List certificate store containers.
4343

44-
###### Auto generated by spf13/cobra on 12-Dec-2024
44+
###### Auto generated on 27-Apr-2025

0 commit comments

Comments
 (0)