Maint: alpine package interface rework

- return concrete struct type
- split interface is sub-interfaces
This commit is contained in:
Quentin McGaw (desktop)
2021-07-23 18:51:51 +00:00
parent c5d92ae02c
commit 0b985e8c35
3 changed files with 22 additions and 13 deletions

View File

@@ -12,10 +12,14 @@ var (
ErrUserAlreadyExists = errors.New("user already exists")
)
type UserCreater interface {
CreateUser(username string, uid int) (createdUsername string, err error)
}
// CreateUser creates a user in Alpine with the given UID.
func (c *configurator) CreateUser(username string, uid int) (createdUsername string, err error) {
func (a *Alpine) CreateUser(username string, uid int) (createdUsername string, err error) {
UIDStr := strconv.Itoa(uid)
u, err := c.lookupID(UIDStr)
u, err := a.lookupID(UIDStr)
_, unknownUID := err.(user.UnknownUserIdError)
if err != nil && !unknownUID {
return "", err
@@ -28,7 +32,7 @@ func (c *configurator) CreateUser(username string, uid int) (createdUsername str
return u.Username, nil
}
u, err = c.lookup(username)
u, err = a.lookup(username)
_, unknownUsername := err.(user.UnknownUserError)
if err != nil && !unknownUsername {
return "", err
@@ -39,7 +43,7 @@ func (c *configurator) CreateUser(username string, uid int) (createdUsername str
ErrUserAlreadyExists, username, u.Uid, uid)
}
file, err := os.OpenFile(c.passwdPath, os.O_APPEND|os.O_WRONLY, 0644)
file, err := os.OpenFile(a.passwdPath, os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
return "", err
}