Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert image digest to manifest digest, Switch to use digest.Hex inst… #12040

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 6 additions & 30 deletions pkg/sign/notary.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ type ReferenceInterface interface {
type ImageInterface interface {
// Manifest retrieves the manifest of the image.
Manifest() (ManifestInterface, error)
// GetDigest returns the digest of the image manifest.
GetDigest() (string, error)
// GetSize returns the size of the image.
GetSize() (int64, error)
}

// ManifestInterface abstracts the functionality of v1.Manifest.
Expand Down Expand Up @@ -123,20 +119,6 @@ type ImageWrapper struct {
img v1.Image
}

// GetDigest returns the digest of the image manifest.
func (iw *ImageWrapper) GetDigest() (string, error) {
digest, err := iw.img.Digest()
if err != nil {
return "", err
}
return digest.Hex, nil
}

// GetSize returns the size of the image.
func (iw *ImageWrapper) GetSize() (int64, error) {
return iw.img.Size()
}

// Manifest retrieves the manifest of the image.
func (iw *ImageWrapper) Manifest() (ManifestInterface, error) {
manifest, err := iw.img.Manifest()
Expand All @@ -156,7 +138,7 @@ func (mw *ManifestWrapper) GetConfigSize() int64 {
return mw.manifest.Config.Size
}

// GetConfigDigest returns the digest of the image config without the algorithm prefix.
// GetConfigDigest returns the digest of the image config.
func (mw *ManifestWrapper) GetConfigDigest() string {
return mw.manifest.Config.Digest.Hex
}
Expand Down Expand Up @@ -195,23 +177,17 @@ func (pb *PayloadBuilder) BuildPayload(images []string) (SigningPayload, error)
return SigningPayload{}, fmt.Errorf("failed to fetch image: %w", err)
}

// Retrieve the image manifest digest.
imageDigest, err := img.GetDigest()
if err != nil {
return SigningPayload{}, fmt.Errorf("failed to get image digest: %w", err)
}

// Retrieve the image size.
imageSize, err := img.GetSize()
// Retrieve the image manifest.
manifest, err := img.Manifest()
if err != nil {
return SigningPayload{}, fmt.Errorf("failed to get image size: %w", err)
return SigningPayload{}, fmt.Errorf("failed to get image manifest: %w", err)
}

// Build the target information.
target := Target{
Name: tag,
ByteSize: imageSize,
Digest: imageDigest,
ByteSize: manifest.GetConfigSize(),
Digest: manifest.GetConfigDigest(),
}

// Build the GUN (Global Unique Name) targets.
Expand Down
42 changes: 2 additions & 40 deletions pkg/sign/notary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ func TestImageService_GetImage_Valid(t *testing.T) {
},
}, nil
},
MockGetDigest: func() (string, error) {
return "dummy-digest", nil
},
MockGetSize: func() (int64, error) {
return 1024, nil
},
}, nil
},
}
Expand All @@ -159,23 +153,6 @@ func TestImageService_GetImage_Valid(t *testing.T) {
if manifest.GetConfigDigest() != "sha256:dummy-digest" {
t.Errorf("Expected config digest to be 'sha256:dummy-digest', got '%s'", manifest.GetConfigDigest())
}

// Additional checks for new methods
digest, err := img.GetDigest()
if err != nil {
t.Errorf("Expected no error getting digest, got %v", err)
}
if digest != "dummy-digest" {
t.Errorf("Expected digest to be 'dummy-digest', got '%s'", digest)
}

size, err := img.GetSize()
if err != nil {
t.Errorf("Expected no error getting size, got %v", err)
}
if size != 1024 {
t.Errorf("Expected size to be 1024, got %d", size)
}
}

// TestImageService_GetImage_Invalid checks fetching an invalid image.
Expand Down Expand Up @@ -218,20 +195,14 @@ func TestPayloadBuilder_BuildPayload_Valid(t *testing.T) {
return 1024
},
MockGetConfigDigest: func() string {
return "sha256:dummy-config-digest"
return "sha256:dummy-digest"
},
}

mockImage := &MockImage{
MockManifest: func() (ManifestInterface, error) {
return mockManifest, nil
},
MockGetDigest: func() (string, error) {
return "dummy-manifest-digest", nil
},
MockGetSize: func() (int64, error) {
return 2048, nil
},
}

mockImageRepository := &MockImageRepository{
Expand All @@ -254,15 +225,6 @@ func TestPayloadBuilder_BuildPayload_Valid(t *testing.T) {
if len(payload.GunTargets) == 0 {
t.Errorf("Expected GunTargets to be populated")
}

// Additional checks
target := payload.GunTargets[0].Targets[0]
if target.Digest != "dummy-manifest-digest" {
t.Errorf("Expected digest to be 'dummy-manifest-digest', got '%s'", target.Digest)
}
if target.ByteSize != 2048 {
t.Errorf("Expected byteSize to be 2048, got %d", target.ByteSize)
}
}

// TestPayloadBuilder_BuildPayload_Invalid checks building a payload for invalid images.
Expand Down Expand Up @@ -383,7 +345,7 @@ func TestNotarySigner_Sign_Valid(t *testing.T) {
{
Name: "latest",
ByteSize: 1024,
Digest: "dummy-manifest-digest",
Digest: "sha256:dummy-digest",
},
},
},
Expand Down
Loading