Skip to content

Commit

Permalink
no longer send dockerconfigjson if container.HostedRegistry is true
Browse files Browse the repository at this point in the history
Signed-off-by: Adam D. Cornett <adc@redhat.com>
  • Loading branch information
acornett21 committed Oct 31, 2022
1 parent 577ab6c commit f9cff77
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions certification/pyxis/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type CertProject struct {

type Container struct {
DockerConfigJSON string `json:"docker_config_json,omitempty"`
HostedRegistry bool `json:"hosted_registry,omitempty"`
Type string `json:"type,omitempty"` // conditionally required
ISVPID string `json:"isv_pid,omitempty"` // required
Registry string `json:"registry,omitempty"`
Expand Down
12 changes: 12 additions & 0 deletions internal/lib/fakes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ func gpFuncReturnError(ctx context.Context) (*pyxis.CertProject, error) {
return nil, errors.New("some error returned from the api")
}

// gpFuncReturnHostedRegistry implements gpFunc and returns hosted_registry=true.
func gpFuncReturnHostedRegistry(ctx context.Context) (*pyxis.CertProject, error) {
return &pyxis.CertProject{
ID: "000000000000",
CertificationStatus: "false",
Name: "some-project",
Container: pyxis.Container{
HostedRegistry: true,
},
}, nil
}

// gpFuncReturnScratchException implements gpFunc and returns a scratch exception.
func gpFuncReturnScratchException(ctx context.Context) (*pyxis.CertProject, error) {
return &pyxis.CertProject{
Expand Down
11 changes: 11 additions & 0 deletions internal/lib/lib_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ var _ = Describe("Lib Container Functions", func() {
})
})

Context("and certProject.Container.hosted_registry=true", func() {
BeforeEach(func() {
fakePC.setSRFuncSubmitSuccessfully("", "")
fakePC.getProjectsFunc = gpFuncReturnHostedRegistry
})
It("should not throw an error", func() {
err := sbmt.Submit(context.TODO())
Expect(err).ToNot(HaveOccurred())
})
})

Context("and the cert image cannot be read from disk", func() {
It("should throw an error", func() {
err := os.Remove(path.Join(artifacts.Path(), certification.DefaultCertImageFilename))
Expand Down
6 changes: 6 additions & 0 deletions internal/lib/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ func (s *ContainerCertificationSubmitter) Submit(ctx context.Context) error {
certProject.Container.DockerConfigJSON = ""
}

// no longer set DockerConfigJSON for registries which Red Hat hosts, this prevents the user from sending an invalid
// docker file that systems like clair and registry-proxy cannot use to pull the image
if certProject.Container.HostedRegistry {
certProject.Container.DockerConfigJSON = ""
}

// prepare submission. We ignore the error because nil checks for the certProject
// are done earlier to prevent panics, and that's the only error case for this function.
submission, _ := pyxis.NewCertificationInput(certProject)
Expand Down

0 comments on commit f9cff77

Please sign in to comment.