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

Refactor to avoid not necessary conversion #539

Merged
merged 1 commit into from
Aug 13, 2021
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
6 changes: 3 additions & 3 deletions cmd/cosign/cli/verify_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (c *VerifyManifestCommand) Exec(ctx context.Context, args []string) error {
return fmt.Errorf("could not read manifest: %v", err)
}

images, err := getImagesFromYamlManifest(string(manifest))
images, err := getImagesFromYamlManifest(manifest)
if err != nil {
return fmt.Errorf("unable to extract the container image references in the manifest %v", err)
}
Expand All @@ -116,8 +116,8 @@ func (c *VerifyManifestCommand) Exec(ctx context.Context, args []string) error {
return c.VerifyCommand.Exec(ctx, images)
}

func getImagesFromYamlManifest(manifest string) ([]string, error) {
dec := yaml.NewYAMLOrJSONDecoder(bytes.NewReader([]byte(manifest)), 4096)
func getImagesFromYamlManifest(manifest []byte) ([]string, error) {
dec := yaml.NewYAMLOrJSONDecoder(bytes.NewReader(manifest), 4096)
cScheme := runtime.NewScheme()
var images []string
if err := corev1.AddToScheme(cScheme); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions cmd/cosign/cli/verify_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,27 @@ spec:
func TestGetImagesFromYamlManifest(t *testing.T) {
testCases := []struct {
name string
fileContents string
fileContents []byte
expected []string
}{
{
name: "single image",
fileContents: SingleContainerManifest,
fileContents: []byte(SingleContainerManifest),
expected: []string{"nginx:1.21.1"},
},
{
name: "multi image",
fileContents: MultiContainerManifest,
fileContents: []byte(MultiContainerManifest),
expected: []string{"nginx:1.21.1", "ubuntu:21.10"},
},
{
name: "multiple resources and images within a document",
fileContents: MultiResourceContainerManifest,
fileContents: []byte(MultiResourceContainerManifest),
expected: []string{"nginx:1.14.2", "nginx:1.21.1", "ubuntu:21.10"},
},
{
name: "no images found",
fileContents: ``,
fileContents: []byte(``),
expected: nil,
},
}
Expand Down