Skip to content

Commit e2bc551

Browse files
authored
Merge 8d1b82f into 6cc2538
2 parents 6cc2538 + 8d1b82f commit e2bc551

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

+240
-130
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: 86 additions & 3 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

@@ -117,6 +117,19 @@ var storesCreateFromCSVCmd = &cobra.Command{
117117
filePath, _ := cmd.Flags().GetString("file")
118118
outPath, _ := cmd.Flags().GetString("results-path")
119119
dryRun, _ := cmd.Flags().GetBool("dry-run")
120+
serverUsername, _ := cmd.Flags().GetString("server-username")
121+
serverPassword, _ := cmd.Flags().GetString("server-password")
122+
storePassword, _ := cmd.Flags().GetString("store-password")
123+
124+
if serverUsername == "" {
125+
serverUsername = os.Getenv(EnvStoresImportCSVServerUsername)
126+
}
127+
if serverPassword == "" {
128+
serverPassword = os.Getenv(EnvStoresImportCSVServerPassword)
129+
}
130+
if storePassword == "" {
131+
storePassword = os.Getenv(EnvStoresImportCSVStorePassword)
132+
}
120133

121134
//// Flag Checks
122135
//inputErr := storeTypeIdentifierFlagCheck(cmd)
@@ -259,6 +272,19 @@ var storesCreateFromCSVCmd = &cobra.Command{
259272

260273
errorCount := 0
261274

275+
if !noPrompt {
276+
promptCreds := promptForInteractiveYesNo("Input default credentials to use for certificate stores?")
277+
if promptCreds {
278+
outputResult("NOTE: Credentials provided in file will take precedence over prompts.", outputFormat)
279+
serverUsername = promptForInteractiveParameter("ServerUsername", serverUsername)
280+
log.Debug().Str("serverUsername", serverUsername).Msg("ServerUsername")
281+
serverPassword = promptForInteractivePassword("ServerPassword", serverPassword)
282+
log.Debug().Str("serverPassword", hashSecretValue(serverPassword)).Msg("ServerPassword")
283+
storePassword = promptForInteractivePassword("StorePassword", storePassword)
284+
log.Debug().Str("storePassword", hashSecretValue(storePassword)).Msg("StorePassword")
285+
}
286+
}
287+
262288
log.Info().Msgf("Processing CSV rows from file '%s'", filePath)
263289
for idx, row := range inFile {
264290
log.Debug().Msgf("Processing row '%d'", idx)
@@ -270,7 +296,6 @@ var storesCreateFromCSVCmd = &cobra.Command{
270296
continue
271297
}
272298
reqJson := getJsonForRequest(headerRow, row)
273-
274299
reqJson = formatProperties(reqJson, reqPropertiesForStoreType)
275300

276301
reqJson.Set(intID, "CertStoreType")
@@ -286,7 +311,31 @@ var storesCreateFromCSVCmd = &cobra.Command{
286311
// parse properties
287312
var createStoreReqParameters api.CreateStoreFctArgs
288313
props := unmarshalPropertiesString(reqJson.S("Properties").String())
314+
315+
//check if ServerUsername is present in the properties
316+
_, uOk := props["ServerUsername"]
317+
if !uOk && serverUsername != "" {
318+
props["ServerUsername"] = serverUsername
319+
}
320+
321+
_, pOk := props["ServerPassword"]
322+
if !pOk && serverPassword != "" {
323+
props["ServerPassword"] = serverPassword
324+
}
325+
326+
rowStorePassword := reqJson.S("Password").String()
289327
reqJson.Delete("Properties") // todo: why is this deleting the properties from the request json?
328+
var passwdParams *api.StorePasswordConfig
329+
if rowStorePassword != "" {
330+
reqJson.Delete("Password")
331+
passwdParams = &api.StorePasswordConfig{
332+
Value: &rowStorePassword,
333+
}
334+
} else {
335+
passwdParams = &api.StorePasswordConfig{
336+
Value: &storePassword,
337+
}
338+
}
290339
mJSON := reqJson.String()
291340
conversionError := json.Unmarshal([]byte(mJSON), &createStoreReqParameters)
292341

@@ -299,10 +348,10 @@ var storesCreateFromCSVCmd = &cobra.Command{
299348
return conversionError
300349
}
301350

351+
createStoreReqParameters.Password = passwdParams
302352
createStoreReqParameters.Properties = props
303353
log.Debug().Msgf("Request parameters: %v", createStoreReqParameters)
304354

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

@@ -335,6 +384,7 @@ var storesCreateFromCSVCmd = &cobra.Command{
335384
Int("totalSuccess", totalSuccess).Send()
336385

337386
log.Info().Msgf("Writing results to file '%s'", outPath)
387+
338388
//writeCsvFile(outPath, originalMap)
339389
mapToCSV(inputMap, outPath)
340390
log.Info().Int("totalRows", totalRows).
@@ -1111,6 +1161,39 @@ func init() {
11111161
-1,
11121162
"The ID of the cert store type for the stores.",
11131163
)
1164+
storesCreateFromCSVCmd.Flags().StringVarP(
1165+
&storeTypeName,
1166+
"server-username",
1167+
"u",
1168+
"",
1169+
"The username Keyfactor Command will use to use connect to the certificate store host. "+
1170+
"This field can be specified in the CSV file in the column `Properties.ServerUsername`. "+
1171+
"This value can also be sourced from the environmental variable `KFUTIL_CSV_SERVER_USERNAME`. "+
1172+
"*NOTE* a value provided in the CSV file will override any other input value",
1173+
)
1174+
storesCreateFromCSVCmd.Flags().StringVarP(
1175+
&storeTypeName,
1176+
"server-password",
1177+
"p",
1178+
"",
1179+
"The password Keyfactor Command will use to use connect to the certificate store host. "+
1180+
"This field can be specified in the CSV file in the column `Properties.ServerPassword`. "+
1181+
"This value can also be sourced from the environmental variable `KFUTIL_CSV_SERVER_PASSWORD`. "+
1182+
"*NOTE* a value provided in the CSV file will override any other input value",
1183+
)
1184+
storesCreateFromCSVCmd.Flags().StringVarP(
1185+
&storeTypeName,
1186+
"store-password",
1187+
"s",
1188+
"",
1189+
"The credential information Keyfactor Command will use to access the certificates in a specific certificate"+
1190+
" store (the store password). This is different from credential information Keyfactor Command uses to"+
1191+
" access a certificate store host."+
1192+
" This field can be specified in the CSV file in the column `Password`. This value can also be sourced from"+
1193+
" the environmental variable `KFUTIL_CSV_STORE_PASSWORD`. *NOTE* a value provided in the CSV file will"+
1194+
" override any other input value",
1195+
)
1196+
11141197
storesCreateFromCSVCmd.Flags().StringVarP(&file, "file", "f", "", "CSV file containing cert stores to create.")
11151198
storesCreateFromCSVCmd.MarkFlagRequired("file")
11161199
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)