Skip to content

Commit

Permalink
use PreRunE instead of Args for functions utilizing config values
Browse files Browse the repository at this point in the history
in cases where all credentials are resolved without config file (environment variables)
we need to run these functions in the right order, first resolve the root.PersistentPreRunE (to resolve the bearer token etcetra)
after we have resolved those values, we can continue with the sub-command and correctly assert opts.Appliance() without having to worry about
empty Authorization header value, which is the current case in the main branch.

This PR fixes cases where we have disabled keyring and do not persist the bearer token value, as example:

```bash
SDPCTL_URL=https://controller.appgate.devops:8443/ SDPCTL_API_VERSION=19 SDPCTL_NO_KEYRING=true SDPCTL_USERNAME=usernmaeSDPCTL_PASSWORD=the_password sdpctl appliance export-seed
```
  • Loading branch information
dlnilsson committed Jul 17, 2023
1 parent 2a88915 commit 96565db
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/appliance/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewLogsCmd(f *factory.Factory) *cobra.Command {
Short: docs.ApplianceLogsDoc.Short,
Long: docs.ApplianceLogsDoc.Short,
Example: docs.ApplianceLogsDoc.ExampleString(),
Args: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, args []string) error {
return cmdappliance.ArgsSelectAppliance(cmd, args, &opts.AppliancCmdOpts)
},
RunE: func(c *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/appliance/maintenance/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewDisableCmd(f *factory.Factory) *cobra.Command {
Short: docs.MaintenanceDisable.Short,
Long: docs.MaintenanceDisable.Long,
Example: docs.MaintenanceDisable.ExampleString(),
Args: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, args []string) error {
return toggleArgs(cmd, &opts, args)
},
RunE: func(c *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/appliance/maintenance/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewEnableCmd(f *factory.Factory) *cobra.Command {
Short: docs.MaintenanceEnable.Short,
Long: docs.MaintenanceEnable.Long,
Example: docs.MaintenanceEnable.ExampleString(),
Args: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, args []string) error {
return toggleArgs(cmd, &opts, args)
},
RunE: func(c *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/appliance/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewMetricCmd(f *factory.Factory) *cobra.Command {
Long: docs.ApplianceMetricsDoc.Long,
Example: docs.ApplianceMetricsDoc.ExampleString(),
Aliases: []string{"metrics"},
Args: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
a, err := opts.Appliance(opts.Config)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/appliance/resolve_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewResolveNameCmd(f *factory.Factory) *cobra.Command {
Short: docs.ApplianceResolveNameDoc.Short,
Long: docs.ApplianceResolveNameDoc.Long,
Example: docs.ApplianceResolveNameDoc.ExampleString(),
Args: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, args []string) error {
a, err := opts.Appliance(opts.Config)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/appliance/resolve_name_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewResolveNameStatusCmd(f *factory.Factory) *cobra.Command {
Short: docs.ApplianceResolveNameStatusDoc.Short,
Long: docs.ApplianceResolveNameStatusDoc.Long,
Example: docs.ApplianceResolveNameStatusDoc.ExampleString(),
Args: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, args []string) error {
a, err := opts.Appliance(opts.Config)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/appliance/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewSeedCmd(f *factory.Factory) *cobra.Command {
Short: docs.ApplianceSeedDocs.Short,
Long: docs.ApplianceSeedDocs.Long,
Example: docs.ApplianceSeedDocs.ExampleString(),
Args: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, args []string) error {
noInteractive, err := cmd.Flags().GetBool("no-interactive")
if err != nil {
return err
Expand Down

0 comments on commit 96565db

Please sign in to comment.