|
15 | 15 | package cmd |
16 | 16 |
|
17 | 17 | import ( |
| 18 | + _ "embed" |
18 | 19 | "fmt" |
| 20 | + "io" |
| 21 | + stdlog "log" |
| 22 | + "os" |
| 23 | + |
19 | 24 | "github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor" |
20 | 25 | "github.com/Keyfactor/keyfactor-go-client/v2/api" |
21 | 26 | "github.com/rs/zerolog/log" |
22 | 27 | "github.com/spf13/cobra" |
23 | 28 | "github.com/spf13/cobra/doc" |
24 | 29 | "golang.org/x/crypto/bcrypt" |
25 | | - "io" |
26 | | - stdlog "log" |
27 | | - "os" |
28 | 30 | ) |
29 | 31 |
|
| 32 | +//go:embed store_types.json |
| 33 | +var EmbeddedStoreTypesJSON []byte |
| 34 | + |
30 | 35 | var ( |
31 | 36 | configFile string |
32 | 37 | profile string |
@@ -63,7 +68,15 @@ func hashSecretValue(secretValue string) string { |
63 | 68 | return string(hashedPassword) |
64 | 69 | } |
65 | 70 |
|
66 | | -func initClient(flagConfigFile string, flagProfile string, flagAuthProviderType string, flagAuthProviderProfile string, noPrompt bool, authConfig *api.AuthConfig, saveConfig bool) (*api.Client, error) { |
| 71 | +func initClient( |
| 72 | + flagConfigFile string, |
| 73 | + flagProfile string, |
| 74 | + flagAuthProviderType string, |
| 75 | + flagAuthProviderProfile string, |
| 76 | + noPrompt bool, |
| 77 | + authConfig *api.AuthConfig, |
| 78 | + saveConfig bool, |
| 79 | +) (*api.Client, error) { |
67 | 80 | log.Debug().Msg("Enter initClient()") |
68 | 81 | var clientAuth api.AuthConfig |
69 | 82 | var commandConfig ConfigurationFile |
@@ -163,7 +176,17 @@ func initClient(flagConfigFile string, flagProfile string, flagAuthProviderType |
163 | 176 | if !noPrompt { |
164 | 177 | // Auth user interactively |
165 | 178 | authConfigEntry := commandConfig.Servers[flagProfile] |
166 | | - commandConfig, _ = authInteractive(authConfigEntry.Hostname, authConfigEntry.Username, authConfigEntry.Password, authConfigEntry.Domain, authConfigEntry.APIPath, flagProfile, false, false, flagConfigFile) |
| 179 | + commandConfig, _ = authInteractive( |
| 180 | + authConfigEntry.Hostname, |
| 181 | + authConfigEntry.Username, |
| 182 | + authConfigEntry.Password, |
| 183 | + authConfigEntry.Domain, |
| 184 | + authConfigEntry.APIPath, |
| 185 | + flagProfile, |
| 186 | + false, |
| 187 | + false, |
| 188 | + flagConfigFile, |
| 189 | + ) |
167 | 190 | } else { |
168 | 191 | //log.Fatalf("[ERROR] auth config profile: %s", flagProfile) |
169 | 192 | log.Error().Str("flagProfile", flagProfile).Msg("invalid auth config profile") |
@@ -198,7 +221,13 @@ func initClient(flagConfigFile string, flagProfile string, flagAuthProviderType |
198 | 221 | return c, nil |
199 | 222 | } |
200 | 223 |
|
201 | | -func initGenClient(flagConfig string, flagProfile string, noPrompt bool, authConfig *api.AuthConfig, saveConfig bool) (*keyfactor.APIClient, error) { |
| 224 | +func initGenClient( |
| 225 | + flagConfig string, |
| 226 | + flagProfile string, |
| 227 | + noPrompt bool, |
| 228 | + authConfig *api.AuthConfig, |
| 229 | + saveConfig bool, |
| 230 | +) (*keyfactor.APIClient, error) { |
202 | 231 | var commandConfig ConfigurationFile |
203 | 232 |
|
204 | 233 | if providerType != "" { |
@@ -246,7 +275,17 @@ func initGenClient(flagConfig string, flagProfile string, noPrompt bool, authCon |
246 | 275 | if !noPrompt { |
247 | 276 | // Auth user interactively |
248 | 277 | authConfigEntry := commandConfig.Servers[flagProfile] |
249 | | - commandConfig, _ = authInteractive(authConfigEntry.Hostname, authConfigEntry.Username, authConfigEntry.Password, authConfigEntry.Domain, authConfigEntry.APIPath, flagProfile, false, false, flagConfig) |
| 278 | + commandConfig, _ = authInteractive( |
| 279 | + authConfigEntry.Hostname, |
| 280 | + authConfigEntry.Username, |
| 281 | + authConfigEntry.Password, |
| 282 | + authConfigEntry.Domain, |
| 283 | + authConfigEntry.APIPath, |
| 284 | + flagProfile, |
| 285 | + false, |
| 286 | + false, |
| 287 | + flagConfig, |
| 288 | + ) |
250 | 289 | } else { |
251 | 290 | //log.Fatalf("[ERROR] auth config profile: %s", flagProfile) |
252 | 291 | log.Error().Str("flagProfile", flagProfile).Msg("invalid auth config profile") |
@@ -306,24 +345,92 @@ func init() { |
306 | 345 |
|
307 | 346 | defaultConfigPath := fmt.Sprintf("$HOME/.keyfactor/%s", DefaultConfigFileName) |
308 | 347 |
|
309 | | - RootCmd.PersistentFlags().StringVarP(&configFile, "config", "", "", fmt.Sprintf("Full path to config file in JSON format. (default is %s)", defaultConfigPath)) |
310 | | - RootCmd.PersistentFlags().BoolVar(&noPrompt, "no-prompt", false, "Do not prompt for any user input and assume defaults or environmental variables are set.") |
311 | | - RootCmd.PersistentFlags().BoolVar(&expEnabled, "exp", false, "Enable expEnabled features. (USE AT YOUR OWN RISK, these features are not supported and may change or be removed at any time.)") |
| 348 | + RootCmd.PersistentFlags().StringVarP( |
| 349 | + &configFile, |
| 350 | + "config", |
| 351 | + "", |
| 352 | + "", |
| 353 | + fmt.Sprintf("Full path to config file in JSON format. (default is %s)", defaultConfigPath), |
| 354 | + ) |
| 355 | + RootCmd.PersistentFlags().BoolVar( |
| 356 | + &noPrompt, |
| 357 | + "no-prompt", |
| 358 | + false, |
| 359 | + "Do not prompt for any user input and assume defaults or environmental variables are set.", |
| 360 | + ) |
| 361 | + RootCmd.PersistentFlags().BoolVar( |
| 362 | + &expEnabled, |
| 363 | + "exp", |
| 364 | + false, |
| 365 | + "Enable expEnabled features. (USE AT YOUR OWN RISK, these features are not supported and may change or be removed at any time.)", |
| 366 | + ) |
312 | 367 | RootCmd.PersistentFlags().BoolVar(&debugFlag, "debug", false, "Enable debugFlag logging.") |
313 | | - RootCmd.PersistentFlags().BoolVar(&logInsecure, "log-insecure", false, "Log insecure API requests. (USE AT YOUR OWN RISK, this WILL log sensitive information to the console.)") |
314 | | - RootCmd.PersistentFlags().StringVarP(&profile, "profile", "", "", "Use a specific profile from your config file. If not specified the config named 'default' will be used if it exists.") |
315 | | - RootCmd.PersistentFlags().StringVar(&outputFormat, "format", "text", "How to format the CLI output. Currently only `text` is supported.") |
| 368 | + RootCmd.PersistentFlags().BoolVar( |
| 369 | + &logInsecure, |
| 370 | + "log-insecure", |
| 371 | + false, |
| 372 | + "Log insecure API requests. (USE AT YOUR OWN RISK, this WILL log sensitive information to the console.)", |
| 373 | + ) |
| 374 | + RootCmd.PersistentFlags().StringVarP( |
| 375 | + &profile, |
| 376 | + "profile", |
| 377 | + "", |
| 378 | + "", |
| 379 | + "Use a specific profile from your config file. If not specified the config named 'default' will be used if it exists.", |
| 380 | + ) |
| 381 | + RootCmd.PersistentFlags().StringVar( |
| 382 | + &outputFormat, |
| 383 | + "format", |
| 384 | + "text", |
| 385 | + "How to format the CLI output. Currently only `text` is supported.", |
| 386 | + ) |
316 | 387 |
|
317 | 388 | RootCmd.PersistentFlags().StringVar(&providerType, "auth-provider-type", "", "Provider type choices: (azid)") |
318 | 389 | // Validating the provider-type flag against the predefined choices |
319 | 390 | RootCmd.PersistentFlags().SetAnnotation("auth-provider-type", cobra.BashCompCustom, ProviderTypeChoices) |
320 | | - RootCmd.PersistentFlags().StringVarP(&providerProfile, "auth-provider-profile", "", "default", "The profile to use defined in the securely stored config. If not specified the config named 'default' will be used if it exists.") |
321 | | - |
322 | | - RootCmd.PersistentFlags().StringVarP(&kfcUsername, "username", "", "", "Username to use for authenticating to Keyfactor Command.") |
323 | | - RootCmd.PersistentFlags().StringVarP(&kfcHostName, "hostname", "", "", "Hostname to use for authenticating to Keyfactor Command.") |
324 | | - RootCmd.PersistentFlags().StringVarP(&kfcPassword, "password", "", "", "Password to use for authenticating to Keyfactor Command. WARNING: Remember to delete your console history if providing kfcPassword here in plain text.") |
325 | | - RootCmd.PersistentFlags().StringVarP(&kfcDomain, "domain", "", "", "Domain to use for authenticating to Keyfactor Command.") |
326 | | - RootCmd.PersistentFlags().StringVarP(&kfcAPIPath, "api-path", "", "KeyfactorAPI", "API Path to use for authenticating to Keyfactor Command. (default is KeyfactorAPI)") |
| 391 | + RootCmd.PersistentFlags().StringVarP( |
| 392 | + &providerProfile, |
| 393 | + "auth-provider-profile", |
| 394 | + "", |
| 395 | + "default", |
| 396 | + "The profile to use defined in the securely stored config. If not specified the config named 'default' will be used if it exists.", |
| 397 | + ) |
| 398 | + |
| 399 | + RootCmd.PersistentFlags().StringVarP( |
| 400 | + &kfcUsername, |
| 401 | + "username", |
| 402 | + "", |
| 403 | + "", |
| 404 | + "Username to use for authenticating to Keyfactor Command.", |
| 405 | + ) |
| 406 | + RootCmd.PersistentFlags().StringVarP( |
| 407 | + &kfcHostName, |
| 408 | + "hostname", |
| 409 | + "", |
| 410 | + "", |
| 411 | + "Hostname to use for authenticating to Keyfactor Command.", |
| 412 | + ) |
| 413 | + RootCmd.PersistentFlags().StringVarP( |
| 414 | + &kfcPassword, |
| 415 | + "password", |
| 416 | + "", |
| 417 | + "", |
| 418 | + "Password to use for authenticating to Keyfactor Command. WARNING: Remember to delete your console history if providing kfcPassword here in plain text.", |
| 419 | + ) |
| 420 | + RootCmd.PersistentFlags().StringVarP( |
| 421 | + &kfcDomain, |
| 422 | + "domain", |
| 423 | + "", |
| 424 | + "", |
| 425 | + "Domain to use for authenticating to Keyfactor Command.", |
| 426 | + ) |
| 427 | + RootCmd.PersistentFlags().StringVarP( |
| 428 | + &kfcAPIPath, |
| 429 | + "api-path", |
| 430 | + "", |
| 431 | + "KeyfactorAPI", |
| 432 | + "API Path to use for authenticating to Keyfactor Command. (default is KeyfactorAPI)", |
| 433 | + ) |
327 | 434 |
|
328 | 435 | // Cobra also supports local flags, which will only run |
329 | 436 | // when this action is called directly. |
|
0 commit comments