Class: Inspec::Resources::User

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

Overview

rubocop:disable Metrics/ClassLength

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ User

Returns a new instance of User.



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

def initialize(user)
  @user = user

  # select package manager
  @user_provider = nil
  os = inspec.os
  if os.linux?
    @user_provider = LinuxUser.new(inspec)
  elsif os.windows?
    @user_provider = WindowsUser.new(inspec)
  elsif ['darwin'].include?(os[:family])
    @user_provider = DarwinUser.new(inspec)
  elsif ['freebsd'].include?(os[:family])
    @user_provider = FreeBSDUser.new(inspec)
  elsif ['aix'].include?(os[:family])
    @user_provider = AixUser.new(inspec)
  elsif os.solaris?
    @user_provider = SolarisUser.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



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

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

#exists?Boolean

Returns:

  • (Boolean)


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

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

#gidObject



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

def gid
  identity[:gid] unless identity.nil?
end

#groupObject



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

def group
  identity[:group] unless identity.nil?
end

#groupsObject



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

def groups
  identity[:groups] unless identity.nil?
end

#has_authorized_key?(_compare_key) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#has_home_directory?(compare_home) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


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

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)


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

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

#homeObject



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

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

#identityObject



160
161
162
163
# File 'lib/resources/user.rb', line 160

def identity
  return @id_cache if defined?(@id_cache)
  @id_cache = @user_provider.identity(@user) if !@user_provider.nil?
end

#maxdaysObject

returns the maximum days between password changes



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

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

#maximum_days_between_password_changeObject

implement ‘maxdays’ method to be compatible with serverspec



125
126
127
128
# File 'lib/resources/user.rb', line 125

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



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

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

#minimum_days_between_password_changeObject

implement ‘mindays’ method to be compatible with serverspec



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

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

#shellObject



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

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

#to_sObject



156
157
158
# File 'lib/resources/user.rb', line 156

def to_s
  "User #{@user}"
end

#uidObject



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

def uid
  identity[:uid] unless identity.nil?
end

#warndaysObject

returns the days for password change warning



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

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