Skip to content

Commit

Permalink
Address gosec issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nmanoogian committed Feb 12, 2024
1 parent ec59714 commit 9b13e87
Show file tree
Hide file tree
Showing 31 changed files with 400 additions and 150 deletions.
4 changes: 3 additions & 1 deletion pkg/cmd/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func activityLogIDsValidArgs(cmd *cobra.Command, args []string, toComplete strin

func init() {
activityGetCmd.Flags().String("log", "", "activity log id")
activityGetCmd.RegisterFlagCompletionFunc("log", activityLogIDsValidArgs)
if err := activityGetCmd.RegisterFlagCompletionFunc("log", activityLogIDsValidArgs); err != nil {
utils.HandleError(err)
}
activityCmd.AddCommand(activityGetCmd)

activityCmd.Flags().IntP("number", "n", 20, "max number of logs to display")
Expand Down
64 changes: 48 additions & 16 deletions pkg/cmd/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,29 +355,45 @@ func unlockedConfigNamesValidArgs(cmd *cobra.Command, args []string, toComplete

func init() {
configsCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := configsCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsCmd.Flags().StringP("environment", "e", "", "config environment")
configsCmd.RegisterFlagCompletionFunc("environment", configEnvironmentIDsValidArgs)
if err := configsCmd.RegisterFlagCompletionFunc("environment", configEnvironmentIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsCmd.Flags().IntP("number", "n", 100, "max number of configs to display")
configsCmd.Flags().Int("page", 1, "page to display")

configsGetCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsGetCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := configsGetCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsGetCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsGetCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs)
if err := configsGetCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs); err != nil {
utils.HandleError(err)
}
configsCmd.AddCommand(configsGetCmd)

configsCreateCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsCreateCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := configsCreateCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsCreateCmd.Flags().String("name", "", "config name")
configsCreateCmd.Flags().StringP("environment", "e", "", "config environment")
configsCreateCmd.RegisterFlagCompletionFunc("environment", configEnvironmentIDsValidArgs)
if err := configsCreateCmd.RegisterFlagCompletionFunc("environment", configEnvironmentIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsCmd.AddCommand(configsCreateCmd)

configsUpdateCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsUpdateCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := configsUpdateCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsUpdateCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsUpdateCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs)
if err := configsUpdateCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs); err != nil {
utils.HandleError(err)
}
configsUpdateCmd.Flags().String("name", "", "config name")
if err := configsUpdateCmd.MarkFlagRequired("name"); err != nil {
utils.HandleError(err)
Expand All @@ -386,30 +402,46 @@ func init() {
configsCmd.AddCommand(configsUpdateCmd)

configsDeleteCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsDeleteCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := configsDeleteCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsDeleteCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsDeleteCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs)
if err := configsDeleteCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs); err != nil {
utils.HandleError(err)
}
configsDeleteCmd.Flags().BoolP("yes", "y", false, "proceed without confirmation")
configsCmd.AddCommand(configsDeleteCmd)

configsLockCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsLockCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := configsLockCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsLockCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsLockCmd.RegisterFlagCompletionFunc("config", lockedConfigNamesValidArgs)
if err := configsLockCmd.RegisterFlagCompletionFunc("config", lockedConfigNamesValidArgs); err != nil {
utils.HandleError(err)
}
configsLockCmd.Flags().BoolP("yes", "y", false, "proceed without confirmation")
configsCmd.AddCommand(configsLockCmd)

configsUnlockCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsUnlockCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := configsUnlockCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsUnlockCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsUnlockCmd.RegisterFlagCompletionFunc("config", unlockedConfigNamesValidArgs)
if err := configsUnlockCmd.RegisterFlagCompletionFunc("config", unlockedConfigNamesValidArgs); err != nil {
utils.HandleError(err)
}
configsUnlockCmd.Flags().BoolP("yes", "y", false, "proceed without confirmation")
configsCmd.AddCommand(configsUnlockCmd)

configsCloneCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsCloneCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := configsCloneCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsCloneCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsCloneCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs)
if err := configsCloneCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs); err != nil {
utils.HandleError(err)
}
configsCloneCmd.Flags().String("name", "", "new config name")
configsCmd.AddCommand(configsCloneCmd)

Expand Down
32 changes: 24 additions & 8 deletions pkg/cmd/configs_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,42 @@ func configLogIDsValidArgs(cmd *cobra.Command, args []string, toComplete string)

func init() {
configsLogsCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsLogsCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := configsLogsCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsLogsCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsLogsCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs)
if err := configsLogsCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs); err != nil {
utils.HandleError(err)
}
configsLogsCmd.Flags().Int("page", 1, "log page to display")
configsLogsCmd.Flags().IntP("number", "n", 20, "max number of logs to display")
configsCmd.AddCommand(configsLogsCmd)

