...
1 package release
2
3 import (
4 "fmt"
5
6 wh "edge-infra.dev/pkg/f8n/warehouse"
7 "edge-infra.dev/pkg/f8n/warehouse/oci"
8 "edge-infra.dev/pkg/f8n/warehouse/pallet"
9 )
10
11 const (
12 ReleaseMetadataKind = "edge-release"
13 AnnotationReleaseSourceRegistry = "com.ncr.warehouse.release.registry"
14 AnnotationReleaseSourceRepo = "com.ncr.warehouse.release.repo"
15 AnnotationReleaseVersion = "com.ncr.warehouse.release.version"
16 )
17
18
19 type Metadata struct {
20
21 Vendor string
22 Version string
23 ReleaseRegistry string
24 ReleaseRepo string
25 pallet.BuildInfo
26 }
27
28 func (m Metadata) OCIAnnotations() map[string]string {
29 if m.Vendor == "" {
30 m.Vendor = "NCR"
31 }
32 r := map[string]string{
33 wh.AnnotationVendor: m.Vendor,
34
35 wh.AnnotationSource: m.Source,
36 wh.AnnotationVersion: m.BuildInfo.Version,
37 wh.AnnotationCreated: m.Created,
38 wh.AnnotationRevision: m.Revision,
39
40 AnnotationReleaseSourceRegistry: m.ReleaseRegistry,
41 AnnotationReleaseSourceRepo: m.ReleaseRepo,
42 AnnotationReleaseVersion: m.Version,
43 }
44
45 return r
46 }
47
48 var requiredMetaAnnos = []string{
49 wh.AnnotationVendor,
50 wh.AnnotationRevision,
51 wh.AnnotationSource,
52 wh.AnnotationVersion,
53 wh.AnnotationCreated,
54 AnnotationReleaseSourceRegistry,
55 AnnotationReleaseSourceRepo,
56 }
57
58 func metadataFromAnnotations(aa map[string]string) (Metadata, error) {
59 if _, ok := aa[wh.AnnotationVendor]; !ok {
60 aa[wh.AnnotationVendor] = "NCR"
61 }
62
63 for _, a := range requiredMetaAnnos {
64 if _, ok := aa[a]; !ok {
65 return Metadata{}, fmt.Errorf(
66 "%w: invalid pallet metadata: required annotation %s not found",
67 oci.ErrInvalidArtifact,
68 a,
69 )
70 }
71 }
72 return Metadata{
73 BuildInfo: pallet.BuildInfo{
74 Version: aa[wh.AnnotationVersion],
75 Source: aa[wh.AnnotationSource],
76 Created: aa[wh.AnnotationCreated],
77 Revision: aa[wh.AnnotationRevision],
78 },
79 Version: aa[AnnotationReleaseVersion],
80 Vendor: aa[wh.AnnotationVendor],
81 ReleaseRegistry: aa[AnnotationReleaseSourceRegistry],
82 ReleaseRepo: aa[AnnotationReleaseSourceRepo],
83 }, nil
84 }
85
View as plain text