Class: Itamae::Resource::User

Inherits:
Base
  • Object
show all
Defined in:
lib/itamae/resource/user.rb

Instance Attribute Summary

Attributes inherited from Base

#attributes, #current_attributes, #notifications, #recipe, #resource_name, #subscriptions, #updated

Instance Method Summary collapse

Methods inherited from Base

#action_nothing, define_attribute, inherited, #initialize, #resource_type, #run

Constructor Details

This class inherits a constructor from Itamae::Resource::Base

Instance Method Details

#action_create(options) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/itamae/resource/user.rb', line 32

def action_create(options)
  if run_specinfra(:check_user_exists, attributes.username)
    if attributes.uid && attributes.uid != current.uid
      run_specinfra(:update_user_uid, attributes.username, attributes.uid)
      updated!
    end

    if attributes.gid && attributes.gid != current.gid
      run_specinfra(:update_user_gid, attributes.username, attributes.gid)
      updated!
    end

    if attributes.password && attributes.password != current.password
      run_specinfra(:update_user_encrypted_password, attributes.username, attributes.password)
      updated!
    end

    if attributes.home && attributes.home != current.home
      run_specinfra(:update_user_home_directory, attributes.username, attributes.home)
      updated!
    end
  else
    options = {
      gid:            attributes.gid,
      home_directory: attributes.home,
      password:       attributes.password,
      system_user:    attributes.system_user,
      uid:            attributes.uid,
    }

    run_specinfra(:add_user, attributes.username, options)

    updated!
  end
end

#pre_actionObject



14
15
16
17
18
19
# File 'lib/itamae/resource/user.rb', line 14

def pre_action
  case @current_action
  when :create
    attributes.exist = true
  end
end

#set_current_attributesObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/itamae/resource/user.rb', line 21

def set_current_attributes
  current.exist = exist?

  if current.exist
    current.uid = run_specinfra(:get_user_uid, attributes.username).stdout.strip.to_i
    current.gid = run_specinfra(:get_user_gid, attributes.username).stdout.strip.to_i
    current.home = run_specinfra(:get_user_home_directory, attributes.username).stdout.strip
    current.password = current_password
  end
end