Skip to content

Commit

Permalink
Merge pull request #507 from redhat-openshift-ecosystem/fix_layers_url
Browse files Browse the repository at this point in the history
fix url for call to search for layers
  • Loading branch information
bcrochet authored Mar 22, 2022
2 parents c75bfed + 935ce26 commit 5feddae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions certification/internal/policy/container/base_on_ubi.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (p *BasedOnUBICheck) checkRedHatLayers(ctx context.Context, layerHashes []c
if certImages != nil && len(certImages) >= 1 {
return true, nil
}
log.Error("No matching layer ids found in pyxis db. Please verify if the image is based on a recent UBI image")
return false, nil
}

Expand Down
10 changes: 6 additions & 4 deletions certification/pyxis/layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"strings"

cranev1 "github.com/google/go-containerregistry/pkg/v1"
Expand All @@ -18,13 +19,14 @@ func (p *pyxisEngine) CheckRedHatLayers(ctx context.Context, layerHashes []crane
for _, layer := range layerHashes {
layerIds = append(layerIds, layer.String())
}

log.Tracef("the layerIds passed to pyxis are %s", layerIds)

pyxisQuery := url.QueryEscape(fmt.Sprintf("repositories.registry=in=(registry.access.redhat.com) and uncompressed_top_layer_id=in=(%s)", strings.Join(layerIds, ",")))

req, err := p.newRequestWithApiToken(
ctx,
http.MethodGet,
getPyxisUrl(fmt.Sprintf("filter=repositories.registry=eq=(registry.access.redhat.com) and uncompressed_top_layer_id=in=(%s)", strings.Join(layerIds, ","))),
fmt.Sprintf("%s?filter=%s", getPyxisUrl("images"), pyxisQuery),
nil,
)
if err != nil {
Expand All @@ -43,15 +45,15 @@ func (p *pyxisEngine) CheckRedHatLayers(ctx context.Context, layerHashes []crane
log.Error("Unexpected Status Code", err)
return nil, errors.New(err)
}

defer resp.Body.Close()

body, err := io.ReadAll(resp.Body)
if err != nil {
log.Error(err)
return nil, err
}

log.Tracef("query response from pyxis %s", string(body))

type imageList struct {
Images []CertImage `json:"data"`
}
Expand Down

0 comments on commit 5feddae

Please sign in to comment.