osbuild: use internal users package structs in stages
Don't pass blueprint Users and Groups options all the way down to the osbuild stage bindings. Instead, convert them to the internal users.User and users.Group structs. Ideally we would do this even higher up in the code path, before reaching the distro, but this is the first step towards that.
This commit is contained in:
parent
5bf4b2ab98
commit
14f608de0a
10 changed files with 32 additions and 36 deletions
|
|
@ -257,8 +257,8 @@ func iotInstallerImage(workload workload.Workload,
|
|||
|
||||
img.Platform = t.platform
|
||||
img.ExtraBasePackages = packageSets[installerPkgsKey]
|
||||
img.Users = customizations.GetUsers()
|
||||
img.Groups = customizations.GetGroups()
|
||||
img.Users = users.UsersFromBP(customizations.GetUsers())
|
||||
img.Groups = users.GroupsFromBP(customizations.GetGroups())
|
||||
|
||||
img.ISOLabelTempl = d.isolabelTmpl
|
||||
img.Product = d.product
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/users"
|
||||
)
|
||||
|
||||
func buildPipeline(repos []rpmmd.RepoConfig, buildPackageSpecs []rpmmd.PackageSpec, runner string) *osbuild.Pipeline {
|
||||
|
|
@ -87,10 +88,10 @@ func osPipeline(t *imageType,
|
|||
}
|
||||
|
||||
if groups := c.GetGroups(); len(groups) > 0 {
|
||||
p.AddStage(osbuild.NewGroupsStage(osbuild.NewGroupsStageOptions(groups)))
|
||||
p.AddStage(osbuild.NewGroupsStage(osbuild.NewGroupsStageOptions(users.GroupsFromBP(groups))))
|
||||
}
|
||||
|
||||
if userOptions, err := osbuild.NewUsersStageOptions(c.GetUsers(), false); err != nil {
|
||||
if userOptions, err := osbuild.NewUsersStageOptions(users.UsersFromBP(c.GetUsers()), false); err != nil {
|
||||
return nil, err
|
||||
} else if userOptions != nil {
|
||||
p.AddStage(osbuild.NewUsersStage(userOptions))
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ func edgeInstallerPipelines(t *imageType, customizations *blueprint.Customizatio
|
|||
kernelVer := rpmmd.GetVerStrFromPackageSpecListPanic(installerPackages, "kernel")
|
||||
ostreeRepoPath := "/ostree/repo"
|
||||
payloadStages := ostreePayloadStages(options, ostreeRepoPath)
|
||||
kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, "", customizations.GetUsers(), customizations.GetGroups(), makeISORootPath(ostreeRepoPath), options.OSTree.Ref, "rhel")
|
||||
kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, "", users.UsersFromBP(customizations.GetUsers()), users.GroupsFromBP(customizations.GetGroups()), makeISORootPath(ostreeRepoPath), options.OSTree.Ref, "rhel")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -255,7 +255,7 @@ func imageInstallerPipelines(t *imageType, customizations *blueprint.Customizati
|
|||
|
||||
tarPath := "/liveimg.tar"
|
||||
tarPayloadStages := []*osbuild.Stage{osbuild.NewTarStage(&osbuild.TarStageOptions{Filename: tarPath}, treePipeline.Name)}
|
||||
kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, makeISORootPath(tarPath), customizations.GetUsers(), customizations.GetGroups(), "", "", "rhel")
|
||||
kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, makeISORootPath(tarPath), users.UsersFromBP(customizations.GetUsers()), users.GroupsFromBP(customizations.GetGroups()), "", "", "rhel")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -449,17 +449,17 @@ func osPipeline(t *imageType,
|
|||
// don't put users and groups in the payload of an installer
|
||||
// add them via kickstart instead
|
||||
if groups := c.GetGroups(); len(groups) > 0 {
|
||||
p.AddStage(osbuild.NewGroupsStage(osbuild.NewGroupsStageOptions(groups)))
|
||||
p.AddStage(osbuild.NewGroupsStage(osbuild.NewGroupsStageOptions(users.GroupsFromBP(groups))))
|
||||
}
|
||||
|
||||
if userOptions, err := osbuild.NewUsersStageOptions(c.GetUsers(), false); err != nil {
|
||||
if userOptions, err := osbuild.NewUsersStageOptions(users.UsersFromBP(c.GetUsers()), false); err != nil {
|
||||
return nil, err
|
||||
} else if userOptions != nil {
|
||||
if t.rpmOstree {
|
||||
// for ostree, writing the key during user creation is
|
||||
// redundant and can cause issues so create users without keys
|
||||
// and write them on first boot
|
||||
userOptionsSansKeys, err := osbuild.NewUsersStageOptions(c.GetUsers(), true)
|
||||
userOptionsSansKeys, err := osbuild.NewUsersStageOptions(users.UsersFromBP(c.GetUsers()), true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ func edgeInstallerPipelines(t *imageType, customizations *blueprint.Customizatio
|
|||
kernelVer := rpmmd.GetVerStrFromPackageSpecListPanic(installerPackages, "kernel")
|
||||
ostreeRepoPath := "/ostree/repo"
|
||||
payloadStages := ostreePayloadStages(options, ostreeRepoPath)
|
||||
kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, "", customizations.GetUsers(), customizations.GetGroups(), makeISORootPath(ostreeRepoPath), options.OSTree.Ref, "rhel")
|
||||
kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, "", users.UsersFromBP(customizations.GetUsers()), users.GroupsFromBP(customizations.GetGroups()), makeISORootPath(ostreeRepoPath), options.OSTree.Ref, "rhel")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -250,7 +250,7 @@ func imageInstallerPipelines(t *imageType, customizations *blueprint.Customizati
|
|||
|
||||
tarPath := "/liveimg.tar"
|
||||
tarPayloadStages := []*osbuild.Stage{osbuild.NewTarStage(&osbuild.TarStageOptions{Filename: tarPath}, treePipeline.Name)}
|
||||
kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, makeISORootPath(tarPath), customizations.GetUsers(), customizations.GetGroups(), "", "", "rhel")
|
||||
kickstartOptions, err := osbuild.NewKickstartStageOptions(kspath, makeISORootPath(tarPath), users.UsersFromBP(customizations.GetUsers()), users.GroupsFromBP(customizations.GetGroups()), "", "", "rhel")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -444,17 +444,17 @@ func osPipeline(t *imageType,
|
|||
// don't put users and groups in the payload of an installer
|
||||
// add them via kickstart instead
|
||||
if groups := c.GetGroups(); len(groups) > 0 {
|
||||
p.AddStage(osbuild.NewGroupsStage(osbuild.NewGroupsStageOptions(groups)))
|
||||
p.AddStage(osbuild.NewGroupsStage(osbuild.NewGroupsStageOptions(users.GroupsFromBP(groups))))
|
||||
}
|
||||
|
||||
if userOptions, err := osbuild.NewUsersStageOptions(c.GetUsers(), false); err != nil {
|
||||
if userOptions, err := osbuild.NewUsersStageOptions(users.UsersFromBP(c.GetUsers()), false); err != nil {
|
||||
return nil, err
|
||||
} else if userOptions != nil {
|
||||
if t.rpmOstree {
|
||||
// for ostree, writing the key during user creation is
|
||||
// redundant and can cause issues so create users without keys
|
||||
// and write them on first boot
|
||||
userOptionsSansKeys, err := osbuild.NewUsersStageOptions(c.GetUsers(), true)
|
||||
userOptionsSansKeys, err := osbuild.NewUsersStageOptions(users.UsersFromBP(c.GetUsers()), true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,19 +4,19 @@ import (
|
|||
"math/rand"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/artifact"
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/manifest"
|
||||
"github.com/osbuild/osbuild-composer/internal/platform"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/runner"
|
||||
"github.com/osbuild/osbuild-composer/internal/users"
|
||||
)
|
||||
|
||||
type OSTreeInstaller struct {
|
||||
Base
|
||||
Platform platform.Platform
|
||||
ExtraBasePackages rpmmd.PackageSet
|
||||
Users []blueprint.UserCustomization
|
||||
Groups []blueprint.GroupCustomization
|
||||
Users []users.User
|
||||
Groups []users.Group
|
||||
|
||||
ISOLabelTempl string
|
||||
Product string
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import (
|
|||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/disk"
|
||||
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||
"github.com/osbuild/osbuild-composer/internal/users"
|
||||
)
|
||||
|
||||
// An ISOTree represents a tree containing the anaconda installer,
|
||||
|
|
@ -18,8 +18,8 @@ type ISOTree struct {
|
|||
// TODO: review optional and mandatory fields and their meaning
|
||||
OSName string
|
||||
Release string
|
||||
Users []blueprint.UserCustomization
|
||||
Groups []blueprint.GroupCustomization
|
||||
Users []users.User
|
||||
Groups []users.Group
|
||||
|
||||
PartitionTable *disk.PartitionTable
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package osbuild
|
||||
|
||||
import (
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/users"
|
||||
)
|
||||
|
||||
|
|
@ -22,7 +21,7 @@ func NewGroupsStage(options *GroupsStageOptions) *Stage {
|
|||
}
|
||||
}
|
||||
|
||||
func NewGroupsStageOptions(groups []blueprint.GroupCustomization) *GroupsStageOptions {
|
||||
func NewGroupsStageOptions(groups []users.Group) *GroupsStageOptions {
|
||||
options := GroupsStageOptions{
|
||||
Groups: map[string]GroupsStageOptionsGroup{},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package osbuild
|
||||
|
||||
import (
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
)
|
||||
import "github.com/osbuild/osbuild-composer/internal/users"
|
||||
|
||||
type KickstartStageOptions struct {
|
||||
// Where to place the kickstart file
|
||||
|
|
@ -41,8 +39,8 @@ func NewKickstartStage(options *KickstartStageOptions) *Stage {
|
|||
func NewKickstartStageOptions(
|
||||
path string,
|
||||
imageURL string,
|
||||
userCustomizations []blueprint.UserCustomization,
|
||||
groupCustomizations []blueprint.GroupCustomization,
|
||||
userCustomizations []users.User,
|
||||
groupCustomizations []users.Group,
|
||||
ostreeURL string,
|
||||
ostreeRef string,
|
||||
osName string) (*KickstartStageOptions, error) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package osbuild
|
||||
|
||||
import (
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/crypt"
|
||||
"github.com/osbuild/osbuild-composer/internal/users"
|
||||
)
|
||||
|
|
@ -30,7 +29,7 @@ func NewUsersStage(options *UsersStageOptions) *Stage {
|
|||
}
|
||||
}
|
||||
|
||||
func NewUsersStageOptions(userCustomizations []blueprint.UserCustomization, omitKey bool) (*UsersStageOptions, error) {
|
||||
func NewUsersStageOptions(userCustomizations []users.User, omitKey bool) (*UsersStageOptions, error) {
|
||||
if len(userCustomizations) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/users"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -24,20 +23,20 @@ func TestNewUsersStageOptionsPassword(t *testing.T) {
|
|||
EmptyPass := ""
|
||||
CryptPass := "$6$RWdHzrPfoM6BMuIP$gKYlBXQuJgP.G2j2twbOyxYjFDPUQw8Jp.gWe1WD/obX0RMyfgw5vt.Mn/tLLX4mQjaklSiIzoAW3HrVQRg4Q." // #nosec G101
|
||||
|
||||
users := []blueprint.UserCustomization{
|
||||
blueprint.UserCustomization{
|
||||
users := []users.User{
|
||||
{
|
||||
Name: "bart",
|
||||
Password: &Pass,
|
||||
},
|
||||
blueprint.UserCustomization{
|
||||
{
|
||||
Name: "lisa",
|
||||
Password: &CryptPass,
|
||||
},
|
||||
blueprint.UserCustomization{
|
||||
{
|
||||
Name: "maggie",
|
||||
Password: &EmptyPass,
|
||||
},
|
||||
blueprint.UserCustomization{
|
||||
{
|
||||
Name: "homer",
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue