-
Notifications
You must be signed in to change notification settings - Fork 18
/
oci_config.go
47 lines (38 loc) · 1.12 KB
/
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
45
46
47
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0
package builder
import (
"github.com/open-component-model/ocm/pkg/common/accessio"
"github.com/open-component-model/ocm/pkg/contexts/oci/artdesc"
"github.com/open-component-model/ocm/pkg/errors"
)
const T_OCICONFIG = "oci config"
type ociConfig struct {
base
blob accessio.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)
}