(ctx context.Context, executor ProviderExecutor, auth *Auth)
| 2836 | } |
| 2837 | |
| 2838 | func (m *Manager) prepareRequestAuth(ctx context.Context, executor ProviderExecutor, auth *Auth) (*Auth, error) { |
| 2839 | if m == nil || executor == nil || auth == nil { |
| 2840 | return auth, nil |
| 2841 | } |
| 2842 | preparer, ok := executor.(RequestAuthPreparer) |
| 2843 | if !ok || preparer == nil || !preparer.ShouldPrepareRequestAuth(auth) { |
| 2844 | return auth, nil |
| 2845 | } |
| 2846 | |
| 2847 | id := strings.TrimSpace(auth.ID) |
| 2848 | if id == "" { |
| 2849 | return preparer.PrepareRequestAuth(ctx, auth.Clone()) |
| 2850 | } |
| 2851 | |
| 2852 | lockValue, _ := m.requestPrepareLocks.LoadOrStore(id, &requestAuthPrepareLock{}) |
| 2853 | lock, ok := lockValue.(*requestAuthPrepareLock) |
| 2854 | if !ok || lock == nil { |
| 2855 | return preparer.PrepareRequestAuth(ctx, auth.Clone()) |
| 2856 | } |
| 2857 | |
| 2858 | lock.mu.Lock() |
| 2859 | defer lock.mu.Unlock() |
| 2860 | |
| 2861 | target := auth.Clone() |
| 2862 | m.mu.RLock() |
| 2863 | if current := m.auths[id]; current != nil { |
| 2864 | target = current.Clone() |
| 2865 | } |
| 2866 | m.mu.RUnlock() |
| 2867 | |
| 2868 | if !preparer.ShouldPrepareRequestAuth(target) { |
| 2869 | return target, nil |
| 2870 | } |
| 2871 | |
| 2872 | updated, errPrepare := preparer.PrepareRequestAuth(ctx, target) |
| 2873 | if errPrepare != nil { |
| 2874 | return auth, errPrepare |
| 2875 | } |
| 2876 | if updated == nil { |
| 2877 | return target, nil |
| 2878 | } |
| 2879 | |
| 2880 | saved, errUpdate := m.Update(ctx, updated) |
| 2881 | if errUpdate != nil { |
| 2882 | return updated, errUpdate |
| 2883 | } |
| 2884 | if saved != nil { |
| 2885 | return saved, nil |
| 2886 | } |
| 2887 | return updated, nil |
| 2888 | } |
| 2889 | |
| 2890 | func contextWithRequestedModelAlias(ctx context.Context, opts cliproxyexecutor.Options, fallback string) context.Context { |
| 2891 | alias := requestedModelAliasFromOptions(opts, fallback) |
no test coverage detected