Skip to content

Commit 329fc89

Browse files
authored
fix(backend): correct auth key handling for token retrieval (#314)
Signed-off-by: chlins <[email protected]>
1 parent 4bdee95 commit 329fc89

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pkg/backend/pull_by_d7y.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,20 @@ func getAuthToken(ctx context.Context, src *remote.Repository, registry, repo st
141141
return "", fmt.Errorf("failed to get scheme: %w", err)
142142
}
143143

144-
repo = strings.TrimPrefix(repo, registry+"/")
145-
token, err := client.Cache.GetToken(ctx, registry, scheme, fmt.Sprintf("repository:%s:pull", repo))
144+
// Auth key in client cache is different for basic and bearer authentication,
145+
// it is empty for basic but with scope repository:{repo_name}:pull for bearer.
146+
var authKey string
147+
switch scheme {
148+
case auth.SchemeBasic:
149+
authKey = ""
150+
case auth.SchemeBearer:
151+
repo = strings.TrimPrefix(repo, registry+"/")
152+
authKey = fmt.Sprintf("repository:%s:pull", repo)
153+
default:
154+
return "", fmt.Errorf("unsupported scheme: %s", scheme)
155+
}
156+
157+
token, err := client.Cache.GetToken(ctx, registry, scheme, authKey)
146158
if err != nil {
147159
return "", fmt.Errorf("failed to get token: %w", err)
148160
}

0 commit comments

Comments
 (0)