configsLogsGetCmd.Flags().String("log", "", "audit log id")
configsLogsGetCmd.RegisterFlagCompletionFunc("log", configLogIDsValidArgs)
if err := configsLogsGetCmd.RegisterFlagCompletionFunc("log", configLogIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsLogsGetCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsLogsGetCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := configsLogsGetCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsLogsGetCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsLogsGetCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs)
if err := configsLogsGetCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs); err != nil {
utils.HandleError(err)
}
configsLogsCmd.AddCommand(configsLogsGetCmd)

configsLogsRollbackCmd.Flags().String("log", "", "audit log id")
configsLogsRollbackCmd.RegisterFlagCompletionFunc("log", configLogIDsValidArgs)
if err := configsLogsRollbackCmd.RegisterFlagCompletionFunc("log", configLogIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsLogsRollbackCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsLogsRollbackCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := configsLogsRollbackCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsLogsRollbackCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsLogsRollbackCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs)
if err := configsLogsRollbackCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs); err != nil {
utils.HandleError(err)
}
configsLogsCmd.AddCommand(configsLogsRollbackCmd)
}
45 changes: 34 additions & 11 deletions pkg/cmd/configs_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,38 +189,61 @@ func configTokenSlugsValidArgs(cmd *cobra.Command, args []string, toComplete str

func init() {
configsTokensCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsTokensCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := configsTokensCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsTokensCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsTokensCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs)
if err := configsTokensCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs); err != nil {
utils.HandleError(err)
}
configsCmd.AddCommand(configsTokensCmd)

configsTokensGetCmd.Flags().String("slug", "", "service token slug")
configsTokensGetCmd.RegisterFlagCompletionFunc("slug", configTokenSlugsValidArgs)
if err := configsTokensGetCmd.RegisterFlagCompletionFunc("slug", configTokenSlugsValidArgs); err != nil {
utils.HandleError(err)
}
configsTokensGetCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsTokensGetCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := configsTokensGetCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsTokensGetCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsTokensGetCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs)
if err := configsTokensGetCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs); err != nil {
utils.HandleError(err)
}
configsTokensCmd.AddCommand(configsTokensGetCmd)

configsTokensCreateCmd.Flags().String("name", "", "service token name")
configsTokensCreateCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsTokensCreateCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := configsTokensCreateCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsTokensCreateCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsTokensCreateCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs)
if err := configsTokensCreateCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs); err != nil {
utils.HandleError(err)
}
configsTokensCreateCmd.Flags().Bool("plain", false, "print only the token, without formatting")
configsTokensCreateCmd.Flags().Bool("copy", false, "copy the token to your clipboard")
configsTokensCreateCmd.Flags().Duration("max-age", 0, "token will expire after specified duration, (e.g. '3h', '15m')")
configsTokensCreateCmd.Flags().String("access", "read", "the token's access. one of [\"read\", \"read/write\"]")
configsTokensCreateCmd.RegisterFlagCompletionFunc("access", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
err := configsTokensCreateCmd.RegisterFlagCompletionFunc("access", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"read", "read/write"}, cobra.ShellCompDirectiveDefault
})
if err != nil {
utils.HandleError(err)
}
configsTokensCmd.AddCommand(configsTokensCreateCmd)

configsTokensRevokeCmd.Flags().String("slug", "", "service token slug")
configsTokensRevokeCmd.RegisterFlagCompletionFunc("slug", configTokenSlugsValidArgs)
if err := configsTokensRevokeCmd.RegisterFlagCompletionFunc("slug", configTokenSlugsValidArgs); err != nil {
utils.HandleError(err)
}
configsTokensRevokeCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
configsTokensRevokeCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := configsTokensRevokeCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
configsTokensRevokeCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
configsTokensRevokeCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs)
if err := configsTokensRevokeCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs); err != nil {
utils.HandleError(err)
}
configsTokensCmd.AddCommand(configsTokensRevokeCmd)
}
56 changes: 42 additions & 14 deletions pkg/cmd/enclave_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,45 @@ var enclaveConfigsUnlockCmd = &cobra.Command{

func init() {
enclaveConfigsCmd.Flags().StringP("project", "p", "", "enclave project (e.g. backend)")
enclaveConfigsCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := enclaveConfigsCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
enclaveConfigsCmd.Flags().StringP("environment", "e", "", "config environment")
enclaveConfigsCmd.RegisterFlagCompletionFunc("environment", configEnvironmentIDsValidArgs)
if err := enclaveConfigsCmd.RegisterFlagCompletionFunc("environment", configEnvironmentIDsValidArgs); err != nil {
utils.HandleError(err)
}
enclaveConfigsCmd.Flags().IntP("number", "n", 100, "max number of configs to display")
enclaveConfigsCmd.Flags().Int("page", 1, "page to display")

enclaveConfigsGetCmd.Flags().StringP("project", "p", "", "enclave project (e.g. backend)")
enclaveConfigsGetCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := enclaveConfigsGetCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
enclaveConfigsGetCmd.Flags().StringP("config", "c", "", "enclave config (e.g. dev)")
enclaveConfigsGetCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs)
if err := enclaveConfigsGetCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs); err != nil {
utils.HandleError(err)
}
enclaveConfigsCmd.AddCommand(enclaveConfigsGetCmd)

