Skip to content

Commit f6ae138

Browse files
committed
chore(docs): Add CLI YAML def.
Signed-off-by: sbailey <[email protected]>
1 parent c55d95d commit f6ae138

File tree

13 files changed

+1635
-228
lines changed

13 files changed

+1635
-228
lines changed

cmd/constants.go

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,33 @@ package cmd
1616
import "fmt"
1717

1818
const (
19-
ColorRed = "\033[31m"
20-
ColorWhite = "\033[37m"
21-
DefaultAPIPath = "KeyfactorAPI"
22-
DefaultConfigFileName = "command_config.json"
23-
FailedAuthMsg = "Login failed!"
24-
SuccessfulAuthMsg = "Login successful!"
25-
XKeyfactorRequestedWith = "APIClient"
26-
XKeyfactorApiVersion = "1"
27-
FlagGitRef = "git-ref"
28-
FlagFromFile = "from-file"
29-
DebugFuncEnter = "entered: %s"
30-
DebugFuncExit = "exiting: %s"
31-
DebugFuncCall = "calling: %s"
32-
ErrMsgEmptyResponse = "empty response received from Keyfactor Command %s"
19+
ColorRed = "\033[31m"
20+
ColorWhite = "\033[37m"
21+
DefaultAPIPath = "KeyfactorAPI"
22+
DefaultConfigFileName = "command_config.json"
23+
DefaultROTAuditStoresOutfilePath = "rot_audit_selected_stores.csv"
24+
DefaultROTAuditAddCertsOutfilePath = "rot_audit_selected_certs_add.csv"
25+
DefaultROTAuditRemoveCertsOutfilePath = "rot_audit_selected_certs_remove.csv"
26+
FailedAuthMsg = "Login failed!"
27+
SuccessfulAuthMsg = "Login successful!"
28+
XKeyfactorRequestedWith = "APIClient"
29+
XKeyfactorApiVersion = "1"
30+
FlagGitRef = "git-ref"
31+
FlagFromFile = "from-file"
32+
DebugFuncEnter = "entered: %s"
33+
DebugFuncExit = "exiting: %s"
34+
DebugFuncCall = "calling: %s"
35+
ErrMsgEmptyResponse = "empty response received from Keyfactor Command %s"
36+
)
37+
38+
// CLI Menu Defaults
39+
const (
40+
DefaultMenuPageSizeSmall = 25
41+
DefaultMenuPageSizeLarge = 100
42+
)
43+
44+
var (
45+
DefaultSourceTypeOptions = []string{"API", "File"}
3346
)
3447

