-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathutils.go
53 lines (46 loc) · 1.22 KB
/
utils.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
package oci
import (
"fmt"
"strings"
"ocm.software/ocm/api/credentials/cpi"
"ocm.software/ocm/api/oci/artdesc"
"ocm.software/ocm/api/oci/grammar"
ociidentity "ocm.software/ocm/api/tech/oci/identity"
"ocm.software/ocm/api/utils/runtime"
)
func AsTags(tag string) []string {
if tag != "" {
return []string{tag}
}
return nil
}
func StandardOCIRef(host, repository, version string) string {
sep := grammar.TagSeparator
i := strings.Index(version, grammar.DigestSeparator)
if i > 1 {
return fmt.Sprintf("%s%s%s%s%s", host, grammar.RepositorySeparator, repository, sep, version)
}
if ok, _ := artdesc.IsDigest(version); ok {
sep = grammar.DigestSeparator
if strings.HasPrefix(version, sep) {
sep = ""
}
}
return fmt.Sprintf("%s%s%s%s%s", host, grammar.RepositorySeparator, repository, sep, version)
}
func IsIntermediate(spec RepositorySpec) bool {
if s, ok := spec.(IntermediateRepositorySpecAspect); ok {
return s.IsIntermediate()
}
return false
}
func IsUnknown(r RepositorySpec) bool {
return runtime.IsUnknown(r)
}
func GetConsumerIdForRef(ref string) (cpi.ConsumerIdentity, error) {
r, err := ParseRef(ref)
if err != nil {
return nil, err
}
return ociidentity.GetConsumerId(r.Host, r.Repository), nil
}