This takes a different approach to outputs and customizations, which is much shorter and duplicates less code. This uses links to internal repositories for now, because 8.2 hasn't been released yet. Add a `distro` flag to `osbuild-pipeline`.
173 lines
4.1 KiB
Go
173 lines
4.1 KiB
Go
// Package blueprint contains primitives for representing weldr blueprints
|
|
package blueprint
|
|
|
|
// An InvalidOutputFormatError is returned when a requested output format is
|
|
// not supported. The requested format is included as the error message.
|
|
type InvalidOutputFormatError struct {
|
|
message string
|
|
}
|
|
|
|
func (e *InvalidOutputFormatError) Error() string {
|
|
return e.message
|
|
}
|
|
|
|
// A Blueprint is a high-level description of an image.
|
|
type Blueprint struct {
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Version string `json:"version,omitempty"`
|
|
Packages []Package `json:"packages"`
|
|
Modules []Package `json:"modules"`
|
|
Groups []Group `json:"groups"`
|
|
Customizations *Customizations `json:"customizations,omitempty"`
|
|
}
|
|
|
|
type Change struct {
|
|
Commit string `json:"commit"`
|
|
Message string `json:"message"`
|
|
Revision *string `json:"revision"`
|
|
Timestamp string `json:"timestamp"`
|
|
Blueprint Blueprint `json:"-"`
|
|
}
|
|
|
|
// A Package specifies an RPM package.
|
|
type Package struct {
|
|
Name string `json:"name"`
|
|
Version string `json:"version,omitempty"`
|
|
}
|
|
|
|
// A group specifies an package group.
|
|
type Group struct {
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
// packages, modules, and groups all resolve to rpm packages right now. This
|
|
// function returns a combined list of "name-version" strings.
|
|
func (b *Blueprint) GetPackages() []string {
|
|
packages := []string{}
|
|
for _, pkg := range b.Packages {
|
|
packages = append(packages, pkg.ToNameVersion())
|
|
}
|
|
for _, pkg := range b.Modules {
|
|
packages = append(packages, pkg.ToNameVersion())
|
|
}
|
|
for _, group := range b.Groups {
|
|
packages = append(packages, group.Name)
|
|
}
|
|
return packages
|
|
}
|
|
|
|
func (b *Blueprint) GetHostname() *string {
|
|
if b.Customizations == nil {
|
|
return nil
|
|
}
|
|
return b.Customizations.Hostname
|
|
}
|
|
|
|
func (b *Blueprint) GetPrimaryLocale() (*string, *string) {
|
|
if b.Customizations == nil {
|
|
return nil, nil
|
|
}
|
|
if b.Customizations.Locale == nil {
|
|
return nil, nil
|
|
}
|
|
if len(b.Customizations.Locale.Languages) == 0 {
|
|
return nil, b.Customizations.Locale.Keyboard
|
|
}
|
|
return &b.Customizations.Locale.Languages[0], b.Customizations.Locale.Keyboard
|
|
}
|
|
|
|
func (b *Blueprint) GetTimezoneSettings() (*string, []string) {
|
|
if b.Customizations == nil {
|
|
return nil, nil
|
|
}
|
|
if b.Customizations.Timezone == nil {
|
|
return nil, nil
|
|
}
|
|
return b.Customizations.Timezone.Timezone, b.Customizations.Timezone.NTPServers
|
|
}
|
|
|
|
func (b *Blueprint) GetUsers() []UserCustomization {
|
|
if b.Customizations == nil {
|
|
return nil
|
|
}
|
|
|
|
users := []UserCustomization{}
|
|
|
|
// prepend sshkey for backwards compat (overridden by users)
|
|
if len(b.Customizations.SSHKey) > 0 {
|
|
for _, c := range b.Customizations.SSHKey {
|
|
users = append(users, UserCustomization{
|
|
Name: c.User,
|
|
Key: &c.Key,
|
|
})
|
|
}
|
|
}
|
|
|
|
return append(users, b.Customizations.User...)
|
|
}
|
|
|
|
func (b *Blueprint) GetGroups() []GroupCustomization {
|
|
if b.Customizations == nil {
|
|
return nil
|
|
}
|
|
|
|
// This is for parity with lorax, which assumes that for each
|
|
// user, a group with that name already exists. Thus, filter groups
|
|
// named like an existing user.
|
|
|
|
groups := []GroupCustomization{}
|
|
for _, group := range b.Customizations.Group {
|
|
exists := false
|
|
for _, user := range b.Customizations.User {
|
|
if user.Name == group.Name {
|
|
exists = true
|
|
break
|
|
}
|
|
}
|
|
for _, key := range b.Customizations.SSHKey {
|
|
if key.User == group.Name {
|
|
exists = true
|
|
break
|
|
}
|
|
}
|
|
if !exists {
|
|
groups = append(groups, group)
|
|
}
|
|
}
|
|
|
|
return groups
|
|
}
|
|
|
|
func (b *Blueprint) GetKernel() *KernelCustomization {
|
|
if b.Customizations == nil {
|
|
return nil
|
|
}
|
|
|
|
return b.Customizations.Kernel
|
|
}
|
|
|
|
func (b *Blueprint) GetFirewall() *FirewallCustomization {
|
|
if b.Customizations == nil {
|
|
return nil
|
|
}
|
|
|
|
return b.Customizations.Firewall
|
|
}
|
|
|
|
func (b *Blueprint) GetServices() *ServicesCustomization {
|
|
if b.Customizations == nil {
|
|
return nil
|
|
}
|
|
|
|
return b.Customizations.Services
|
|
}
|
|
|
|
func (p Package) ToNameVersion() string {
|
|
// Omit version to prevent all packages with prefix of name to be installed
|
|
if p.Version == "*" {
|
|
return p.Name
|
|
}
|
|
|
|
return p.Name + "-" + p.Version
|
|
}
|