Skip to content

Commit

Permalink
attempt to get first gar registry using provided server url (#4365)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianedwards authored Mar 4, 2024
1 parent 7f2e57a commit 51c3176
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions api/server/handlers/registry/get_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func (c *RegistryGetECRTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Re
// if the aws integration doesn't have an ARN populated, populate it
if awsInt.AWSArn == "" {
err = awsInt.PopulateAWSArn()

if err != nil {
continue
}
Expand Down Expand Up @@ -230,9 +229,13 @@ func (c *RegistryGetGARTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Re
request := &types.GetRegistryGCRTokenRequest{}

if ok := c.DecodeAndValidate(w, r, request); !ok {
err := telemetry.Error(ctx, span, nil, "error decoding request")
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
return
}

telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "server-url", Value: request.ServerURL})

// list registries and find one that matches the region
regs, err := c.Repo().Registry().ListRegistriesByProjectID(proj.ID)
if err != nil {
Expand All @@ -251,18 +254,29 @@ func (c *RegistryGetGARTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Re
var registryURL string

for _, reg := range regs {
if strings.Contains(reg.URL, "-docker.pkg.dev") {
if strings.Contains(reg.URL, request.ServerURL) {
registryURL = reg.URL
break
}
}

if registryURL == "" {
e := telemetry.Error(ctx, span, err, "no matching registry found")
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(e, http.StatusNotFound))
return
for _, reg := range regs {
if strings.Contains(reg.URL, "-docker.pkg.dev") {
registryURL = reg.URL
break
}
}

if registryURL == "" {
e := telemetry.Error(ctx, span, err, "no matching registry found")
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(e, http.StatusNotFound))
return
}
}

telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "registry-url", Value: registryURL})

regInput := connect.NewRequest(&porterv1.TokenForRegistryRequest{
ProjectId: int64(proj.ID),
RegistryUri: registryURL,
Expand Down

0 comments on commit 51c3176

Please sign in to comment.