Skip to content

Commit c879240

Browse files
committed
fix auth method
1 parent 80cfeb4 commit c879240

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

cmd/root.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,25 @@ func getKernelClient(cmd *cobra.Command) kernel.Client {
7171
return util.GetKernelClient(cmd)
7272
}
7373

74-
// isAuthExempt returns true if the command or any of its parents should skip auth.
74+
// isAuthExempt returns true if the command should skip auth.
7575
func isAuthExempt(cmd *cobra.Command) bool {
76-
// bare root command does not need auth
76+
// Root command doesn't need auth
7777
if cmd == rootCmd {
7878
return true
7979
}
80-
for c := cmd; c != nil; c = c.Parent() {
81-
switch c.Name() {
82-
case "login", "logout", "auth", "help", "completion",
83-
"create":
84-
return true
85-
}
80+
81+
// Walk up to find the top-level command (direct child of rootCmd)
82+
topLevel := cmd
83+
for topLevel.Parent() != nil && topLevel.Parent() != rootCmd {
84+
topLevel = topLevel.Parent()
85+
}
86+
87+
// Check if the top-level command is in the exempt list
88+
switch topLevel.Name() {
89+
case "login", "logout", "auth", "help", "completion", "create":
90+
return true
8691
}
92+
8793
return false
8894
}
8995

0 commit comments

Comments
 (0)