Class: Serverspec::Type::SudoUser
- Inherits:
-
Base
- Object
- Base
- Serverspec::Type::SudoUser
- Defined in:
- lib/serverspec_extra_types/types/sudo_user.rb
Instance Method Summary collapse
- #allowed_to_run_command?(command, user = nil, checkpw = false) ⇒ Boolean
- #exist? ⇒ Boolean
- #has_sudo_disabled? ⇒ Boolean
-
#initialize(name) ⇒ SudoUser
constructor
A new instance of SudoUser.
- #inspection ⇒ Object
- #permission(command) ⇒ Object
- #permissions ⇒ Object
Constructor Details
#initialize(name) ⇒ SudoUser
Returns a new instance of SudoUser.
10 11 12 13 |
# File 'lib/serverspec_extra_types/types/sudo_user.rb', line 10 def initialize(name) super @user = name end |
Instance Method Details
#allowed_to_run_command?(command, user = nil, checkpw = false) ⇒ Boolean
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/serverspec_extra_types/types/sudo_user.rb', line 23 def allowed_to_run_command?(command, user = nil, checkpw = false) perm = (command) if user if checkpw perm[:user] == user && perm[:nopasswd] else perm[:user] == user end else checkpw ? perm && perm[:nopasswd] : perm end end |
#exist? ⇒ Boolean
15 16 17 18 19 20 21 |
# File 'lib/serverspec_extra_types/types/sudo_user.rb', line 15 def exist? if get_inspection.success? && /User #{@user} may run the following commands/.match(@get_inspection.stdout) true else false end end |
#has_sudo_disabled? ⇒ Boolean
44 45 46 |
# File 'lib/serverspec_extra_types/types/sudo_user.rb', line 44 def has_sudo_disabled? /User #{@user} is not allowed to run sudo/.match(@get_inspection.stdout) end |
#inspection ⇒ Object
48 49 50 |
# File 'lib/serverspec_extra_types/types/sudo_user.rb', line 48 def inspection @inspection ||= get_sudo_perms(get_inspection.stdout) end |
#permission(command) ⇒ Object
36 37 38 |
# File 'lib/serverspec_extra_types/types/sudo_user.rb', line 36 def (command) .find { |x| x[:command] == command } end |
#permissions ⇒ Object
40 41 42 |
# File 'lib/serverspec_extra_types/types/sudo_user.rb', line 40 def inspection[:permissions] end |