add support for getting a user name from config
This commit is contained in:
parent
dae9c1cf45
commit
ea97070fea
@ -182,6 +182,11 @@ func (u *User) UseConfig(config data.ConfigurationValueGetter) {
|
||||
}
|
||||
|
||||
func (u *User) ResolveId(ctx context.Context) string {
|
||||
if u.config != nil {
|
||||
if configUser, configUserErr := u.config.GetValue("user"); configUserErr == nil && u.Name == "" {
|
||||
u.Name = configUser.(string)
|
||||
}
|
||||
}
|
||||
return LookupUIDString(u.Name)
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
_ "os"
|
||||
_ "strings"
|
||||
"testing"
|
||||
"decl/internal/data"
|
||||
)
|
||||
|
||||
func TestNewUserResource(t *testing.T) {
|
||||
@ -77,3 +78,22 @@ func TestCreateUser(t *testing.T) {
|
||||
applyDeleteErr := u.Apply()
|
||||
assert.Equal(t, nil, applyDeleteErr)
|
||||
}
|
||||
|
||||
func TestSystemUser(t *testing.T) {
|
||||
u := NewUser()
|
||||
|
||||
u.UseConfig(MockConfigValueGetter(func(key string) (any, error) {
|
||||
switch key {
|
||||
case "user":
|
||||
return "bar", nil
|
||||
case "group":
|
||||
return "foo", nil
|
||||
case "uid":
|
||||
return "", nil
|
||||
}
|
||||
return nil, fmt.Errorf("%w: %s", data.ErrUnknownConfigurationKey, key)
|
||||
}))
|
||||
|
||||
u.ResolveId(context.Background())
|
||||
assert.Equal(t, "bar", u.Name)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user