From 34d52aa8e1c695101463888c57b9c506c375baff Mon Sep 17 00:00:00 2001 From: Tomas Hozza Date: Thu, 1 Jul 2021 15:53:11 +0200 Subject: [PATCH] osbuild2: add support for `org.osbuild.authselect` stage Add support for the `org.osbuild.authselect` osbuild stage [1], which allows one to set system identity profile and authentication sources using `authselect`. Add unit test cases for the newly added stage. [1] https://github.com/osbuild/osbuild/pull/696 Signed-off-by: Tomas Hozza --- internal/osbuild2/authselect_stage.go | 15 +++++++++++++ internal/osbuild2/authselect_stage_test.go | 16 ++++++++++++++ internal/osbuild2/stage.go | 2 ++ internal/osbuild2/stage_test.go | 25 ++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 internal/osbuild2/authselect_stage.go create mode 100644 internal/osbuild2/authselect_stage_test.go diff --git a/internal/osbuild2/authselect_stage.go b/internal/osbuild2/authselect_stage.go new file mode 100644 index 000000000..72ed5597b --- /dev/null +++ b/internal/osbuild2/authselect_stage.go @@ -0,0 +1,15 @@ +package osbuild2 + +type AuthselectStageOptions struct { + Profile string `json:"profile_id"` + Features []string `json:"features,omitempty"` +} + +func (AuthselectStageOptions) isStageOptions() {} + +func NewAuthselectStage(options *AuthselectStageOptions) *Stage { + return &Stage{ + Type: "org.osbuild.authselect", + Options: options, + } +} diff --git a/internal/osbuild2/authselect_stage_test.go b/internal/osbuild2/authselect_stage_test.go new file mode 100644 index 000000000..7e954fc85 --- /dev/null +++ b/internal/osbuild2/authselect_stage_test.go @@ -0,0 +1,16 @@ +package osbuild2 + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestNewAuthselectStage(t *testing.T) { + expectedStage := &Stage{ + Type: "org.osbuild.authselect", + Options: &AuthselectStageOptions{}, + } + actualStage := NewAuthselectStage(&AuthselectStageOptions{}) + assert.Equal(t, expectedStage, actualStage) +} diff --git a/internal/osbuild2/stage.go b/internal/osbuild2/stage.go index cfb0dda90..454baffb1 100644 --- a/internal/osbuild2/stage.go +++ b/internal/osbuild2/stage.go @@ -67,6 +67,8 @@ func (stage *Stage) UnmarshalJSON(data []byte) error { var options StageOptions var inputs Inputs switch rawStage.Type { + case "org.osbuild.authselect": + options = new(AuthselectStageOptions) case "org.osbuild.fix-bls": options = new(FixBLSStageOptions) case "org.osbuild.fstab": diff --git a/internal/osbuild2/stage_test.go b/internal/osbuild2/stage_test.go index 1335a073a..9af9b1d7f 100644 --- a/internal/osbuild2/stage_test.go +++ b/internal/osbuild2/stage_test.go @@ -53,6 +53,31 @@ func TestStage_UnmarshalJSON(t *testing.T) { }, wantErr: true, }, + { + name: "authselect", + fields: fields{ + Type: "org.osbuild.authselect", + Options: &AuthselectStageOptions{ + Profile: "sssd", + }, + }, + args: args{ + data: []byte(`{"type":"org.osbuild.authselect","options":{"profile_id":"sssd"}}`), + }, + }, + { + name: "authselect-features", + fields: fields{ + Type: "org.osbuild.authselect", + Options: &AuthselectStageOptions{ + Profile: "nis", + Features: []string{"with-ecryptfs", "with-mkhomedir"}, + }, + }, + args: args{ + data: []byte(`{"type":"org.osbuild.authselect","options":{"profile_id":"nis","features":["with-ecryptfs","with-mkhomedir"]}}`), + }, + }, { name: "cloud-init", fields: fields{