Class: Serverspec::Type::UnixPam
- Inherits:
-
Base
- Object
- Base
- Serverspec::Type::UnixPam
- Defined in:
- lib/serverspec_extra_types/types/unix_pam.rb
Instance Method Summary collapse
- #account(acc) ⇒ Object
- #accounts ⇒ Object
- #auth(auth) ⇒ Object
- #auths ⇒ Object
- #exists? ⇒ Boolean
-
#get_inspection ⇒ Object
rubocop:disable Naming/AccessorMethodName.
- #has_account?(account, control = nil, args = nil) ⇒ Boolean
- #has_auth?(auth, control = nil, args = nil) ⇒ Boolean
- #has_include?(inc) ⇒ Boolean
- #has_password?(password, control = nil, args = nil) ⇒ Boolean
- #has_session?(session, control = nil, args = nil) ⇒ Boolean
- #host(host_id) ⇒ Object
- #include(inc) ⇒ Object
- #include?(inc) ⇒ Boolean
- #includes ⇒ Object
-
#initialize(name = nil, dir = '/etc/pam.d', options = {}) ⇒ UnixPam
constructor
A new instance of UnixPam.
- #inspection ⇒ Object
- #password(passwd) ⇒ Object
- #passwords ⇒ Object
- #session(ses) ⇒ Object
- #sessions ⇒ Object
Constructor Details
#initialize(name = nil, dir = '/etc/pam.d', options = {}) ⇒ UnixPam
Returns a new instance of UnixPam.
9 10 11 12 13 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 9 def initialize(name = nil, dir = '/etc/pam.d', = {}) super(name, ) @name = name @dir = dir end |
Instance Method Details
#account(acc) ⇒ Object
39 40 41 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 39 def account(acc) accounts[acc] end |
#accounts ⇒ Object
35 36 37 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 35 def accounts inspection['account'] end |
#auth(auth) ⇒ Object
23 24 25 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 23 def auth(auth) auths[auth] end |
#auths ⇒ Object
19 20 21 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 19 def auths inspection['auth'] end |
#exists? ⇒ Boolean
15 16 17 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 15 def exists? get_inspection.success? end |
#get_inspection ⇒ Object
rubocop:disable Naming/AccessorMethodName
124 125 126 127 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 124 def get_inspection command = "cat #{@dir}/#{@name}" @get_inspection ||= @runner.run_command(command) end |
#has_account?(account, control = nil, args = nil) ⇒ Boolean
67 68 69 70 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 67 def has_account?(account, control = nil, args = nil) acc = self.account(account) check(acc, control, args) end |
#has_auth?(auth, control = nil, args = nil) ⇒ Boolean
72 73 74 75 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 72 def has_auth?(auth, control = nil, args = nil) ath = self.auth(auth) check(ath, control, args) end |
#has_include?(inc) ⇒ Boolean
63 64 65 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 63 def has_include?(inc) include? inc end |
#has_password?(password, control = nil, args = nil) ⇒ Boolean
82 83 84 85 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 82 def has_password?(password, control = nil, args = nil) psw = self.password(password) check(psw, control, args) end |
#has_session?(session, control = nil, args = nil) ⇒ Boolean
77 78 79 80 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 77 def has_session?(session, control = nil, args = nil) ses = self.session(session) check(ses, control, args) end |
#host(host_id) ⇒ Object
89 90 91 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 89 def host(host_id) hosts[host_id] end |
#include(inc) ⇒ Object
55 56 57 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 55 def include(inc) includes.include? inc end |
#include?(inc) ⇒ Boolean
59 60 61 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 59 def include?(inc) !self.include(inc).nil? end |
#includes ⇒ Object
51 52 53 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 51 def includes inspection['include'] end |
#inspection ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 93 def inspection unless @inspection config = {} get_inspection.stdout.each_line do |line| if line.start_with?(/[a-z]/) parts = %r{^([a-z]+)(?:\s+)([a-z]+|\[[a-z0-9= _]*\])(?:\s+)([a-z_\.]+)(?:\s?)(.*)}.match line next unless parts config[parts[1]] = {} unless config[parts[1]] if config.dig(parts[1],parts[3]) data = {'flag' => parts[2] } data['args'] = parts[4].split unless [nil, '' ].include?(parts[4]) config[parts[1]][parts[3]] << data else config[parts[1]][parts[3]] = [] data = {'flag' => parts[2] } data['args'] = parts[4].split unless [nil, '' ].include?(parts[4]) config[parts[1]][parts[3]] << data end elsif line.start_with? '@inc' parts = %r{^@[a-z]+(?:\s+)([a-z\-]+|\[[a-z0-9_=\-]*\])}.match line next unless parts config['include'] = [] unless config['include'] config['include'] << parts[1] end end @inspection = config end @inspection end |
#password(passwd) ⇒ Object
47 48 49 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 47 def password(passwd) passwords[passwd] end |
#passwords ⇒ Object
43 44 45 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 43 def passwords inspection['password'] end |
#session(ses) ⇒ Object
31 32 33 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 31 def session(ses) sessions[ses] end |
#sessions ⇒ Object
27 28 29 |
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 27 def sessions inspection['session'] end |