diff --git a/internal/distro/distro.go b/internal/distro/distro.go index 40ee85a20..4b25cdd32 100644 --- a/internal/distro/distro.go +++ b/internal/distro/distro.go @@ -3,6 +3,7 @@ package distro import ( "bufio" "errors" + "github.com/osbuild/osbuild-composer/internal/common" "io" "os" "strings" @@ -20,6 +21,9 @@ type Distro interface { // passed to New(). Name() string + // Return strong-typed distribution + Distribution() common.Distribution + // Returns a list of repositories from which this distribution gets its // content. Repositories(arch string) []rpmmd.RepoConfig @@ -45,12 +49,12 @@ type Distro interface { } type Registry struct { - distros map[string]Distro + distros map[common.Distribution]Distro } func NewRegistry(confPaths []string) *Registry { distros := &Registry{ - distros: make(map[string]Distro), + distros: make(map[common.Distribution]Distro), } distros.register(fedora30.New(confPaths)) distros.register(rhel82.New(confPaths)) @@ -58,15 +62,19 @@ func NewRegistry(confPaths []string) *Registry { } func (r *Registry) register(distro Distro) { - name := distro.Name() - if _, exists := r.distros[name]; exists { - panic("a distro with this name already exists: " + name) + distroTag := distro.Distribution() + if _, exists := r.distros[distroTag]; exists { + panic("a distro with this name already exists: " + distro.Name()) } - r.distros[name] = distro + r.distros[distroTag] = distro } func (r *Registry) GetDistro(name string) Distro { - distro, ok := r.distros[name] + distroTag, exists := common.DistributionFromString(name) + if !exists { + return nil + } + distro, ok := r.distros[distroTag] if !ok { return nil } diff --git a/internal/distro/fedora30/distro.go b/internal/distro/fedora30/distro.go index 16522b91f..d72e26b61 100644 --- a/internal/distro/fedora30/distro.go +++ b/internal/distro/fedora30/distro.go @@ -2,6 +2,7 @@ package fedora30 import ( "errors" + "github.com/osbuild/osbuild-composer/internal/common" "log" "sort" "strconv" @@ -40,7 +41,7 @@ type output struct { Assembler func(uefi bool, size uint64) *pipeline.Assembler } -const Name = "fedora-30" +const Distro = common.Fedora30 func New(confPaths []string) *Fedora30 { const GigaByte = 1024 * 1024 * 1024 @@ -50,15 +51,15 @@ func New(confPaths []string) *Fedora30 { outputs: map[string]output{}, } - repoMap, err := rpmmd.LoadRepositories(confPaths, Name) + repoMap, err := rpmmd.LoadRepositories(confPaths, r.Name()) if err != nil { - log.Printf("Could not load repository data for %s: %s", Name, err.Error()) + log.Printf("Could not load repository data for %s: %s", r.Name(), err.Error()) return nil } repos, exists := repoMap["x86_64"] if !exists { - log.Printf("Could not load architecture-specific repository data for x86_64 (%s): %s", Name, err.Error()) + log.Printf("Could not load architecture-specific repository data for x86_64 (%s): %s", r.Name(), err.Error()) } else { r.arches["x86_64"] = arch{ Name: "x86_64", @@ -74,7 +75,7 @@ func New(confPaths []string) *Fedora30 { repos, exists = repoMap["aarch64"] if !exists { - log.Printf("Could not load architecture-specific repository data for x86_64 (%s): %s", Name, err.Error()) + log.Printf("Could not load architecture-specific repository data for x86_64 (%s): %s", r.Name(), err.Error()) } else { r.arches["aarch64"] = arch{ Name: "aarch64", @@ -298,7 +299,15 @@ func New(confPaths []string) *Fedora30 { } func (r *Fedora30) Name() string { - return Name + name, exists := Distro.ToString() + if !exists { + panic("Fatal error, hardcoded distro value in fedora30 package is not valid!") + } + return name +} + +func (r *Fedora30) Distribution() common.Distribution { + return Distro } func (r *Fedora30) Repositories(arch string) []rpmmd.RepoConfig { diff --git a/internal/distro/rhel82/distro.go b/internal/distro/rhel82/distro.go index f2ed9f499..031b05551 100644 --- a/internal/distro/rhel82/distro.go +++ b/internal/distro/rhel82/distro.go @@ -2,6 +2,7 @@ package rhel82 import ( "errors" + "github.com/osbuild/osbuild-composer/internal/common" "log" "sort" "strconv" @@ -41,7 +42,7 @@ type output struct { Assembler func(uefi bool, size uint64) *pipeline.Assembler } -const Name = "rhel-8.2" +const Distro = common.RHEL82 func New(confPaths []string) *RHEL82 { const GigaByte = 1024 * 1024 * 1024 @@ -51,15 +52,15 @@ func New(confPaths []string) *RHEL82 { outputs: map[string]output{}, } - repoMap, err := rpmmd.LoadRepositories(confPaths, Name) + repoMap, err := rpmmd.LoadRepositories(confPaths, r.Name()) if err != nil { - log.Printf("Could not load repository data for %s: %s", Name, err.Error()) + log.Printf("Could not load repository data for %s: %s", r.Name(), err.Error()) return nil } repos, exists := repoMap["x86_64"] if !exists { - log.Printf("Could not load architecture-specific repository data for x86_64 (%s): %s", Name, err.Error()) + log.Printf("Could not load architecture-specific repository data for x86_64 (%s): %s", r.Name(), err.Error()) } else { r.arches["x86_64"] = arch{ Name: "x86_64", @@ -75,7 +76,7 @@ func New(confPaths []string) *RHEL82 { repos, exists = repoMap["aarch64"] if !exists { - log.Printf("Could not load architecture-specific repository data for aarch64 (%s): %s", Name, err.Error()) + log.Printf("Could not load architecture-specific repository data for aarch64 (%s): %s", r.Name(), err.Error()) } else { r.arches["aarch64"] = arch{ Name: "aarch64", @@ -433,7 +434,16 @@ func New(confPaths []string) *RHEL82 { } func (r *RHEL82) Name() string { - return Name + name, exists := Distro.ToString() + if !exists { + panic("Fatal error, hardcoded distro value in rhel82 package is not valid!") + } + return name +} + + +func (r *RHEL82) Distribution() common.Distribution { + return Distro } func (r *RHEL82) Repositories(arch string) []rpmmd.RepoConfig {