Skip to content

Commit b2ff17c

Browse files
committed
exporter: move fs opt parsing to method
This allows one implementation for all the opts parsing, similar to how we do today for the ImageCommitOpts. Signed-off-by: Justin Chadwell <[email protected]>
1 parent 81d697b commit b2ff17c

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

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: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
)
2222

2323
const (
24-
attestationPrefixKey = "attestation-prefix"
25-
2624
// preferNondistLayersKey is an exporter option which can be used to mark a layer as non-distributable if the layer reference was
2725
// already found to use a non-distributable media type.
2826
// When this option is not set, the exporter will change the media type of the layer to a distributable one.
@@ -45,12 +43,10 @@ func New(opt Opt) (exporter.Exporter, error) {
4543

4644
func (e *localExporter) Resolve(ctx context.Context, opt map[string]string) (exporter.ExporterInstance, error) {
4745
li := &localExporterInstance{localExporter: e}
48-
49-
tm, opt, err := epoch.ParseExporterAttrs(opt)
46+
_, err := li.opts.Load(opt)
5047
if err != nil {
5148
return nil, err
5249
}
53-
li.opts.Epoch = tm
5450

5551
for k, v := range opt {
5652
switch k {
@@ -60,8 +56,6 @@ func (e *localExporter) Resolve(ctx context.Context, opt map[string]string) (exp
6056
return nil, errors.Wrapf(err, "non-bool value for %s: %s", preferNondistLayersKey, v)
6157
}
6258
li.preferNonDist = b
63-
case attestationPrefixKey:
64-
li.opts.AttestationPrefix = v
6559
}
6660
}
6761

0 commit comments

Comments
 (0)