3548
var ProviderTypeChoices = []string{
@@ -40,6 +53,10 @@ var ErrKfcEmptyResponse = fmt.Errorf("empty response recieved from Keyfactor Com
4053

4154
// Error messages
4255
var (
43-
StoreTypeReadError = fmt.Errorf("error reading store type from configuration file")
44-
InvalidInputError = fmt.Errorf("invalid input")
56+
StoreTypeReadError = fmt.Errorf("error reading store type from configuration file")
57+
InvalidInputError = fmt.Errorf("invalid input")
58+
InvalidROTCertsInputErr = fmt.Errorf(
59+
"at least one of `--add-certs` or `--remove-certs` is required to perform a" +
60+
" root of trust audit",
61+
)
4562
)

cmd/export.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ import (
1818
"context"
1919
"encoding/json"
2020
"fmt"
21+
"os"
22+
"strconv"
23+
2124
"github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor"
2225
"github.com/Keyfactor/keyfactor-go-client/v2/api"
2326
"github.com/rs/zerolog/log"
2427
"github.com/spf13/cobra"
25-
"os"
26-
"strconv"
2728
)
2829

2930
var exportPath string
@@ -371,8 +372,10 @@ func getIssuedAlerts(kfClient *keyfactor.APIClient) []keyfactor.KeyfactorApiMode
371372
func getDeniedAlerts(kfClient *keyfactor.APIClient) []keyfactor.KeyfactorApiModelsAlertsDeniedDeniedAlertCreationRequest {
372373

373374
alerts, _, reqErr := kfClient.DeniedAlertApi.DeniedAlertGetDeniedAlerts(
374-
context.Background()).XKeyfactorRequestedWith(
375-
XKeyfactorRequestedWith).XKeyfactorApiVersion(XKeyfactorApiVersion).Execute()
375+
context.Background(),
376+
).XKeyfactorRequestedWith(
377+
XKeyfactorRequestedWith,
378+
).XKeyfactorApiVersion(XKeyfactorApiVersion).Execute()
376379
if reqErr != nil {
377380
fmt.Printf("%s Error! Unable to get denied cert alerts %s%s\n", ColorRed, reqErr, ColorWhite)
378381
}
@@ -575,7 +578,13 @@ func init() {
575578
exportCmd.Flags().Lookup("collections").NoOptDefVal = "true"
576579
exportCmd.Flags().BoolVarP(&fMetadata, "metadata", "m", false, "export metadata to JSON file")
577580
exportCmd.Flags().Lookup("metadata").NoOptDefVal = "true"
578-
exportCmd.Flags().BoolVarP(&fExpirationAlerts, "expiration-alerts", "e", false, "export expiration cert alerts to JSON file")
581+
exportCmd.Flags().BoolVarP(
582+
&fExpirationAlerts,
583+
"expiration-alerts",
584+
"e",
585+
false,
586+
"export expiration cert alerts to JSON file",
587+
)
579588
exportCmd.Flags().Lookup("expiration-alerts").NoOptDefVal = "true"
580589
exportCmd.Flags().BoolVarP(&fIssuedAlerts, "issued-alerts", "i", false, "export issued cert alerts to JSON file")
581590
exportCmd.Flags().Lookup("issued-alerts").NoOptDefVal = "true"
@@ -585,7 +594,13 @@ func init() {
585594
exportCmd.Flags().Lookup("pending-alerts").NoOptDefVal = "true"
586595
exportCmd.Flags().BoolVarP(&fNetworks, "networks", "n", false, "export SSL networks to JSON file")
587596
exportCmd.Flags().Lookup("networks").NoOptDefVal = "true"
588-
exportCmd.Flags().BoolVarP(&fWorkflowDefinitions, "workflow-definitions", "w", false, "export workflow definitions to JSON file")
597+
exportCmd.Flags().BoolVarP(
598+
&fWorkflowDefinitions,
599+
"workflow-definitions",
600+
"w",
601+
false,
602+
"export workflow definitions to JSON file",
603+
)
589604
exportCmd.Flags().Lookup("workflow-definitions").NoOptDefVal = "true"
590605
exportCmd.Flags().BoolVarP(&fReports, "reports", "r", false, "export reports to JSON file")
591606
exportCmd.Flags().Lookup("reports").NoOptDefVal = "true"

cmd/helpers.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ import (
3232
"github.com/spf13/cobra"
3333
)
3434

35-
func mergeErrsToString(errs *[]error) string {
35+
func mergeErrsToString(errs *[]error, indent bool) string {
3636
var errStr string
3737
if errs == nil || len(*errs) == 0 {
3838
return ""
3939
}
4040
for _, err := range *errs {
41-
errStr += fmt.Sprintf("%s\n", err)
41+
if indent {
42+
errStr += fmt.Sprintf(" \t%s\r\n", err)
43+
continue
44+
}
45+
errStr += fmt.Sprintf("%s\r\n", err)
4246
}
4347
return errStr
4448
}

cmd/root.go

Lines changed: 138 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ package cmd
1616

1717
import (
1818
"fmt"
19+
"io"
20+
stdlog "log"
21+
"os"
22+
"os/signal"
23+
"syscall"
24+
1925
"github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor"
2026
"github.com/Keyfactor/keyfactor-go-client/v2/api"
2127
"github.com/rs/zerolog/log"
2228
"github.com/spf13/cobra"
2329
"github.com/spf13/cobra/doc"
2430
"golang.org/x/crypto/bcrypt"
25-
"io"
26-
stdlog "log"
27-
"os"
2831
)
2932

3033
var (
@@ -45,6 +48,19 @@ var (
4548
outputFormat string
4649
)
4750

51+
func setupSignalHandler() {
52+
// Start a goroutine to listen for SIGINT signals
53+
sigChan := make(chan os.Signal, 1)
54+
signal.Notify(sigChan, syscall.SIGINT)
55+
56+
go func() {
57+
<-sigChan
58+
// Handle SIGINT signal
59+
fmt.Println("\nCtrl+C pressed. Exiting...")
60+
os.Exit(1)
61+
}()
62+
}
63+
4864
func hashSecretValue(secretValue string) string {
4965
log.Debug().Msg("Enter hashSecretValue()")
5066
if logInsecure {
@@ -63,7 +79,15 @@ func hashSecretValue(secretValue string) string {
6379
return string(hashedPassword)
6480
}
6581

66-
func initClient(flagConfigFile string, flagProfile string, flagAuthProviderType string, flagAuthProviderProfile string, noPrompt bool, authConfig *api.AuthConfig, saveConfig bool) (*api.Client, error) {
82+
func initClient(
83+
flagConfigFile string,
84+
flagProfile string,
85+
flagAuthProviderType string,
86+
flagAuthProviderProfile string,
87+
noPrompt bool,
88+
authConfig *api.AuthConfig,
89+
saveConfig bool,
90+
) (*api.Client, error) {
6791
log.Debug().Msg("Enter initClient()")
6892
var clientAuth api.AuthConfig
6993
var commandConfig ConfigurationFile
@@ -163,9 +187,18 @@ func initClient(flagConfigFile string, flagProfile string, flagAuthProviderType
163187
if !noPrompt {
164188
// Auth user interactively
165189
authConfigEntry := commandConfig.Servers[flagProfile]
166-
commandConfig, _ = authInteractive(authConfigEntry.Hostname, authConfigEntry.Username, authConfigEntry.Password, authConfigEntry.Domain, authConfigEntry.APIPath, flagProfile, false, false, flagConfigFile)
190+
commandConfig, _ = authInteractive(
191+
authConfigEntry.Hostname,
192+
authConfigEntry.Username,
193+
authConfigEntry.Password,
194+
authConfigEntry.Domain,
195+
authConfigEntry.APIPath,
196+
flagProfile,
197+
false,
198+
false,
199+
flagConfigFile,
200+
)
167201
} else {
168-
//log.Fatalf("[ERROR] auth config profile: %s", flagProfile)
169202
log.Error().Str("flagProfile", flagProfile).Msg("invalid auth config profile")
170203
return nil, fmt.Errorf("invalid auth config profile: %s", flagProfile)
171204
}
@@ -191,14 +224,19 @@ func initClient(flagConfigFile string, flagProfile string, flagAuthProviderType
191224
if err != nil {
192225
//fmt.Printf("Error connecting to Keyfactor: %s\n", err)
193226
outputError(err, true, "text")
194-
//log.Fatalf("[ERROR] creating Keyfactor client: %s", err)
195227
return nil, fmt.Errorf("unable to create Keyfactor Command client: %s", err)
196228
}
197229
log.Info().Msg("Keyfactor Command client created")
198230
return c, nil
199231
}
200232

201-
func initGenClient(flagConfig string, flagProfile string, noPrompt bool, authConfig *api.AuthConfig, saveConfig bool) (*keyfactor.APIClient, error) {
233+
func initGenClient(
234+
flagConfig string,
235+
flagProfile string,
236+
noPrompt bool,
237+
authConfig *api.AuthConfig,
238+
saveConfig bool,
239+
) (*keyfactor.APIClient, error) {
202240
var commandConfig ConfigurationFile
203241

204242
if providerType != "" {
@@ -246,7 +284,17 @@ func initGenClient(flagConfig string, flagProfile string, noPrompt bool, authCon
246284
if !noPrompt {
247285
// Auth user interactively
248286
authConfigEntry := commandConfig.Servers[flagProfile]
249-
commandConfig, _ = authInteractive(authConfigEntry.Hostname, authConfigEntry.Username, authConfigEntry.Password, authConfigEntry.Domain, authConfigEntry.APIPath, flagProfile, false, false, flagConfig)
287+
commandConfig, _ = authInteractive(
288+
authConfigEntry.Hostname,
289+
authConfigEntry.Username,
290+
authConfigEntry.Password,
291+
authConfigEntry.Domain,
292+
authConfigEntry.APIPath,
293+
flagProfile,
294+
false,
295+
false,
296+
flagConfig,
297+
)
250298
} else {
251299
//log.Fatalf("[ERROR] auth config profile: %s", flagProfile)
252300
log.Error().Str("flagProfile", flagProfile).Msg("invalid auth config profile")
@@ -306,24 +354,92 @@ func init() {
306354

307355
defaultConfigPath := fmt.Sprintf("$HOME/.keyfactor/%s", DefaultConfigFileName)
308356

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.)")
357+
RootCmd.PersistentFlags().StringVarP(
358+
&configFile,
359+
"config",
360+
"",
361+
"",
362+
fmt.Sprintf("Full path to config file in JSON format. (default is %s)", defaultConfigPath),
363+
)
364+
RootCmd.PersistentFlags().BoolVar(
365+
&noPrompt,
366+
"no-prompt",
367+
false,
368+
"Do not prompt for any user input and assume defaults or environmental variables are set.",
369+
)
370+
RootCmd.PersistentFlags().BoolVar(
371+
&expEnabled,
372+
"exp",
373+
false,
374+
"Enable expEnabled features. (USE AT YOUR OWN RISK, these features are not supported and may change or be removed at any time.)",
375+
)
312376
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.")
377+
RootCmd.PersistentFlags().BoolVar(
378+
&logInsecure,
379+
"log-insecure",
380+
false,
381+
"Log insecure API requests. (USE AT YOUR OWN RISK, this WILL log sensitive information to the console.)",
382+
)
383+
RootCmd.PersistentFlags().StringVarP(
384+
&profile,
385+
"profile",
386+
"",
387+
"",
388+
"Use a specific profile from your config file. If not specified the config named 'default' will be used if it exists.",
389+
)
390+
RootCmd.PersistentFlags().StringVar(
391+
&outputFormat,
392+
"format",
393+
"text",
394+
"How to format the CLI output. Currently only `text` is supported.",
395+
)
316396

317397
RootCmd.PersistentFlags().StringVar(&providerType, "auth-provider-type", "", "Provider type choices: (azid)")
318398
// Validating the provider-type flag against the predefined choices
319399
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)")
400+
RootCmd.PersistentFlags().StringVarP(
401+
&providerProfile,
402+
"auth-provider-profile",
403+
"",
404+
"default",
405+
"The profile to use defined in the securely stored config. If not specified the config named 'default' will be used if it exists.",
406+
)
407+
408+
RootCmd.PersistentFlags().StringVarP(
409+
&kfcUsername,
410+
"username",
411+
"",
412+
"",
413+
"Username to use for authenticating to Keyfactor Command.",
414+
)
415+
RootCmd.PersistentFlags().StringVarP(
416+
&kfcHostName,
417+
"hostname",
418+
"",
419+
"",
420+
"Hostname to use for authenticating to Keyfactor Command.",
421+
)
422+
RootCmd.PersistentFlags().StringVarP(
423+
&kfcPassword,
424+
"password",
425+
"",
426+
"",
427+
"Password to use for authenticating to Keyfactor Command. WARNING: Remember to delete your console history if providing kfcPassword here in plain text.",
428+
)
429+
RootCmd.PersistentFlags().StringVarP(
430+
&kfcDomain,
431+
"domain",
432+
"",
433+
"",
434+
"Domain to use for authenticating to Keyfactor Command.",
435+
)
436+
RootCmd.PersistentFlags().StringVarP(
437+
&kfcAPIPath,
438+
"api-path",
439+
"",
440+
"KeyfactorAPI",
441+
"API Path to use for authenticating to Keyfactor Command. (default is KeyfactorAPI)",
442+
)
327443

328444
// Cobra also supports local flags, which will only run
329445
// when this action is called directly.

0 commit comments

Comments
 (0)