enclaveConfigsCreateCmd.Flags().StringP("project", "p", "", "enclave project (e.g. backend)")
enclaveConfigsCreateCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := enclaveConfigsCreateCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
enclaveConfigsCreateCmd.Flags().String("name", "", "config name")
enclaveConfigsCreateCmd.Flags().StringP("environment", "e", "", "config environment")
enclaveConfigsCreateCmd.RegisterFlagCompletionFunc("environment", configEnvironmentIDsValidArgs)
if err := enclaveConfigsCreateCmd.RegisterFlagCompletionFunc("environment", configEnvironmentIDsValidArgs); err != nil {
utils.HandleError(err)
}
enclaveConfigsCmd.AddCommand(enclaveConfigsCreateCmd)

enclaveConfigsUpdateCmd.Flags().StringP("project", "p", "", "enclave project (e.g. backend)")
enclaveConfigsUpdateCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := enclaveConfigsUpdateCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
enclaveConfigsUpdateCmd.Flags().StringP("config", "c", "", "enclave config (e.g. dev)")
enclaveConfigsUpdateCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs)
if err := enclaveConfigsUpdateCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs); err != nil {
utils.HandleError(err)
}
enclaveConfigsUpdateCmd.Flags().String("name", "", "config name")
if err := enclaveConfigsUpdateCmd.MarkFlagRequired("name"); err != nil {
utils.HandleError(err)
Expand All @@ -123,23 +139,35 @@ func init() {
enclaveConfigsCmd.AddCommand(enclaveConfigsUpdateCmd)

enclaveConfigsDeleteCmd.Flags().StringP("project", "p", "", "enclave project (e.g. backend)")
enclaveConfigsDeleteCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := enclaveConfigsDeleteCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
enclaveConfigsDeleteCmd.Flags().StringP("config", "c", "", "enclave config (e.g. dev)")
enclaveConfigsDeleteCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs)
if err := enclaveConfigsDeleteCmd.RegisterFlagCompletionFunc("config", configNamesValidArgs); err != nil {
utils.HandleError(err)
}
enclaveConfigsDeleteCmd.Flags().BoolP("yes", "y", false, "proceed without confirmation")
enclaveConfigsCmd.AddCommand(enclaveConfigsDeleteCmd)

enclaveConfigsLockCmd.Flags().StringP("project", "p", "", "enclave project (e.g. backend)")
enclaveConfigsLockCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := enclaveConfigsLockCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
enclaveConfigsLockCmd.Flags().StringP("config", "c", "", "enclave config (e.g. dev)")
enclaveConfigsLockCmd.RegisterFlagCompletionFunc("config", lockedConfigNamesValidArgs)
if err := enclaveConfigsLockCmd.RegisterFlagCompletionFunc("config", lockedConfigNamesValidArgs); err != nil {
utils.HandleError(err)
}
enclaveConfigsLockCmd.Flags().BoolP("yes", "y", false, "proceed without confirmation")
enclaveConfigsCmd.AddCommand(enclaveConfigsLockCmd)

enclaveConfigsUnlockCmd.Flags().StringP("project", "p", "", "enclave project (e.g. backend)")
enclaveConfigsUnlockCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs)
if err := enclaveConfigsUnlockCmd.RegisterFlagCompletionFunc("project", projectIDsValidArgs); err != nil {
utils.HandleError(err)
}
enclaveConfigsUnlockCmd.Flags().StringP("config", "c", "", "enclave config (e.g. dev)")
enclaveConfigsUnlockCmd.RegisterFlagCompletionFunc("config", unlockedConfigNamesValidArgs)
if err := enclaveConfigsUnlockCmd.RegisterFlagCompletionFunc("config", unlockedConfigNamesValidArgs); err != nil {
utils.HandleError(err)
}
enclaveConfigsUnlockCmd.Flags().BoolP("yes", "y", false, "proceed without confirmation")
enclaveConfigsCmd.AddCommand(enclaveConfigsUnlockCmd)

Expand Down
Loading

0 comments on commit 9b13e87

Please sign in to comment.