diff --git a/client/client_test.go b/client/client_test.go index f98672353cc0..ae175ea3d164 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -7692,8 +7692,9 @@ func testExportAttestations(t *testing.T, sb integration.Sandbox) { for _, p := range ps { var attest intoto.Statement - dt := m[path.Join(strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation.json")].Data - require.NoError(t, json.Unmarshal(dt, &attest)) + item := m[path.Join(strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation.json")] + require.NotNil(t, item) + require.NoError(t, json.Unmarshal(item.Data, &attest)) require.Equal(t, "https://in-toto.io/Statement/v0.1", attest.Type) require.Equal(t, "https://example.com/attestations/v1.0", attest.PredicateType) @@ -7705,8 +7706,9 @@ func testExportAttestations(t *testing.T, sb integration.Sandbox) { }}, attest.Subject) var attest2 intoto.Statement - dt = m[path.Join(strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation2.json")].Data - require.NoError(t, json.Unmarshal(dt, &attest2)) + item = m[path.Join(strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation2.json")] + require.NotNil(t, item) + require.NoError(t, json.Unmarshal(item.Data, &attest2)) require.Equal(t, "https://in-toto.io/Statement/v0.1", attest2.Type) require.Equal(t, "https://example.com/attestations2/v1.0", attest2.PredicateType) diff --git a/exporter/local/export.go b/exporter/local/export.go index 7d08b172e019..7157c63dac80 100644 --- a/exporter/local/export.go +++ b/exporter/local/export.go @@ -20,10 +20,6 @@ import ( "golang.org/x/time/rate" ) -const ( - keyAttestationPrefix = "attestation-prefix" -) - type Opt struct { SessionManager *session.Manager } @@ -39,23 +35,12 @@ func New(opt Opt) (exporter.Exporter, error) { } func (e *localExporter) Resolve(ctx context.Context, opt map[string]string) (exporter.ExporterInstance, error) { - tm, _, err := epoch.ParseExporterAttrs(opt) - if err != nil { - return nil, err - } - i := &localExporterInstance{ localExporter: e, - opts: CreateFSOpts{ - Epoch: tm, - }, } - - for k, v := range opt { - switch k { - case keyAttestationPrefix: - i.opts.AttestationPrefix = v - } + _, err := i.opts.Load(opt) + if err != nil { + return nil, err } return i, nil diff --git a/exporter/local/fs.go b/exporter/local/fs.go index c5a524aae32f..9caf6f73af60 100644 --- a/exporter/local/fs.go +++ b/exporter/local/fs.go @@ -15,6 +15,7 @@ import ( "github.com/moby/buildkit/cache" "github.com/moby/buildkit/exporter" "github.com/moby/buildkit/exporter/attestation" + "github.com/moby/buildkit/exporter/util/epoch" "github.com/moby/buildkit/session" "github.com/moby/buildkit/snapshot" "github.com/moby/buildkit/solver/result" @@ -25,11 +26,36 @@ import ( fstypes "github.com/tonistiigi/fsutil/types" ) +const ( + keyAttestationPrefix = "attestation-prefix" +) + type CreateFSOpts struct { Epoch *time.Time AttestationPrefix string } +func (c *CreateFSOpts) Load(opt map[string]string) (map[string]string, error) { + rest := make(map[string]string) + + var err error + c.Epoch, opt, err = epoch.ParseExporterAttrs(opt) + if err != nil { + return nil, err + } + + for k, v := range opt { + switch k { + case keyAttestationPrefix: + c.AttestationPrefix = v + default: + rest[k] = v + } + } + + return rest, nil +} + func CreateFS(ctx context.Context, sessionID string, k string, ref cache.ImmutableRef, attestations []exporter.Attestation, defaultTime time.Time, opt CreateFSOpts) (fsutil.FS, func() error, error) { var cleanup func() error var src string diff --git a/exporter/tar/export.go b/exporter/tar/export.go index 4d136c89c1ca..7259f6b24a9a 100644 --- a/exporter/tar/export.go +++ b/exporter/tar/export.go @@ -3,7 +3,6 @@ package local import ( "context" "os" - "strconv" "strings" "time" @@ -20,15 +19,6 @@ import ( fstypes "github.com/tonistiigi/fsutil/types" ) -const ( - attestationPrefixKey = "attestation-prefix" - - // preferNondistLayersKey is an exporter option which can be used to mark a layer as non-distributable if the layer reference was - // already found to use a non-distributable media type. - // When this option is not set, the exporter will change the media type of the layer to a distributable one. - preferNondistLayersKey = "prefer-nondist-layers" -) - type Opt struct { SessionManager *session.Manager } @@ -45,33 +35,18 @@ func New(opt Opt) (exporter.Exporter, error) { func (e *localExporter) Resolve(ctx context.Context, opt map[string]string) (exporter.ExporterInstance, error) { li := &localExporterInstance{localExporter: e} - - tm, opt, err := epoch.ParseExporterAttrs(opt) + _, err := li.opts.Load(opt) if err != nil { return nil, err } - li.opts.Epoch = tm - - for k, v := range opt { - switch k { - case preferNondistLayersKey: - b, err := strconv.ParseBool(v) - if err != nil { - return nil, errors.Wrapf(err, "non-bool value for %s: %s", preferNondistLayersKey, v) - } - li.preferNonDist = b - case attestationPrefixKey: - li.opts.AttestationPrefix = v - } - } + _ = opt return li, nil } type localExporterInstance struct { *localExporter - opts local.CreateFSOpts - preferNonDist bool + opts local.CreateFSOpts } func (e *localExporterInstance) Name() string {