2021-02-06 16:26:23 +00:00
|
|
|
// Package alpine defines a configurator to interact with the Alpine operating system.
|
2020-03-29 19:52:49 -04:00
|
|
|
package alpine
|
|
|
|
|
|
|
|
|
|
import (
|
2021-05-19 14:30:43 +00:00
|
|
|
"context"
|
2021-07-23 16:06:19 +00:00
|
|
|
"os/user"
|
2020-03-29 19:52:49 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Configurator interface {
|
2020-12-27 00:36:39 +00:00
|
|
|
CreateUser(username string, uid int) (createdUsername string, err error)
|
2021-05-19 14:30:43 +00:00
|
|
|
Version(ctx context.Context) (version string, err error)
|
2020-03-29 19:52:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type configurator struct {
|
2021-07-23 16:06:19 +00:00
|
|
|
alpineReleasePath string
|
|
|
|
|
passwdPath string
|
|
|
|
|
lookupID func(uid string) (*user.User, error)
|
|
|
|
|
lookup func(username string) (*user.User, error)
|
2020-03-29 19:52:49 -04:00
|
|
|
}
|
|
|
|
|
|
2021-07-23 16:06:19 +00:00
|
|
|
func NewConfigurator() Configurator {
|
2020-03-29 19:52:49 -04:00
|
|
|
return &configurator{
|
2021-07-23 16:06:19 +00:00
|
|
|
alpineReleasePath: "/etc/alpine-release",
|
|
|
|
|
passwdPath: "/etc/passwd",
|
|
|
|
|
lookupID: user.LookupId,
|
|
|
|
|
lookup: user.Lookup,
|
2020-03-29 19:52:49 -04:00
|
|
|
}
|
|
|
|
|
}
|