-
Notifications
You must be signed in to change notification settings - Fork 19
/
utils.go
45 lines (38 loc) · 1.13 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
package oci
import (
"fmt"
ociidentity "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/oci/identity"
"github.com/open-component-model/ocm/pkg/contexts/credentials/cpi"
"github.com/open-component-model/ocm/pkg/contexts/oci/artdesc"
"github.com/open-component-model/ocm/pkg/contexts/oci/grammar"
"github.com/open-component-model/ocm/pkg/runtime"
)
func AsTags(tag string) []string {
if tag != "" {
return []string{tag}
}
return nil
}
func StandardOCIRef(host, repository, version string) string {
sep := grammar.TagSeparator
if ok, _ := artdesc.IsDigest(version); ok {
sep = grammar.DigestSeparator
}
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
}