Skip to content

Commit

Permalink
Use const for skipAuthCheck annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
mandopaloooza committed Jun 23, 2023
1 parent 711d7dc commit 8b70df8
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func NewCmdCompletion() *cobra.Command {
var completionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Annotations: map[string]string{
"skipAuthCheck": "true",
configuration.SkipAuthCheck: "true",
},
Short: docs.CompletionDocs.Short,
Long: docs.CompletionDocs.Long,
Expand Down
2 changes: 1 addition & 1 deletion cmd/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewCmdConfigure(f *factory.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "configure",
Annotations: map[string]string{
"skipAuthCheck": "true",
configuration.SkipAuthCheck: "true",
},
Short: docs.ConfigureDocs.Short,
Long: docs.ConfigureDocs.Long,
Expand Down
3 changes: 2 additions & 1 deletion cmd/configure/signin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package configure

import (
"fmt"
"github.com/appgate/sdpctl/pkg/configuration"
"io"
"os"

Expand All @@ -27,7 +28,7 @@ func NewSigninCmd(f *factory.Factory) *cobra.Command {
var signinCmd = &cobra.Command{
Use: "signin",
Annotations: map[string]string{
"skipAuthCheck": "true",
configuration.SkipAuthCheck: "true",
},
Aliases: []string{"login"},
Short: docs.ConfigureSigninDocs.Short,
Expand Down
3 changes: 2 additions & 1 deletion cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"compress/gzip"
"errors"
"fmt"
"github.com/appgate/sdpctl/pkg/configuration"
"io"
"io/fs"
"os"
Expand All @@ -32,7 +33,7 @@ var generateCmd = &cobra.Command{
Aliases: []string{"gen"},
Hidden: true,
Annotations: map[string]string{
"skipAuthCheck": "true",
configuration.SkipAuthCheck: "true",
},
DisableFlagsInUseLine: true,
ValidArgs: []string{"man", "html", "all"},
Expand Down
2 changes: 1 addition & 1 deletion cmd/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func NewOpenCmd(f *factory.Factory) *cobra.Command {
return &cobra.Command{
Use: "open",
Annotations: map[string]string{
"skipAuthCheck": "true",
configuration.SkipAuthCheck: "true",
},
Short: "Open the Admin UI in your browser",
RunE: func(c *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewProfileCmd(f *factory.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "profile",
Annotations: map[string]string{
"skipAuthCheck": "true",
configuration.SkipAuthCheck: "true",
},
TraverseChildren: true,
Short: docs.ProfileRootDoc.Short,
Expand Down
4 changes: 3 additions & 1 deletion pkg/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ func DefaultDeviceID() string {
return v
}

const SkipAuthCheck = "skipAuthCheck"

func IsAuthCheckEnabled(cmd *cobra.Command) bool {
switch cmd.Name() {
case "help", cobra.ShellCompRequestCmd, cobra.ShellCompNoDescRequestCmd:
return false
}
for c := cmd; c.Parent() != nil; c = c.Parent() {
if c.Annotations != nil && c.Annotations["skipAuthCheck"] == "true" {
if c.Annotations != nil && c.Annotations[SkipAuthCheck] == "true" {
return false
}
}
Expand Down

0 comments on commit 8b70df8

Please sign in to comment.