Inspect requirements by profile identity
This commit is contained in:
@@ -15,16 +15,27 @@ type resolvedProfileSelection struct {
|
||||
profile *domain.ExecutionProfile
|
||||
}
|
||||
|
||||
type profileIdentityRepository interface {
|
||||
GetProfileIdentity(context.Context, string) (string, error)
|
||||
}
|
||||
|
||||
func (r *Runner) profileLookupID(profileID string) (string, error) {
|
||||
if strings.TrimSpace(profileID) == "" {
|
||||
return "", fmt.Errorf("%w: profile id is required", ErrInvalidRequest)
|
||||
}
|
||||
if r == nil || r.profiles == nil {
|
||||
return "", fmt.Errorf("%w: profile repository is not configured", ErrProfileLoad)
|
||||
}
|
||||
return profileID, nil
|
||||
}
|
||||
|
||||
func (r *Runner) resolveProfileSelection(
|
||||
ctx context.Context,
|
||||
profileID string,
|
||||
) (*resolvedProfileSelection, error) {
|
||||
lookupID := profileID
|
||||
if strings.TrimSpace(lookupID) == "" {
|
||||
return nil, fmt.Errorf("%w: profile id is required", ErrInvalidRequest)
|
||||
}
|
||||
if r == nil || r.profiles == nil {
|
||||
return nil, fmt.Errorf("%w: profile repository is not configured", ErrProfileLoad)
|
||||
lookupID, err := r.profileLookupID(profileID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selectedProfile, err := r.profiles.GetProfile(ctx, lookupID)
|
||||
if err != nil {
|
||||
@@ -45,6 +56,25 @@ func (r *Runner) resolveProfileSelection(
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Runner) resolveProfileIdentity(ctx context.Context, profileID string) (string, error) {
|
||||
lookupID, err := r.profileLookupID(profileID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if indexed, ok := r.profiles.(profileIdentityRepository); ok {
|
||||
identity, err := indexed.GetProfileIdentity(ctx, lookupID)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("%w: %w", ErrProfileLoad, err)
|
||||
}
|
||||
return identity, nil
|
||||
}
|
||||
selection, err := r.resolveProfileSelection(ctx, lookupID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return selection.id, nil
|
||||
}
|
||||
|
||||
func normalizeResolvedExecutionTarget(target domain.ExecutionTarget) (domain.ExecutionTarget, error) {
|
||||
endpoint, err := domain.NormalizeOpenAICompatibleBaseEndpoint(target.Endpoint)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user