Class: Inspec::Resources::User
- Inherits:
-
Object
- Object
- Inspec::Resources::User
- Defined in:
- lib/resources/user.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Method Summary collapse
- #deprecated(name, alternative = nil) ⇒ Object
- #exists? ⇒ Boolean
- #gid ⇒ Object
- #group ⇒ Object
- #groups ⇒ Object
- #has_authorized_key?(_compare_key) ⇒ Boolean
- #has_home_directory?(compare_home) ⇒ Boolean
- #has_login_shell?(compare_shell) ⇒ Boolean
-
#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.
- #home ⇒ Object
- #identity ⇒ Object
-
#initialize(user) ⇒ User
constructor
A new instance of User.
-
#maxdays ⇒ Object
returns the maximum days between password changes.
-
#maximum_days_between_password_change ⇒ Object
implement ‘maxdays’ method to be compatible with serverspec.
-
#mindays ⇒ Object
returns the minimum days between password changes.
-
#minimum_days_between_password_change ⇒ Object
implement ‘mindays’ method to be compatible with serverspec.
- #shell ⇒ Object
- #to_s ⇒ Object
- #uid ⇒ Object
-
#warndays ⇒ Object
returns the days for password change warning.
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 74 75 |
# 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) elsif ['hpux'].include?(os[:family]) @user_provider = HpuxUser.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
154 155 156 |
# File 'lib/resources/user.rb', line 154 def deprecated(name, alternative = nil) warn "[DEPRECATION] #{name} is deprecated. #{alternative}" end |
#exists? ⇒ Boolean
77 78 79 |
# File 'lib/resources/user.rb', line 77 def exists? !identity.nil? && !identity[:user].nil? end |
#gid ⇒ Object
85 86 87 |
# File 'lib/resources/user.rb', line 85 def gid identity[:gid] unless identity.nil? end |
#group ⇒ Object
89 90 91 |
# File 'lib/resources/user.rb', line 89 def group identity[:group] unless identity.nil? end |
#groups ⇒ Object
93 94 95 |
# File 'lib/resources/user.rb', line 93 def groups identity[:groups] unless identity.nil? end |
#has_authorized_key?(_compare_key) ⇒ Boolean
149 150 151 152 |
# File 'lib/resources/user.rb', line 149 def (_compare_key) deprecated('has_authorized_key?') fail NotImplementedError end |
#has_home_directory?(compare_home) ⇒ Boolean
139 140 141 142 |
# File 'lib/resources/user.rb', line 139 def has_home_directory?(compare_home) deprecated('has_home_directory?', "Please use: its('home')") home == compare_home end |
#has_login_shell?(compare_shell) ⇒ Boolean
144 145 146 147 |
# File 'lib/resources/user.rb', line 144 def has_login_shell?(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
134 135 136 137 |
# File 'lib/resources/user.rb', line 134 def has_uid?(compare_uid) deprecated('has_uid?') uid == compare_uid end |
#home ⇒ Object
97 98 99 |
# File 'lib/resources/user.rb', line 97 def home [:home] unless .nil? end |
#identity ⇒ Object
162 163 164 165 |
# File 'lib/resources/user.rb', line 162 def identity return @id_cache if defined?(@id_cache) @id_cache = @user_provider.identity(@user) if !@user_provider.nil? end |
#maxdays ⇒ Object
returns the maximum days between password changes
111 112 113 |
# File 'lib/resources/user.rb', line 111 def maxdays credentials[:maxdays] unless credentials.nil? end |
#maximum_days_between_password_change ⇒ Object
implement ‘maxdays’ method to be compatible with serverspec
127 128 129 130 |
# File 'lib/resources/user.rb', line 127 def maximum_days_between_password_change deprecated('maximum_days_between_password_change', "Please use: its('maxdays')") maxdays end |
#mindays ⇒ Object
returns the minimum days between password changes
106 107 108 |
# File 'lib/resources/user.rb', line 106 def mindays credentials[:mindays] unless credentials.nil? end |
#minimum_days_between_password_change ⇒ Object
implement ‘mindays’ method to be compatible with serverspec
121 122 123 124 |
# File 'lib/resources/user.rb', line 121 def minimum_days_between_password_change deprecated('minimum_days_between_password_change', "Please use: its('mindays')") mindays end |
#shell ⇒ Object
101 102 103 |
# File 'lib/resources/user.rb', line 101 def shell [:shell] unless .nil? end |
#to_s ⇒ Object
158 159 160 |
# File 'lib/resources/user.rb', line 158 def to_s "User #{@user}" end |
#uid ⇒ Object
81 82 83 |
# File 'lib/resources/user.rb', line 81 def uid identity[:uid] unless identity.nil? end |
#warndays ⇒ Object
returns the days for password change warning
116 117 118 |
# File 'lib/resources/user.rb', line 116 def warndays credentials[:warndays] unless credentials.nil? end |