| 39 | } |
| 40 | |
| 41 | func IsAuthCheckEnabled(cmd *cobra.Command) bool { |
| 42 | switch cmd.Name() { |
| 43 | case "help", cobra.ShellCompRequestCmd, cobra.ShellCompNoDescRequestCmd: |
| 44 | return false |
| 45 | } |
| 46 | |
| 47 | for c := cmd; c.Parent() != nil; c = c.Parent() { |
| 48 | // Check whether any command marked as DisableAuthCheck is set |
| 49 | if c.Annotations != nil && c.Annotations[skipAuthCheckAnnotation] == "true" { |
| 50 | return false |
| 51 | } |
| 52 | |
| 53 | // Check whether any flag marked as DisableAuthCheckFlag is set |
| 54 | var skipAuthCheck bool |
| 55 | c.Flags().Visit(func(f *pflag.Flag) { |
| 56 | if f.Annotations != nil && reflect.DeepEqual(f.Annotations[skipAuthCheckAnnotation], []string{"true"}) { |
| 57 | skipAuthCheck = true |
| 58 | } |
| 59 | }) |
| 60 | if skipAuthCheck { |
| 61 | return false |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return true |
| 66 | } |