-
Notifications
You must be signed in to change notification settings - Fork 19
/
oci_config.go
44 lines (35 loc) · 982 Bytes
/
oci_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package builder
import (
"github.com/mandelsoft/goutils/errors"
"github.com/open-component-model/ocm/pkg/blobaccess"
"github.com/open-component-model/ocm/pkg/contexts/oci/artdesc"
)
const T_OCICONFIG = "oci config"
type ociConfig struct {
base
blob blobaccess.BlobAccess
}
func (r *ociConfig) Type() string {
return T_OCICONFIG
}
func (r *ociConfig) Set() {
r.Builder.blob = &r.blob
}
func (r *ociConfig) Close() error {
if r.blob == nil {
return errors.Newf("config blob required")
}
m := r.Builder.oci_artacc.ManifestAccess()
err := m.AddBlob(r.blob)
if err != nil {
return errors.Newf("cannot add config blob: %s", err)
}
d := artdesc.DefaultBlobDescriptor(r.blob)
m.GetDescriptor().Config = *d
return nil
}
////////////////////////////////////////////////////////////////////////////////
func (b *Builder) Config(f ...func()) {
b.expect(b.oci_artacc, T_OCIMANIFEST, func() bool { return b.oci_artacc.IsManifest() })
b.configure(&ociConfig{}, f)
}