distro.Manifest: take Customizations rather than Blueprint as argument

This makes two changes simultaneously, to avoid too much churn:
 - move accessors from being on the blueprint struct to the
   customizations struct, and
 - pass the customizations struct rather than the whole blueprint
   as argumnet to distro.Manifest().

@larskarlitski pointed out in a previous review that it feels
redundant to pass the whole blueprint as well as the list of
packages to the Manifest funciton. Indeed it is, so this
simplifies things a bit.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2020-03-15 22:59:54 +01:00
parent 5d179428be
commit 7957feff48
13 changed files with 172 additions and 172 deletions

View file

@ -106,112 +106,6 @@ func (b *Blueprint) GetPackages() []string {
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 == "*" {

View file

@ -70,3 +70,109 @@ type CustomizationError struct {
func (e *CustomizationError) Error() string {
return e.Message
}
func (c *Customizations) GetHostname() *string {
if c == nil {
return nil
}
return c.Hostname
}
func (c *Customizations) GetPrimaryLocale() (*string, *string) {
if c == nil {
return nil, nil
}
if c.Locale == nil {
return nil, nil
}
if len(c.Locale.Languages) == 0 {
return nil, c.Locale.Keyboard
}
return &c.Locale.Languages[0], c.Locale.Keyboard
}
func (c *Customizations) GetTimezoneSettings() (*string, []string) {
if c == nil {
return nil, nil
}
if c.Timezone == nil {
return nil, nil
}
return c.Timezone.Timezone, c.Timezone.NTPServers
}
func (c *Customizations) GetUsers() []UserCustomization {
if c == nil {
return nil
}
users := []UserCustomization{}
// prepend sshkey for backwards compat (overridden by users)
if len(c.SSHKey) > 0 {
for _, c := range c.SSHKey {
users = append(users, UserCustomization{
Name: c.User,
Key: &c.Key,
})
}
}
return append(users, c.User...)
}
func (c *Customizations) GetGroups() []GroupCustomization {
if c == 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 c.Group {
exists := false
for _, user := range c.User {
if user.Name == group.Name {
exists = true
break
}
}
for _, key := range c.SSHKey {
if key.User == group.Name {
exists = true
break
}
}
if !exists {
groups = append(groups, group)
}
}
return groups
}
func (c *Customizations) GetKernel() *KernelCustomization {
if c == nil {
return nil
}
return c.Kernel
}
func (c *Customizations) GetFirewall() *FirewallCustomization {
if c == nil {
return nil
}
return c.Firewall
}
func (c *Customizations) GetServices() *ServicesCustomization {
if c == nil {
return nil
}
return c.Services
}