Skip to content

Commit 8d1e6a2

Browse files
committed
feat(stores): import csv supports ENV credentials.
Signed-off-by: spbsoluble <1661003+spbsoluble@users.noreply.github.com>
1 parent de21e90 commit 8d1e6a2

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

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: 25 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

@@ -121,6 +121,16 @@ var storesCreateFromCSVCmd = &cobra.Command{
121121
serverPassword, _ := cmd.Flags().GetString("server-password")
122122
storePassword, _ := cmd.Flags().GetString("store-password")
123123

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+
}
133+
124134
//// Flag Checks
125135
//inputErr := storeTypeIdentifierFlagCheck(cmd)
126136
//if inputErr != nil {
@@ -1156,21 +1166,32 @@ func init() {
11561166
"server-username",
11571167
"u",
11581168
"",
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`.",
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",
11601173
)
11611174
storesCreateFromCSVCmd.Flags().StringVarP(
11621175
&storeTypeName,
11631176
"server-password",
11641177
"p",
11651178
"",
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`.",
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",
11671183
)
11681184
storesCreateFromCSVCmd.Flags().StringVarP(
11691185
&storeTypeName,
11701186
"store-password",
11711187
"s",
11721188
"",
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`.",
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",
11741195
)
11751196

11761197
storesCreateFromCSVCmd.Flags().StringVarP(&file, "file", "f", "", "CSV file containing cert stores to create.")

0 commit comments

Comments
 (0)