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 <thozza@redhat.com>
This commit is contained in:
Tomas Hozza 2021-07-01 15:53:11 +02:00 committed by Ondřej Budai
parent 006ff98025
commit 34d52aa8e1
4 changed files with 58 additions and 0 deletions

View file

@ -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,
}
}

View file

@ -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)
}

View file

@ -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":

View file

@ -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{