user

package
v2.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUserDoesNotExist = errors.New("user does not exist")

ErrUserDoesNotExist is returned by GetLinuxUser if a linux user does not exist yet.

View Source
var ErrUserOrGroupAlreadyExists = errors.New("user or group already exists")

ErrUserOrGroupAlreadyExists is the Go error converted from the result of useradd or groupadd when an user or group already exists.

Functions

This section is empty.

Types

type Entries

type Entries map[string]Entry

Entries contains the information for each user defined in '/etc/passwd'.

type Entry

type Entry struct {
	Password  string
	UID       string
	GID       string
	GECOS     string
	Directory string
	Shell     string
}

Entry is an entry of a '/etc/passwd' file.

type LinuxUser

type LinuxUser struct {
	Username string
	Home     string
	UID      int
	GID      int
}

LinuxUser holds relevant information about a linux user (subset of /etc/passwd).

type LinuxUserManager

type LinuxUserManager struct {
	Fs      afero.Fs
	Passwd  passwdParser
	Creator userCreator
}

LinuxUserManager can retrieve information on linux users and create new users.

func NewLinuxUserManager

func NewLinuxUserManager(fs afero.Fs) LinuxUserManager

NewLinuxUserManager creates a new LinuxUserManager.

func NewLinuxUserManagerFake

func NewLinuxUserManagerFake(fs afero.Fs) LinuxUserManager

NewLinuxUserManagerFake creates a new LinuxUserManager that is used for unit tests.

func (*LinuxUserManager) EnsureLinuxUserExists

func (l *LinuxUserManager) EnsureLinuxUserExists(ctx context.Context, username string) (LinuxUser, error)

EnsureLinuxUserExists will try to create the user specified by username and call GetLinuxUser to retrieve user information.

func (*LinuxUserManager) GetLinuxUser

func (l *LinuxUserManager) GetLinuxUser(username string) (LinuxUser, error)

GetLinuxUser tries to find an existing linux user in /etc/passwd.

type Passwd

type Passwd struct{}

Passwd allows to parse users from '/etc/passwd' on the local system.

func (Passwd) Parse

func (p Passwd) Parse(fs afero.Fs) (Entries, error)

Parse opens the '/etc/passwd' file and parses it into a map from usernames to Entries.

type StubUserCreator

type StubUserCreator struct {
	// contains filtered or unexported fields
}

StubUserCreator is used for unit tests.

func (*StubUserCreator) CreateUser

func (s *StubUserCreator) CreateUser(ctx context.Context, username string) error

CreateUser for StubUserCreator creates an user for an unit test environment.

func (*StubUserCreator) CreateUserWithSpecificUIDAndGID

func (s *StubUserCreator) CreateUserWithSpecificUIDAndGID(ctx context.Context, username string, uid int, gid int) error

CreateUserWithSpecificUIDAndGID for StubUserCreator creates an user with a specific UID and GID for an unit test environment.

type Unix

type Unix struct{}

Unix defines an user creation interface for UNIX systems.

func (Unix) CreateUser

func (u Unix) CreateUser(ctx context.Context, username string) error

CreateUser creates a new user with sudo access.

func (Unix) CreateUserWithSpecificUIDAndGID

func (u Unix) CreateUserWithSpecificUIDAndGID(ctx context.Context, username string, uid int, gid int) error

CreateUserWithSpecificUIDAndGID creates a new user with sudo access and a specific UID and GID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL