-
Notifications
You must be signed in to change notification settings - Fork 18
/
uniform.go
54 lines (45 loc) · 1.5 KB
/
uniform.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
51
52
53
54
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0
package artifactset
import (
"github.com/open-component-model/ocm/v2/pkg/common/accessio"
"github.com/open-component-model/ocm/v2/pkg/common/accessobj"
"github.com/open-component-model/ocm/v2/pkg/contexts/datacontext/attrs/vfsattr"
"github.com/open-component-model/ocm/v2/pkg/contexts/oci/cpi"
)
func init() {
h := &repospechandler{}
cpi.RegisterRepositorySpecHandler(h, "")
cpi.RegisterRepositorySpecHandler(h, Type)
for _, f := range SupportedFormats() {
cpi.RegisterRepositorySpecHandler(h, string(f))
}
}
type repospechandler struct{}
func (h *repospechandler) MapReference(ctx cpi.Context, u *cpi.UniformRepositorySpec) (cpi.RepositorySpec, error) {
path := u.Info
if u.Info == "" {
if u.Host == "" || u.Type == "" {
return nil, nil
}
path = u.Host
}
fs := vfsattr.Get(ctx)
hint := u.TypeHint
if !u.CreateIfMissing {
hint = ""
}
create, ok, err := accessobj.CheckFile(Type, hint, accessio.TypeForType(u.Type) == Type, path, fs, ArtifactSetDescriptorFileName)
if err == nil && !ok {
create, ok, err = accessobj.CheckFile(Type, hint, accessio.TypeForType(u.Type) == Type, path, fs, OCIArtifactSetDescriptorFileName)
}
if !ok || err != nil {
return nil, err
}
mode := accessobj.ACC_WRITABLE
if create {
mode |= accessobj.ACC_CREATE
}
return NewRepositorySpec(mode, path, accessio.FileFormatForType(u.Type), accessio.PathFileSystem(fs))
}