user

package
v0.0.0-...-02c76fb Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: Apache-2.0 Imports: 11 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// StatePresent indicates the user should be present
	StatePresent State = "present"

	// StateAbsent indicates the user should be absent
	StateAbsent State = "absent"

	// ShortForm layout for time parsing
	ShortForm = "2006-01-02"

	// MaxTime is the max representable time
	MaxTime = "2038-01-19"
)

Variables

View Source
var ErrUnsupported = fmt.Errorf("user: not supported on this system")

ErrUnsupported is used when a system is not supported

Functions

This section is empty.

Types

type AddUserOptions

type AddUserOptions struct {
	UID        string
	Group      string
	Comment    string
	CreateHome bool
	SkelDir    string
	Directory  string
	Expiry     string
}

AddUserOptions are the options specified in the configuration to be used when adding a user

type ModUserOptions

type ModUserOptions struct {
	Username  string
	UID       string
	Group     string
	Comment   string
	Directory string
	MoveDir   bool
	Expiry    string
}

ModUserOptions are the options specified in the configuration to be used when modifying a user

type Preparer

type Preparer struct {
	// Username is the user login name.
	Username string `hcl:"username" required:"true" nonempty:"true"`

	// NewUsername is used when modifying a user.
	// Username will be changed to NewUsername. No changes to the home directory
	// name or location of the contents will be made. This can be done using
	// HomeDir and MoveDir options.
	NewUsername string `hcl:"new_username" nonempty:"true"`

	// UID is the user ID.
	UID *uint32 `hcl:"uid"`

	// GroupName is the primary group for user and must already exist.
	// Only one of GID or Groupname may be indicated.
	GroupName string `hcl:"groupname" mutually_exclusive:"gid,groupname" nonempty:"true"`

	// Gid is the primary group ID for user and must refer to an existing group.
	// Only one of GID or Groupname may be indicated.
	GID *uint32 `hcl:"gid" mutually_exclusive:"gid,groupname"`

	// Name is the user description.
	// This field can be indicated when adding or modifying a user.
	Name string `hcl:"name" nonempty:"true"`

	// CreateHome when set to true will create the home directory for the user.
	// The files and directories contained in the skeleton directory (which can be
	// defined with the SkelDir option) will be copied to the home directory.
	CreateHome bool `hcl:"create_home"`

	// SkelDir contains files and directories to be copied in the user's home
	// directory when adding a user. If not set, the skeleton directory is defined
	// by the SKEL variable in /etc/default/useradd or, by default, /etc/skel.
	// SkelDir is only valid is CreatHome is specified.
	SkelDir string `hcl:"skel_dir" nonempty:"true"`

	// HomeDir is the name of the user's login directory. If not set, the home
	// directory is defined by appending the value of Username to the HOME
	// variable in /etc/default/useradd, resulting in /HOME/Username.
	// This field can be indicated when adding or modifying a user.
	HomeDir string `hcl:"home_dir" nonempty:"true"`

	// MoveDir is used to move the contents of HomeDir when modifying a user.
	// HomeDir must also be indicated if MoveDir is set to true.
	MoveDir bool `hcl:"move_dir"`

	// Expiry is the date on which the user account will be disabled. The date is
	// specified in the format YYYY-MM-DD. If not specified, the default expiry
	// date specified by the EXPIRE variable in /etc/default/useradd, or an empty
	// string (no expiry) will be used by default.
	Expiry time.Time `hcl:"expiry"`

	// State is whether the user should be present.
	// The default value is present.
	State State `hcl:"state" valid_values:"present,absent"`
}

Preparer for User

User renders user data

func (*Preparer) Prepare

func (p *Preparer) Prepare(ctx context.Context, render resource.Renderer) (resource.Task, error)

Prepare a new task

type State

type State string

State type for User

type System

type System struct{}

System implements SystemUtils

func (*System) AddUser

func (s *System) AddUser(userName string, options *AddUserOptions) error

AddUser adds a user

func (*System) DelUser

func (s *System) DelUser(userName string) error

DelUser deletes a user

func (*System) Lookup

func (s *System) Lookup(userName string) (*user.User, error)

Lookup looks up a user by name If the user cannot be found an error is returned

func (*System) LookupGroup

func (s *System) LookupGroup(groupName string) (*user.Group, error)

LookupGroup looks up a group by name If the group cannot be found an error is returned

func (*System) LookupGroupID

func (s *System) LookupGroupID(groupID string) (*user.Group, error)

LookupGroupID looks up a group by gid If the group cannot be found an error is returned

func (*System) LookupID

func (s *System) LookupID(userID string) (*user.User, error)

LookupID looks up a user by uid If the user cannot be found an error is returned

func (*System) LookupUserExpiry

func (s *System) LookupUserExpiry(userName string) (time.Time, error)

LookupUserExpiry looks up a user's expiry

func (*System) ModUser

func (s *System) ModUser(userName string, options *ModUserOptions) error

ModUser modifies a user

type SystemUtils

type SystemUtils interface {
	AddUser(userName string, options *AddUserOptions) error
	DelUser(userName string) error
	ModUser(userName string, options *ModUserOptions) error
	LookupUserExpiry(userName string) (time.Time, error)
	Lookup(userName string) (*user.User, error)
	LookupID(userID string) (*user.User, error)
	LookupGroup(groupName string) (*user.Group, error)
	LookupGroupID(groupID string) (*user.Group, error)
}

SystemUtils provides system utilities for user

type User

type User struct {

	// the configured username
	Username string `export:"username"`

	// the desired username
	NewUsername string `export:"newusername"`

	// the user id
	UID string `export:"uid"`

	// the group name
	GroupName string `export:"groupname"`

	// the group id
	GID string `export:"gid"`

	// the real name of the user
	Name string `export:"name"`

	// if the home directory should be created
	CreateHome bool `export:"createhome"`

	// the path to the skeleton directory
	SkelDir string `export:"skeldir"`

	// the path to the home directory
	HomeDir string `export:"homedir"`

	// if the contents of the home directory should be moved
	MoveDir bool `export:"movedir"`

	// the date the user account will be disabled
	Expiry time.Time `export:"expiry"`

	// configured the user state
	State State `export:"state"`
	// contains filtered or unexported fields
}

User manages user users

func NewUser

func NewUser(system SystemUtils) *User

NewUser constructs and returns a new User

func (*User) Apply

Apply changes for user

func (*User) Check

Check if a user user exists

func (*User) DiffAdd

func (u *User) DiffAdd(status *resource.Status) (*AddUserOptions, error)

DiffAdd checks for differences between the current and desired state for the user to be added indicated by the User fields. The options to be used for the add command are set.

func (*User) DiffDel

func (u *User) DiffDel(status *resource.Status, userByName *user.User, nameNotFound bool) error

DiffDel checks for differences between the current and desired state for the user to be deleted indicated by the User fields.

func (*User) DiffMod

func (u *User) DiffMod(status *resource.Status, currUser *user.User) (*ModUserOptions, error)

DiffMod checks for differences between the user associated with u.Username and the desired modifications of that user indicated by the other User fields. The options to be used for the modify command are set.

Jump to

Keyboard shortcuts

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