Skip to content

Commit

Permalink
use first gar registry if needed (#4383)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianedwards authored Mar 6, 2024
1 parent 37889b5 commit 4fc1095
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions api/server/handlers/registry/get_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,27 @@ func (c *RegistryGetGARTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Re
}
}

if token == "" && len(regs) > 0 {
_reg := registry.Registry(*regs[0])

oauthTok, err := _reg.GetGARToken(ctx, c.Repo())
if err != nil {
// if the oauth token is not nil, we still return the token but log an error
if oauthTok == nil {
e := telemetry.Error(ctx, span, err, "error getting gar token")
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(e, http.StatusInternalServerError))
return
}
e := telemetry.Error(ctx, span, err, "error getting gar token, but token was returned")
c.HandleAPIErrorNoWrite(w, r, apierrors.NewErrInternal(e))
}

if oauthTok != nil {
token = oauthTok.AccessToken
expiresAt = oauthTok.Expiry
}
}

resp := &types.GetRegistryTokenResponse{
Token: token,
ExpiresAt: expiresAt,
Expand Down

0 comments on commit 4fc1095

Please sign in to comment.