Skip to content

Commit 268225c

Browse files
authored
Merge pull request moby#3465 from jedevc/exporter-fixups
2 parents c36941f + 9ba004c commit 268225c

File tree

4 files changed

+38
-50
lines changed

4 files changed

+38
-50
lines changed

client/client_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7693,8 +7693,9 @@ func testExportAttestations(t *testing.T, sb integration.Sandbox) {
76937693

76947694
for _, p := range ps {
76957695
var attest intoto.Statement
7696-
dt := m[path.Join(strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation.json")].Data
7697-
require.NoError(t, json.Unmarshal(dt, &attest))
7696+
item := m[path.Join(strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation.json")]
7697+
require.NotNil(t, item)
7698+
require.NoError(t, json.Unmarshal(item.Data, &attest))
76987699

76997700
require.Equal(t, "https://in-toto.io/Statement/v0.1", attest.Type)
77007701
require.Equal(t, "https://example.com/attestations/v1.0", attest.PredicateType)
@@ -7706,8 +7707,9 @@ func testExportAttestations(t *testing.T, sb integration.Sandbox) {
77067707
}}, attest.Subject)
77077708

77087709
var attest2 intoto.Statement
7709-
dt = m[path.Join(strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation2.json")].Data
7710-
require.NoError(t, json.Unmarshal(dt, &attest2))
7710+
item = m[path.Join(strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation2.json")]
7711+
require.NotNil(t, item)
7712+
require.NoError(t, json.Unmarshal(item.Data, &attest2))
77117713

77127714
require.Equal(t, "https://in-toto.io/Statement/v0.1", attest2.Type)
77137715
require.Equal(t, "https://example.com/attestations2/v1.0", attest2.PredicateType)

exporter/local/export.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ import (
2020
"golang.org/x/time/rate"
2121
)
2222

23-
const (
24-
keyAttestationPrefix = "attestation-prefix"
25-
)
26-
2723
type Opt struct {
2824
SessionManager *session.Manager
2925
}
@@ -39,23 +35,12 @@ func New(opt Opt) (exporter.Exporter, error) {
3935
}
4036

4137
func (e *localExporter) Resolve(ctx context.Context, opt map[string]string) (exporter.ExporterInstance, error) {
42-
tm, _, err := epoch.ParseExporterAttrs(opt)
43-
if err != nil {
44-
return nil, err
45-
}
46-
4738
i := &localExporterInstance{
4839
localExporter: e,
49-
opts: CreateFSOpts{
50-
Epoch: tm,
51-
},
5240
}
53-
54-
for k, v := range opt {
55-
switch k {
56-
case keyAttestationPrefix:
57-
i.opts.AttestationPrefix = v
58-
}
41+
_, err := i.opts.Load(opt)
42+
if err != nil {
43+
return nil, err
5944
}
6045

6146
return i, nil

exporter/local/fs.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/moby/buildkit/cache"
1616
"github.com/moby/buildkit/exporter"
1717
"github.com/moby/buildkit/exporter/attestation"
18+
"github.com/moby/buildkit/exporter/util/epoch"
1819
"github.com/moby/buildkit/session"
1920
"github.com/moby/buildkit/snapshot"
2021
"github.com/moby/buildkit/solver/result"
@@ -25,11 +26,36 @@ import (
2526
fstypes "github.com/tonistiigi/fsutil/types"
2627
)
2728

29+
const (
30+
keyAttestationPrefix = "attestation-prefix"
31+
)
32+
2833
type CreateFSOpts struct {
2934
Epoch *time.Time
3035
AttestationPrefix string
3136
}
3237

38+
func (c *CreateFSOpts) Load(opt map[string]string) (map[string]string, error) {
39+
rest := make(map[string]string)
40+
41+
var err error
42+
c.Epoch, opt, err = epoch.ParseExporterAttrs(opt)
43+
if err != nil {
44+
return nil, err
45+
}
46+
47+
for k, v := range opt {
48+
switch k {
49+
case keyAttestationPrefix:
50+
c.AttestationPrefix = v
51+
default:
52+
rest[k] = v
53+
}
54+
}
55+
56+
return rest, nil
57+
}
58+
3359
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) {
3460
var cleanup func() error
3561
var src string

exporter/tar/export.go

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package local
33
import (
44
"context"
55
"os"
6-
"strconv"
76
"strings"
87
"time"
98

@@ -20,15 +19,6 @@ import (
2019
fstypes "github.com/tonistiigi/fsutil/types"
2120
)
2221

23-
const (
24-
attestationPrefixKey = "attestation-prefix"
25-
26-
// preferNondistLayersKey is an exporter option which can be used to mark a layer as non-distributable if the layer reference was
27-
// already found to use a non-distributable media type.
28-
// When this option is not set, the exporter will change the media type of the layer to a distributable one.
29-
preferNondistLayersKey = "prefer-nondist-layers"
30-
)
31-
3222
type Opt struct {
3323
SessionManager *session.Manager
3424
}
@@ -45,33 +35,18 @@ func New(opt Opt) (exporter.Exporter, error) {
4535

4636
func (e *localExporter) Resolve(ctx context.Context, opt map[string]string) (exporter.ExporterInstance, error) {
4737
li := &localExporterInstance{localExporter: e}
48-
49-
tm, opt, err := epoch.ParseExporterAttrs(opt)
38+
_, err := li.opts.Load(opt)
5039
if err != nil {
5140
return nil, err
5241
}
53-
li.opts.Epoch = tm
54-
55-
for k, v := range opt {
56-
switch k {
57-
case preferNondistLayersKey:
58-
b, err := strconv.ParseBool(v)
59-
if err != nil {
60-
return nil, errors.Wrapf(err, "non-bool value for %s: %s", preferNondistLayersKey, v)
61-
}
62-
li.preferNonDist = b
63-
case attestationPrefixKey:
64-
li.opts.AttestationPrefix = v
65-
}
66-
}
42+
_ = opt
6743

6844
return li, nil
6945
}
7046

7147
type localExporterInstance struct {
7248
*localExporter
73-
opts local.CreateFSOpts
74-
preferNonDist bool
49+
opts local.CreateFSOpts
7550
}
7651

7752
func (e *localExporterInstance) Name() string {

0 commit comments

Comments
 (0)