-
Notifications
You must be signed in to change notification settings - Fork 43
/
skopeo_index_source.go
57 lines (44 loc) · 1.18 KB
/
skopeo_index_source.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
54
55
56
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
}