Skip to content

Commit d0b8a50

Browse files
author
Rafid Bin Mostofa
committed
feat: add support for "v2-archives" in "v1" format
"v2-archives" defines the archives, same as "archives". It is added to define Ubuntu Pro archives in chisel-releases with "pro" and "priority" fields (see canonical#160 and canonical#167), while supporting Chisel<=v1.0.0 and chisel-releases "format"<=v1. Since Chisel ignores unknown fields, archives defined in "v2-archives" will be ignored by v1.0.0 but picked up by later versions.
1 parent e2ee603 commit d0b8a50

File tree

3 files changed

+182
-3
lines changed

3 files changed

+182
-3
lines changed

internal/setup/setup_test.go

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,162 @@ var setupTests = []setupTest{{
19331933
`,
19341934
},
19351935
relerror: `chisel.yaml: more than one default archive: bar, foo`,
1936+
}, {
1937+
summary: "Define additional archives in v2-archives",
1938+
input: map[string]string{
1939+
"chisel.yaml": `
1940+
format: v1
1941+
archives:
1942+
ubuntu:
1943+
version: 20.04
1944+
components: [main]
1945+
suites: [focal]
1946+
priority: 10
1947+
public-keys: [test-key]
1948+
v2-archives:
1949+
fips:
1950+
version: 20.04
1951+
components: [main]
1952+
suites: [focal]
1953+
pro: fips
1954+
priority: 20
1955+
public-keys: [test-key]
1956+
public-keys:
1957+
test-key:
1958+
id: ` + testKey.ID + `
1959+
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
1960+
`,
1961+
"slices/mydir/mypkg.yaml": `
1962+
package: mypkg
1963+
`,
1964+
},
1965+
release: &setup.Release{
1966+
Archives: map[string]*setup.Archive{
1967+
"ubuntu": {
1968+
Name: "ubuntu",
1969+
Version: "20.04",
1970+
Suites: []string{"focal"},
1971+
Components: []string{"main"},
1972+
Priority: 10,
1973+
PubKeys: []*packet.PublicKey{testKey.PubKey},
1974+
},
1975+
"fips": {
1976+
Name: "fips",
1977+
Version: "20.04",
1978+
Suites: []string{"focal"},
1979+
Components: []string{"main"},
1980+
Pro: "fips",
1981+
Priority: 20,
1982+
PubKeys: []*packet.PublicKey{testKey.PubKey},
1983+
},
1984+
},
1985+
Packages: map[string]*setup.Package{
1986+
"mypkg": {
1987+
Name: "mypkg",
1988+
Path: "slices/mydir/mypkg.yaml",
1989+
Slices: map[string]*setup.Slice{},
1990+
},
1991+
},
1992+
},
1993+
}, {
1994+
summary: "Define archives in v2-archives only",
1995+
input: map[string]string{
1996+
"chisel.yaml": `
1997+
format: v1
1998+
v2-archives:
1999+
ubuntu:
2000+
version: 20.04
2001+
components: [main]
2002+
suites: [focal]
2003+
priority: 10
2004+
public-keys: [test-key]
2005+
public-keys:
2006+
test-key:
2007+
id: ` + testKey.ID + `
2008+
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
2009+
`,
2010+
"slices/mydir/mypkg.yaml": `
2011+
package: mypkg
2012+
`,
2013+
},
2014+
release: &setup.Release{
2015+
Archives: map[string]*setup.Archive{
2016+
"ubuntu": {
2017+
Name: "ubuntu",
2018+
Version: "20.04",
2019+
Suites: []string{"focal"},
2020+
Components: []string{"main"},
2021+
Priority: 10,
2022+
PubKeys: []*packet.PublicKey{testKey.PubKey},
2023+
},
2024+
},
2025+
Packages: map[string]*setup.Package{
2026+
"mypkg": {
2027+
Name: "mypkg",
2028+
Path: "slices/mydir/mypkg.yaml",
2029+
Slices: map[string]*setup.Slice{},
2030+
},
2031+
},
2032+
},
2033+
}, {
2034+
summary: "Cannot define same archive name in archives and v2-archives",
2035+
input: map[string]string{
2036+
"chisel.yaml": `
2037+
format: v1
2038+
archives:
2039+
ubuntu:
2040+
version: 20.04
2041+
components: [main]
2042+
suites: [focal]
2043+
priority: 10
2044+
public-keys: [test-key]
2045+
v2-archives:
2046+
ubuntu:
2047+
version: 20.04
2048+
components: [main]
2049+
suites: [focal]
2050+
priority: 20
2051+
pro: fips
2052+
public-keys: [test-key]
2053+
public-keys:
2054+
test-key:
2055+
id: ` + testKey.ID + `
2056+
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
2057+
`,
2058+
"slices/mydir/mypkg.yaml": `
2059+
package: mypkg
2060+
`,
2061+
},
2062+
relerror: `chisel.yaml: archive "ubuntu" defined twice`,
2063+
}, {
2064+
summary: "Multiple default archives across archives and v2-archives",
2065+
input: map[string]string{
2066+
"chisel.yaml": `
2067+
format: v1
2068+
archives:
2069+
foo:
2070+
default: true
2071+
version: 22.04
2072+
components: [main]
2073+
suites: [jammy]
2074+
public-keys: [test-key]
2075+
v2-archives:
2076+
bar:
2077+
default: true
2078+
version: 22.04
2079+
components: [main, universe]
2080+
suites: [jammy]
2081+
public-keys: [test-key]
2082+
public-keys:
2083+
test-key:
2084+
id: ` + testKey.ID + `
2085+
armor: |` + "\n" + testutil.PrefixEachLine(testKey.PubKeyArmor, "\t\t\t\t\t\t") + `
2086+
`,
2087+
"slices/mydir/mypkg.yaml": `
2088+
package: mypkg
2089+
`,
2090+
},
2091+
relerror: `chisel.yaml: more than one default archive: bar, foo`,
19362092
}}
19372093

19382094
var defaultChiselYaml = `

internal/setup/yaml.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ type yamlRelease struct {
2525
Format string `yaml:"format"`
2626
Archives map[string]yamlArchive `yaml:"archives"`
2727
PubKeys map[string]yamlPubKey `yaml:"public-keys"`
28+
// "v2-archives" defines the archives, same as "archives". It is added to
29+
// define Ubuntu Pro archives in chisel-releases with "pro" and "priority"
30+
// fields (see #160 and #167), while supporting Chisel<=v1.0.0 and
31+
// chisel-releases "format"<=v1. Since Chisel ignores unknown fields,
32+
// archives defined in "v2-archives" will be ignored by v1.0.0 but picked up
33+
// by later versions.
34+
// Note that the archive definitions in "archives" and "v2-archives" are
35+
// merged together while parsing. (See parseRelease.)
36+
// TODO deprecate this field once both Chisel v1.0.0 and chisel-releases v1
37+
// are unsupported.
38+
V2Archives map[string]yamlArchive `yaml:"v2-archives"`
2839
}
2940

3041
const (
@@ -161,7 +172,7 @@ func parseRelease(baseDir, filePath string, data []byte) (*Release, error) {
161172
if yamlVar.Format != "v1" {
162173
return nil, fmt.Errorf("%s: unknown format %q", fileName, yamlVar.Format)
163174
}
164-
if len(yamlVar.Archives) == 0 {
175+
if len(yamlVar.Archives)+len(yamlVar.V2Archives) == 0 {
165176
return nil, fmt.Errorf("%s: no archives defined", fileName)
166177
}
167178

@@ -178,12 +189,24 @@ func parseRelease(baseDir, filePath string, data []byte) (*Release, error) {
178189
pubKeys[keyName] = key
179190
}
180191

192+
// Merge all archive definitions.
193+
yamlArchives := make(map[string]yamlArchive, len(yamlVar.Archives)+len(yamlVar.V2Archives))
194+
for archiveName, details := range yamlVar.Archives {
195+
yamlArchives[archiveName] = details
196+
}
197+
for archiveName, details := range yamlVar.V2Archives {
198+
if _, ok := yamlArchives[archiveName]; ok {
199+
return nil, fmt.Errorf("%s: archive %q defined twice", fileName, archiveName)
200+
}
201+
yamlArchives[archiveName] = details
202+
}
203+
181204
// For compatibility if there is a default archive set and priorities are
182205
// not being used, we will revert back to the default archive behaviour.
183206
hasPriority := false
184207
var defaultArchive string
185208
var archiveNoPriority string
186-
for archiveName, details := range yamlVar.Archives {
209+
for archiveName, details := range yamlArchives {
187210
if details.Version == "" {
188211
return nil, fmt.Errorf("%s: archive %q missing version field", fileName, archiveName)
189212
}

tests/pro-archives/chisel-releases/chisel.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
format: v1
22

3-
archives:
3+
v2-archives:
44
ubuntu:
55
version: 24.04
66
pro: esm-infra

0 commit comments

Comments
 (0)