package release import ( "fmt" wh "edge-infra.dev/pkg/f8n/warehouse" "edge-infra.dev/pkg/f8n/warehouse/oci" "edge-infra.dev/pkg/f8n/warehouse/pallet" ) const ( ReleaseMetadataKind = "edge-release" AnnotationReleaseSourceRegistry = "com.ncr.warehouse.release.registry" AnnotationReleaseSourceRepo = "com.ncr.warehouse.release.repo" AnnotationReleaseVersion = "com.ncr.warehouse.release.version" ) // Metadata defines information about the package itself. type Metadata struct { // Required Vendor string Version string ReleaseRegistry string ReleaseRepo string pallet.BuildInfo } func (m Metadata) OCIAnnotations() map[string]string { if m.Vendor == "" { m.Vendor = "NCR" } r := map[string]string{ wh.AnnotationVendor: m.Vendor, // wh.AnnotationName: m.Name, wh.AnnotationSource: m.Source, wh.AnnotationVersion: m.BuildInfo.Version, wh.AnnotationCreated: m.Created, wh.AnnotationRevision: m.Revision, // Keep GAR metadata for manifest sources? AnnotationReleaseSourceRegistry: m.ReleaseRegistry, AnnotationReleaseSourceRepo: m.ReleaseRepo, AnnotationReleaseVersion: m.Version, } return r } var requiredMetaAnnos = []string{ wh.AnnotationVendor, wh.AnnotationRevision, wh.AnnotationSource, wh.AnnotationVersion, wh.AnnotationCreated, AnnotationReleaseSourceRegistry, AnnotationReleaseSourceRepo, } func metadataFromAnnotations(aa map[string]string) (Metadata, error) { if _, ok := aa[wh.AnnotationVendor]; !ok { aa[wh.AnnotationVendor] = "NCR" } for _, a := range requiredMetaAnnos { if _, ok := aa[a]; !ok { return Metadata{}, fmt.Errorf( "%w: invalid pallet metadata: required annotation %s not found", oci.ErrInvalidArtifact, a, ) } } return Metadata{ BuildInfo: pallet.BuildInfo{ Version: aa[wh.AnnotationVersion], Source: aa[wh.AnnotationSource], Created: aa[wh.AnnotationCreated], Revision: aa[wh.AnnotationRevision], }, Version: aa[AnnotationReleaseVersion], Vendor: aa[wh.AnnotationVendor], ReleaseRegistry: aa[AnnotationReleaseSourceRegistry], ReleaseRepo: aa[AnnotationReleaseSourceRepo], }, nil }