CheckIdentity verifies the resolved identity is in the supported list. On success, sets f.ResolvedIdentity. On failure, returns an error tailored to whether the identity was explicit (--as) or auto-detected.
(as core.Identity, supported []string)
| 123 | // On success, sets f.ResolvedIdentity. On failure, returns an error |
| 124 | // tailored to whether the identity was explicit (--as) or auto-detected. |
| 125 | func (f *Factory) CheckIdentity(as core.Identity, supported []string) error { |
| 126 | for _, t := range supported { |
| 127 | if string(as) == t { |
| 128 | f.ResolvedIdentity = as |
| 129 | return nil |
| 130 | } |
| 131 | } |
| 132 | list := strings.Join(supported, ", ") |
| 133 | if f.IdentityAutoDetected { |
| 134 | base := errs.NewValidationError(errs.SubtypeInvalidArgument, |
| 135 | "resolved identity %q (via auto-detect or default-as) is not supported, this command only supports: %s", |
| 136 | as, list). |
| 137 | WithParam("--as") |
| 138 | if len(supported) > 0 { |
| 139 | return base.WithHint("use --as %s", supported[0]) |
| 140 | } |
| 141 | return base |
| 142 | } |
| 143 | return errs.NewValidationError(errs.SubtypeInvalidArgument, |
| 144 | "--as %s is not supported, this command only supports: %s", as, list). |
| 145 | WithParam("--as") |
| 146 | } |
| 147 | |
| 148 | // ResolveStrictMode returns the effective strict mode by reading |
| 149 | // Account.SupportedIdentities from the credential provider chain. |