converge: github.com/asteris-llc/converge/resource/user Index | Files

package user

import "github.com/asteris-llc/converge/resource/user"

Index

Package Files

preparer.go user.go user_linux.go

Variables

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

ErrUnsupported is used when a system is not supported

type AddUserOptions Uses

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 Uses

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 Uses

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 Uses

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

Prepare a new task

type State Uses

type State string

State type for User

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"
)

type System Uses

type System struct{}

System implements SystemUtils

func (*System) AddUser Uses

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

AddUser adds a user

func (*System) DelUser Uses

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

DelUser deletes a user

func (*System) Lookup Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

LookupUserExpiry looks up a user's expiry

func (*System) ModUser Uses

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

ModUser modifies a user

type SystemUtils Uses

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 Uses

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 Uses

func NewUser(system SystemUtils) *User

NewUser constructs and returns a new User

func (*User) Apply Uses

func (u *User) Apply(context.Context) (resource.TaskStatus, error)

Apply changes for user

func (*User) Check Uses

func (u *User) Check(context.Context, resource.Renderer) (resource.TaskStatus, error)

Check if a user user exists

func (*User) DiffAdd Uses

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 Uses

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 Uses

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.

Package user imports 11 packages (graph) and is imported by 1 packages. Updated 2017-01-13. Refresh now. Tools for package owners.