-
Notifications
You must be signed in to change notification settings - Fork 18
/
oci_layer.go
50 lines (40 loc) · 1.18 KB
/
oci_layer.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
48
49
50
// 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_OCILAYER = "oci layer"
type ociLayer struct {
base
blob accessio.BlobAccess
}
func (r *ociLayer) Type() string {
return T_OCILAYER
}
func (r *ociLayer) Set() {
r.Builder.blob = &r.blob
}
func (r *ociLayer) Close() error {
if r.blob == nil {
return errors.Newf("config blob required")
}
m := r.Builder.oci_artacc.ManifestAccess()
if r.oci_cleanuplayers {
m.GetDescriptor().Layers = nil
r.oci_cleanuplayers = false
}
_, err := m.AddLayer(r.blob, nil)
if err == nil {
r.result = artdesc.DefaultBlobDescriptor(r.blob)
}
return nil
}
////////////////////////////////////////////////////////////////////////////////
func (b *Builder) Layer(f ...func()) *artdesc.Descriptor {
b.expect(b.oci_artacc, T_OCIMANIFEST, func() bool { return b.oci_artacc.IsManifest() })
return b.configure(&ociLayer{}, f).(*artdesc.Descriptor)
}