Skip to content

Commit

Permalink
Refactor to avoid not necessary conversion (#539)
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Donizetti <[email protected]>
  • Loading branch information
josedonizetti authored Aug 13, 2021
1 parent e2cafee commit 4c755ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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

0 comments on commit 4c755ad

Please sign in to comment.