ResolveAs returns the effective identity type. If the user explicitly passed --as, use that value; otherwise use the configured default. When the value is "auto" (or unset), auto-detect based on credential hints.
(ctx context.Context, cmd *cobra.Command, flagAs core.Identity)
| 61 | // If the user explicitly passed --as, use that value; otherwise use the configured default. |
| 62 | // When the value is "auto" (or unset), auto-detect based on credential hints. |
| 63 | func (f *Factory) ResolveAs(ctx context.Context, cmd *cobra.Command, flagAs core.Identity) core.Identity { |
| 64 | f.IdentityAutoDetected = false |
| 65 | |
| 66 | if cmd != nil && cmd.Flags().Changed("as") { |
| 67 | if flagAs != core.AsAuto { |
| 68 | f.ResolvedIdentity = flagAs |
| 69 | return flagAs |
| 70 | } |
| 71 | // --as auto: fall through to auto-detect |
| 72 | } |
| 73 | |
| 74 | mode := f.ResolveStrictMode(ctx) |
| 75 | // Strict mode forces implicit identity choices. Explicit --as user/bot is |
| 76 | // preserved above so CheckStrictMode can reject incompatible requests. |
| 77 | if forced := mode.ForcedIdentity(); forced != "" { |
| 78 | f.ResolvedIdentity = forced |
| 79 | return forced |
| 80 | } |
| 81 | |
| 82 | hint := f.resolveIdentityHint(ctx) |
| 83 | if cmd == nil || !cmd.Flags().Changed("as") { |
| 84 | if defaultAs := resolveDefaultAsFromHint(hint); defaultAs != "" && defaultAs != core.AsAuto { |
| 85 | f.ResolvedIdentity = defaultAs |
| 86 | return f.ResolvedIdentity |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | // Auto-detect based on credential hint |
| 91 | f.IdentityAutoDetected = true |
| 92 | result := autoDetectIdentityFromHint(hint) |
| 93 | f.ResolvedIdentity = result |
| 94 | return result |
| 95 | } |
| 96 | |
| 97 | func resolveDefaultAsFromHint(hint *credential.IdentityHint) core.Identity { |
| 98 | if hint != nil { |