Skip to content

Commit 9493768

Browse files
authored
Merge de21e90 into 93eb8a7
2 parents 93eb8a7 + de21e90 commit 9493768

Some content is hidden

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

60 files changed

+191
-125
lines changed

cmd/storesBulkOperations.go

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ 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")
120123

121124
//// Flag Checks
122125
//inputErr := storeTypeIdentifierFlagCheck(cmd)
@@ -259,6 +262,19 @@ var storesCreateFromCSVCmd = &cobra.Command{
259262

260263
errorCount := 0
261264

265+
if !noPrompt {
266+
promptCreds := promptForInteractiveYesNo("Input default credentials to use for certificate stores?")
267+
if promptCreds {
268+
outputResult("NOTE: Credentials provided in file will take precedence over prompts.", outputFormat)
269+
serverUsername = promptForInteractiveParameter("ServerUsername", serverUsername)
270+
log.Debug().Str("serverUsername", serverUsername).Msg("ServerUsername")
271+
serverPassword = promptForInteractivePassword("ServerPassword", serverPassword)
272+
log.Debug().Str("serverPassword", hashSecretValue(serverPassword)).Msg("ServerPassword")
273+
storePassword = promptForInteractivePassword("StorePassword", storePassword)
274+
log.Debug().Str("storePassword", hashSecretValue(storePassword)).Msg("StorePassword")
275+
}
276+
}
277+
262278
log.Info().Msgf("Processing CSV rows from file '%s'", filePath)
263279
for idx, row := range inFile {
264280
log.Debug().Msgf("Processing row '%d'", idx)
@@ -270,7 +286,6 @@ var storesCreateFromCSVCmd = &cobra.Command{
270286
continue
271287
}
272288
reqJson := getJsonForRequest(headerRow, row)
273-
274289
reqJson = formatProperties(reqJson, reqPropertiesForStoreType)
275290

276291
reqJson.Set(intID, "CertStoreType")
@@ -286,7 +301,31 @@ var storesCreateFromCSVCmd = &cobra.Command{
286301
// parse properties
287302
var createStoreReqParameters api.CreateStoreFctArgs
288303
props := unmarshalPropertiesString(reqJson.S("Properties").String())
304+
305+
//check if ServerUsername is present in the properties
306+
_, uOk := props["ServerUsername"]
307+
if !uOk && serverUsername != "" {
308+
props["ServerUsername"] = serverUsername
309+
}
310+
311+
_, pOk := props["ServerPassword"]
312+
if !pOk && serverPassword != "" {
313+
props["ServerPassword"] = serverPassword
314+
}
315+
316+
rowStorePassword := reqJson.S("Password").String()
289317
reqJson.Delete("Properties") // todo: why is this deleting the properties from the request json?
318+
var passwdParams *api.StorePasswordConfig
319+
if rowStorePassword != "" {
320+
reqJson.Delete("Password")
321+
passwdParams = &api.StorePasswordConfig{
322+
Value: &rowStorePassword,
323+
}
324+
} else {
325+
passwdParams = &api.StorePasswordConfig{
326+
Value: &storePassword,
327+
}
328+
}
290329
mJSON := reqJson.String()
291330
conversionError := json.Unmarshal([]byte(mJSON), &createStoreReqParameters)
292331

@@ -299,10 +338,10 @@ var storesCreateFromCSVCmd = &cobra.Command{
299338
return conversionError
300339
}
301340

341+
createStoreReqParameters.Password = passwdParams
302342
createStoreReqParameters.Properties = props
303343
log.Debug().Msgf("Request parameters: %v", createStoreReqParameters)
304344

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

@@ -335,6 +374,7 @@ var storesCreateFromCSVCmd = &cobra.Command{
335374
Int("totalSuccess", totalSuccess).Send()
336375

337376
log.Info().Msgf("Writing results to file '%s'", outPath)
377+
338378
//writeCsvFile(outPath, originalMap)
339379
mapToCSV(inputMap, outPath)
340380
log.Info().Int("totalRows", totalRows).
@@ -1111,6 +1151,28 @@ func init() {
11111151
-1,
11121152
"The ID of the cert store type for the stores.",
11131153
)
1154+
storesCreateFromCSVCmd.Flags().StringVarP(
1155+
&storeTypeName,
1156+
"server-username",
1157+
"u",
1158+
"",
1159+
"The username Keyfactor Command will use to use connect to the certificate store host. This field can be specified in the CSV file in the column `Properties.ServerUsername`.",
1160+
)
1161+
storesCreateFromCSVCmd.Flags().StringVarP(
1162+
&storeTypeName,
1163+
"server-password",
1164+
"p",
1165+
"",
1166+
"The password Keyfactor Command will use to use connect to the certificate store host. This field can be specified in the CSV file in the column `Properties.ServerPassword`.",
1167+
)
1168+
storesCreateFromCSVCmd.Flags().StringVarP(
1169+
&storeTypeName,
1170+
"store-password",
1171+
"s",
1172+
"",
1173+
"The credential information Keyfactor Command will use to access the certificates in a specific certificate store (the store password). This is different from credential information Keyfactor Command uses to access a certificate store host. This field can be specified in the CSV file in the column `Password`.",
1174+
)
1175+
11141176
storesCreateFromCSVCmd.Flags().StringVarP(&file, "file", "f", "", "CSV file containing cert stores to create.")
11151177
storesCreateFromCSVCmd.MarkFlagRequired("file")
11161178
storesCreateFromCSVCmd.Flags().BoolP("dry-run", "d", false, "Do not import, just check for necessary fields.")

docs/kfutil.md

Lines changed: 1 addition & 1 deletion

docs/kfutil_completion.md

Lines changed: 1 addition & 1 deletion

docs/kfutil_completion_bash.md

Lines changed: 1 addition & 1 deletion

docs/kfutil_completion_fish.md

Lines changed: 1 addition & 1 deletion

docs/kfutil_completion_powershell.md

Lines changed: 1 addition & 1 deletion

docs/kfutil_completion_zsh.md

Lines changed: 1 addition & 1 deletion

docs/kfutil_containers.md

Lines changed: 1 addition & 1 deletion

docs/kfutil_containers_get.md

Lines changed: 1 addition & 1 deletion

docs/kfutil_containers_list.md

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)