distro: use the new types in distro packages
Each distro is now represented by a strongly typed value but it can also provide its name as a string.
This commit is contained in:
parent
80e01bb397
commit
d02bac15fe
3 changed files with 46 additions and 19 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue