From c8c148c70a0e34ed3f78bd61cbc94593e9b5199c Mon Sep 17 00:00:00 2001 From: James Carnegie Date: Fri, 31 May 2024 11:02:14 +0100 Subject: [PATCH] Expose ParsePlatform (#45) --- pkg/oci/oci.go | 8 ++++---- pkg/oci/oci_test.go | 6 +++--- pkg/oci/resolver.go | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/oci/oci.go b/pkg/oci/oci.go index 98aad3d..1ee2645 100644 --- a/pkg/oci/oci.go +++ b/pkg/oci/oci.go @@ -20,9 +20,9 @@ import ( "github.com/pkg/errors" ) -// parsePlatform parses the provided platform string or attempts to obtain +// ParsePlatform parses the provided platform string or attempts to obtain // the platform of the current host system -func parsePlatform(platformStr string) (*v1.Platform, error) { +func ParsePlatform(platformStr string) (*v1.Platform, error) { if platformStr == "" { cdp := platforms.Normalize(platforms.DefaultSpec()) if cdp.OS != "windows" { @@ -106,7 +106,7 @@ type OCILayoutResolver struct { } func NewOCILayoutAttestationResolver(path string, platform string) (*OCILayoutResolver, error) { - p, err := parsePlatform(platform) + p, err := ParsePlatform(platform) if err != nil { return nil, err } @@ -202,7 +202,7 @@ type RegistryResolver struct { } func NewRegistryAttestationResolver(image string, platform string) (*RegistryResolver, error) { - p, err := parsePlatform(platform) + p, err := ParsePlatform(platform) if err != nil { return nil, err } diff --git a/pkg/oci/oci_test.go b/pkg/oci/oci_test.go index a920331..953979f 100644 --- a/pkg/oci/oci_test.go +++ b/pkg/oci/oci_test.go @@ -10,7 +10,7 @@ import ( ) func TestRefToPurl(t *testing.T) { - arm, err := parsePlatform("arm64/linux") + arm, err := ParsePlatform("arm64/linux") require.NoError(t, err) purl, canonical, err := RefToPURL("alpine", arm) assert.NoError(t, err) @@ -73,13 +73,13 @@ func TestImageDigestForPlatform(t *testing.T) { mfs2, err := mfs.IndexManifest() assert.NoError(t, err) - p, err := parsePlatform("linux/amd64") + p, err := ParsePlatform("linux/amd64") assert.NoError(t, err) digest, err := imageDigestForPlatform(mfs2, p) assert.NoError(t, err) assert.Equal(t, "sha256:da8b190665956ea07890a0273e2a9c96bfe291662f08e2860e868eef69c34620", digest) - p, err = parsePlatform("linux/arm64") + p, err = ParsePlatform("linux/arm64") assert.NoError(t, err) digest, err = imageDigestForPlatform(mfs2, p) assert.NoError(t, err) diff --git a/pkg/oci/resolver.go b/pkg/oci/resolver.go index 595eeec..02d1f71 100644 --- a/pkg/oci/resolver.go +++ b/pkg/oci/resolver.go @@ -42,5 +42,5 @@ func (r MockResolver) ImageDigest(ctx context.Context) (string, error) { } func (r MockResolver) ImagePlatform() (*v1.Platform, error) { - return parsePlatform("linux/amd64") + return ParsePlatform("linux/amd64") }