Class: Wright::Resource::User

Inherits:
Wright::Resource show all
Defined in:
lib/wright/resource/user.rb

Overview

User resource, represents a user.

Examples:

johndoe = Wright::Resource::User.new('johndoe', home: '/home/johndoe')
johndoe.create

Instance Attribute Summary collapse

Attributes inherited from Wright::Resource

#action, #ignore_failure, #name, #resource_name

Instance Method Summary collapse

Methods inherited from Wright::Resource

#run_action

Constructor Details

#initialize(name, args = {}) ⇒ User

Initializes a user.

Parameters:

  • name (String)

    the user’s name

  • args (Hash) (defaults to: {})

    the arguments

Options Hash (args):

  • :action (Symbol) — default: :create

    the action

  • :uid (Integer)

    the user’s uid

  • :full_name (String)

    the user’s full name

  • :groups (Array<String>)

    the user’s groups

  • :shell (String)

    the user’s shell

  • :home (String)

    the user’s home directory

  • :primary_group (String)

    the user’s primary group

  • :system (Bool) — default: false

    denotes whether the user should be a system user or not



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/wright/resource/user.rb', line 49

def initialize(name, args = {})
  super
  @action        = args.fetch(:action, :create)
  @uid           = args.fetch(:uid, nil)
  @full_name     = args.fetch(:full_name, nil)
  @groups        = args.fetch(:groups, nil)
  @shell         = args.fetch(:shell, nil)
  @home          = fetch_last(args, [:home, :homedir], nil)
  @primary_group = fetch_last(args, [:primary_group, :login_group], nil)
  @system        = args.fetch(:system, false)
end

Instance Attribute Details

#full_nameString

Returns the user’s intended full name.

Returns:

  • (String)

    the user’s intended full name



16
17
18
# File 'lib/wright/resource/user.rb', line 16

def full_name
  @full_name
end

#groupsArray<String>

Returns the user’s intended groups.

Returns:

  • (Array<String>)

    the user’s intended groups



19
20
21
# File 'lib/wright/resource/user.rb', line 19

def groups
  @groups
end

#homeString Also known as: homedir

Returns the user’s intended home directory path.

Returns:

  • (String)

    the user’s intended home directory path



25
26
27
# File 'lib/wright/resource/user.rb', line 25

def home
  @home
end

#primary_groupString, Integer Also known as: login_group

Returns the user’s intended primary group.

Returns:

  • (String, Integer)

    the user’s intended primary group



29
30
31
# File 'lib/wright/resource/user.rb', line 29

def primary_group
  @primary_group
end

#shellString

Returns the user’s intended shell.

Returns:

  • (String)

    the user’s intended shell



22
23
24
# File 'lib/wright/resource/user.rb', line 22

def shell
  @shell
end

#systemBool

Returns true if the user should be a system user. Ignored if #uid is set.

Returns:

  • (Bool)

    true if the user should be a system user. Ignored if #uid is set.



34
35
36
# File 'lib/wright/resource/user.rb', line 34

def system
  @system
end

#uidInteger

Returns the user’s intended user id.

Returns:

  • (Integer)

    the user’s intended user id



13
14
15
# File 'lib/wright/resource/user.rb', line 13

def uid
  @uid
end

Instance Method Details

#createBool

Creates or updates the user.

Returns:

  • (Bool)

    true if the user was updated and false otherwise



65
66
67
68
69
# File 'lib/wright/resource/user.rb', line 65

def create
  might_update_resource do
    provider.create
  end
end

#removeBool

Removes the user.

Returns:

  • (Bool)

    true if the user was updated and false otherwise



75
76
77
78
79
# File 'lib/wright/resource/user.rb', line 75

def remove
  might_update_resource do
    provider.remove
  end
end