resolveExternalAuth finds the external auth config matching the given remote origin URL and returns both the provider type string (e.g. "github") and the gitprovider.Provider. Returns ("", nil) if no matching config is found or no provider could be constructed.
(ctx context.Context, origin string)
| 4251 | // (e.g. "github") and the gitprovider.Provider. Returns ("", nil) |
| 4252 | // if no matching config is found or no provider could be constructed. |
| 4253 | func (api *API) resolveExternalAuth(ctx context.Context, origin string) (providerType string, gp gitprovider.Provider) { |
| 4254 | origin = strings.TrimSpace(origin) |
| 4255 | if origin == "" { |
| 4256 | return "", nil |
| 4257 | } |
| 4258 | for _, extAuth := range api.ExternalAuthConfigs { |
| 4259 | if extAuth.Regex == nil || !extAuth.Regex.MatchString(origin) { |
| 4260 | continue |
| 4261 | } |
| 4262 | p, err := extAuth.Git(api.HTTPClient) |
| 4263 | if err != nil { |
| 4264 | api.Logger.Warn(ctx, "failed to construct git provider", |
| 4265 | slog.F("provider_id", extAuth.ID), |
| 4266 | slog.F("provider_type", extAuth.Type), |
| 4267 | slog.Error(err), |
| 4268 | ) |
| 4269 | continue |
| 4270 | } |
| 4271 | if p == nil { |
| 4272 | continue |
| 4273 | } |
| 4274 | return strings.ToLower(strings.TrimSpace(extAuth.Type)), p |
| 4275 | } |
| 4276 | return "", nil |
| 4277 | } |
| 4278 | |
| 4279 | // resolveGitProvider finds the external auth config matching the |
| 4280 | // given remote origin URL and returns its git provider. Returns |
no test coverage detected