class Serverspec::Type::UnixPam
Public Class Methods
new(name = nil, dir = '/etc/pam.d', options = {})
click to toggle source
Calls superclass method
# File lib/serverspec_extra_types/types/unix_pam.rb, line 9 def initialize(name = nil, dir = '/etc/pam.d', options = {}) super(name, options) @name = name @dir = dir end
Public Instance Methods
account(acc)
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 39 def account(acc) accounts[acc] end
accounts()
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 35 def accounts inspection['account'] end
auth(auth)
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 23 def auth(auth) auths[auth] end
auths()
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 19 def auths inspection['auth'] end
exists?()
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 15 def exists? get_inspection.success? end
get_inspection()
click to toggle source
rubocop:disable Naming/AccessorMethodName
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 89 def host(host_id) hosts[host_id] end
include(inc)
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 55 def include(inc) includes.include? inc end
include?(inc)
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 59 def include?(inc) !self.include(inc).nil? end
includes()
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 51 def includes inspection['include'] end
inspection()
click to toggle source
# 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)
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 47 def password(passwd) passwords[passwd] end
passwords()
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 43 def passwords inspection['password'] end
session(ses)
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 31 def session(ses) sessions[ses] end
sessions()
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 27 def sessions inspection['session'] end
Private Instance Methods
check(mod, control = nil, args = nil )
click to toggle source
rubocop:enable Naming/AccessorMethodName
# File lib/serverspec_extra_types/types/unix_pam.rb, line 132 def check(mod, control = nil, args = nil ) if args && control check_args(args, mod) && check_flags(control, mod) elsif args check_args(args, mod) elsif control check_flags(control, mod) else !mod.nil? end end
check_args(args, mod)
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 148 def check_args(args, mod) if args.is_a? Array mod.find {|a| (a['args'] - args).empty?} else mod.find {|a| a['args'].include? args} end end
check_flags(control, mod)
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 144 def check_flags(control, mod) mod.find {|a| a['flag'] == control} end
check_options(host_id, opts)
click to toggle source
# File lib/serverspec_extra_types/types/unix_pam.rb, line 156 def check_options(host_id, opts) options = opts.include?(',') ? opts.spilt(',') : opts if options.is_a? Array host(host_id).split(',').include?(options) else host(host_id).include?(options) end end