(ctx context.Context, a *coreauth.Auth, provider, authKind string, excluded []string)
| 1172 | } |
| 1173 | |
| 1174 | func (s *Service) tryRegisterPluginModelsForAuth(ctx context.Context, a *coreauth.Auth, provider, authKind string, excluded []string) bool { |
| 1175 | if s == nil || s.pluginHost == nil || a == nil { |
| 1176 | return false |
| 1177 | } |
| 1178 | result := s.pluginHost.ModelsForAuth(ctx, a) |
| 1179 | if !result.Handled { |
| 1180 | return false |
| 1181 | } |
| 1182 | if result.Err != nil { |
| 1183 | return true |
| 1184 | } |
| 1185 | activeAuth := a |
| 1186 | providerKey := strings.ToLower(strings.TrimSpace(result.Provider)) |
| 1187 | if providerKey == "" { |
| 1188 | providerKey = strings.ToLower(strings.TrimSpace(provider)) |
| 1189 | } |
| 1190 | if result.Auth != nil && s.coreManager != nil { |
| 1191 | result.Auth.ID = a.ID |
| 1192 | if result.Auth.Provider == "" { |
| 1193 | result.Auth.Provider = a.Provider |
| 1194 | } |
| 1195 | if result.Auth.FileName == "" { |
| 1196 | result.Auth.FileName = a.FileName |
| 1197 | } |
| 1198 | if result.Auth.Attributes == nil { |
| 1199 | result.Auth.Attributes = make(map[string]string) |
| 1200 | } |
| 1201 | for key, value := range a.Attributes { |
| 1202 | if _, exists := result.Auth.Attributes[key]; !exists { |
| 1203 | result.Auth.Attributes[key] = value |
| 1204 | } |
| 1205 | } |
| 1206 | if updated, errUpdate := s.coreManager.Update(context.Background(), result.Auth); errUpdate == nil && updated != nil { |
| 1207 | activeAuth = updated.Clone() |
| 1208 | } |
| 1209 | } |
| 1210 | if activeAuth == nil { |
| 1211 | activeAuth = a |
| 1212 | } |
| 1213 | if activeProvider := strings.ToLower(strings.TrimSpace(activeAuth.Provider)); activeProvider != "" { |
| 1214 | providerKey = activeProvider |
| 1215 | } |
| 1216 | if providerKey == "" { |
| 1217 | providerKey = strings.ToLower(strings.TrimSpace(provider)) |
| 1218 | } |
| 1219 | activeAuthKind := activeAuth.AuthKind() |
| 1220 | activeExcluded := s.oauthExcludedModels(providerKey, activeAuthKind) |
| 1221 | if a == activeAuth && len(activeExcluded) == 0 { |
| 1222 | activeExcluded = excluded |
| 1223 | } |
| 1224 | if activeAuth.Attributes != nil { |
| 1225 | if val, ok := activeAuth.Attributes["excluded_models"]; ok && strings.TrimSpace(val) != "" { |
| 1226 | activeExcluded = strings.Split(val, ",") |
| 1227 | } |
| 1228 | } |
| 1229 | models := applyExcludedModels(result.Models, activeExcluded) |
| 1230 | models = applyOAuthModelAliasForAuth(s.cfg, providerKey, activeAuthKind, activeAuth.Attributes, models) |
| 1231 | if len(models) > 0 { |
no test coverage detected