Class: User

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/user.rb

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ User

Returns a new instance of User.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/resources/user.rb', line 51

def initialize(user)
  @user = user

  # select package manager
  @user_provider = nil
  case inspec.os[:family]
  when 'ubuntu', 'debian', 'redhat', 'fedora', 'centos', 'arch', 'opensuse', 'wrlinux'
    @user_provider = LinuxUser.new(inspec)
  when 'windows'
    @user_provider = WindowsUser.new(inspec)
  when 'darwin'
    @user_provider = DarwinUser.new(inspec)
  when 'freebsd'
    @user_provider = FreeBSDUser.new(inspec)
  else
    return skip_resource 'The `user` resource is not supported on your OS yet.'
  end
end

Instance Method Details

#deprecated(name, alternative = nil) ⇒ Object



147
148
149
# File 'lib/resources/user.rb', line 147

def deprecated(name, alternative = nil)
  warn "[DEPRECATION] #{name} is deprecated. #{alternative}"
end

#exists?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/resources/user.rb', line 70

def exists?
  !identiy.nil? && !identiy[:user].nil?
end

#gidObject



78
79
80
# File 'lib/resources/user.rb', line 78

def gid
  identiy.nil? ? nil : identiy[:gid]
end

#groupObject



82
83
84
# File 'lib/resources/user.rb', line 82

def group
  identiy.nil? ? nil : identiy[:group]
end

#groupsObject



86
87
88
# File 'lib/resources/user.rb', line 86

def groups
  identiy.nil? ? nil : identiy[:groups]
end

#has_authorized_key?(_compare_key) ⇒ Boolean

Returns:

  • (Boolean)


142
143
144
145
# File 'lib/resources/user.rb', line 142

def has_authorized_key?(_compare_key)
  deprecated('has_authorized_key?')
  fail NotImplementedError
end

#has_home_directory?(compare_home) ⇒ Boolean

Returns:

  • (Boolean)


132
133
134
135
# File 'lib/resources/user.rb', line 132

def has_home_directory?(compare_home)
  deprecated('has_home_directory?', "Please use 'its(:home)'")
  home == compare_home
end

#has_login_shell?(compare_shell) ⇒ Boolean

Returns:

  • (Boolean)


137
138
139
140
# File 'lib/resources/user.rb', line 137

def (compare_shell)
  deprecated('has_login_shell?', "Please use 'its(:shell)'")
  shell == compare_shell
end

#has_uid?(compare_uid) ⇒ Boolean

implements rspec has matcher, to be compatible with serverspec @see: github.com/rspec/rspec-expectations/blob/master/lib/rspec/matchers/built_in/has.rb

Returns:

  • (Boolean)


127
128
129
130
# File 'lib/resources/user.rb', line 127

def has_uid?(compare_uid)
  deprecated('has_uid?')
  uid == compare_uid
end

#homeObject



90
91
92
# File 'lib/resources/user.rb', line 90

def home
  meta_info.nil? ? nil : meta_info[:home]
end

#maxdaysObject

returns the maximum days between password changes



104
105
106
# File 'lib/resources/user.rb', line 104

def maxdays
  credentials.nil? ? nil : credentials[:maxdays]
end

#maximum_days_between_password_changeObject

implement ‘maxdays’ method to be compatible with serverspec



120
121
122
123
# File 'lib/resources/user.rb', line 120

def maximum_days_between_password_change
  deprecated('maximum_days_between_password_change', "Please use 'its(:maxdays)'")
  maxdays
end

#mindaysObject

returns the minimum days between password changes



99
100
101
# File 'lib/resources/user.rb', line 99

def mindays
  credentials.nil? ? nil : credentials[:mindays]
end

#minimum_days_between_password_changeObject

implement ‘mindays’ method to be compatible with serverspec



114
115
116
117
# File 'lib/resources/user.rb', line 114

def minimum_days_between_password_change
  deprecated('minimum_days_between_password_change', "Please use 'its(:mindays)'")
  mindays
end

#shellObject



94
95
96
# File 'lib/resources/user.rb', line 94

def shell
  meta_info.nil? ? nil : meta_info[:shell]
end

#to_sObject



151
152
153
# File 'lib/resources/user.rb', line 151

def to_s
  "User #{@user}"
end

#uidObject



74
75
76
# File 'lib/resources/user.rb', line 74

def uid
  identiy.nil? ? nil : identiy[:uid]
end

#warndaysObject

returns the days for password change warning



109
110
111
# File 'lib/resources/user.rb', line 109

def warndays
  credentials.nil? ? nil : credentials[:warndays]
end