From 069021093c818730cf6f678454dd4b3500c77828 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Fri, 17 Mar 2023 13:23:48 +0100 Subject: [PATCH] osbuild: add skopeo-index source New osbuild source that can download a manifest-list from a container registry, using the `--multi-arch=index-only` option of skopeo copy. --- internal/osbuild/skopeo_index_source.go | 57 +++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 internal/osbuild/skopeo_index_source.go diff --git a/internal/osbuild/skopeo_index_source.go b/internal/osbuild/skopeo_index_source.go new file mode 100644 index 000000000..d273fb138 --- /dev/null +++ b/internal/osbuild/skopeo_index_source.go @@ -0,0 +1,57 @@ +package osbuild + +import ( + "fmt" +) + +type SkopeoIndexSource struct { + Items map[string]SkopeoIndexSourceItem `json:"items"` +} + +func (SkopeoIndexSource) isSource() {} + +type SkopeoIndexSourceImage struct { + Name string `json:"name"` + TLSVerify *bool `json:"tls-verify,omitempty"` +} + +type SkopeoIndexSourceItem struct { + Image SkopeoIndexSourceImage `json:"image"` +} + +func (item SkopeoIndexSourceItem) validate() error { + + if item.Image.Name == "" { + return fmt.Errorf("source item has empty name") + } + + return nil +} + +// NewSkopeoIndexSource creates a new and empty SkopeoIndexSource +func NewSkopeoIndexSource() *SkopeoIndexSource { + return &SkopeoIndexSource{ + Items: make(map[string]SkopeoIndexSourceItem), + } +} + +// AddItem adds a source item to the source; will panic +// if any of the supplied options are invalid or missing +func (source *SkopeoIndexSource) AddItem(name, image string, tlsVerify *bool) { + item := SkopeoIndexSourceItem{ + Image: SkopeoIndexSourceImage{ + Name: name, + TLSVerify: tlsVerify, + }, + } + + if err := item.validate(); err != nil { + panic(err) + } + + if !skopeoDigestPattern.MatchString(image) { + panic("item has invalid image id") + } + + source.Items[image] = item +}