Skip to content

Commit

Permalink
osbuild: add consts for more "sources" in sources.go
Browse files Browse the repository at this point in the history
This is a followup for the suggestion in PR#1142 to not use strings
for defining sources but constants. This helps avoiding typos.

Note that this does not change the tests to ensure that we keep
the API promises here. I.e. an accidental change of e.g. the
`SourceNameSkopeoIndex` const should trigger a test failure.
  • Loading branch information
mvo5 authored and thozza committed Jan 24, 2025
1 parent cf2b0d5 commit dd54f7b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/osbuild/containers_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func newContainersInputForSources(containers []container.Spec, forLocal bool) Co

var sourceType string
if forLocal {
sourceType = "org.osbuild.containers-storage"
sourceType = SourceNameContainersStorage
} else {
sourceType = "org.osbuild.containers"
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/osbuild/containers_storage_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package osbuild

import "fmt"

const SourceNameContainersStorage = "org.osbuild.containers-storage"

type ContainersStorageSource struct {
Items map[string]struct{} `json:"items"`
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/osbuild/skopeo_index_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
)

const SourceNameSkopeoIndex = "org.osbuild.skopeo-index"

type SkopeoIndexSource struct {
Items map[string]SkopeoIndexSourceItem `json:"items"`
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/osbuild/skopeo_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"regexp"
)

const SourceNameSkopeo = "org.osbuild.skopeo"

var skopeoDigestPattern = regexp.MustCompile(`sha256:[0-9a-f]{64}`)

const DockerTransport = "docker"
Expand Down
4 changes: 2 additions & 2 deletions pkg/osbuild/skopeo_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewSkopeoStageWithContainersStorage(path string, images ContainersInput, ma
}

return &Stage{
Type: "org.osbuild.skopeo",
Type: SourceNameSkopeo,
Options: &SkopeoStageOptions{
Destination: SkopeoDestinationContainersStorage{
Type: "containers-storage",
Expand All @@ -59,7 +59,7 @@ func NewSkopeoStageWithOCI(path string, images ContainersInput, manifests *Files
}

return &Stage{
Type: "org.osbuild.skopeo",
Type: SourceNameSkopeo,
Options: &SkopeoStageOptions{
Destination: &SkopeoDestinationOCI{
Type: "oci",
Expand Down
6 changes: 3 additions & 3 deletions pkg/osbuild/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ func GenSources(inputs SourceInputs, rpmDownloader RpmDownloader) (Sources, erro
}
}
if len(skopeo.Items) > 0 {
sources["org.osbuild.skopeo"] = skopeo
sources[SourceNameSkopeo] = skopeo
}
if len(skopeoIndex.Items) > 0 {
sources["org.osbuild.skopeo-index"] = skopeoIndex
sources[SourceNameSkopeoIndex] = skopeoIndex
}
if len(localContainers.Items) > 0 {
sources["org.osbuild.containers-storage"] = localContainers
sources[SourceNameContainersStorage] = localContainers
}
}

Expand Down

0 comments on commit dd54f7b

Please sign in to comment.