Class: Serverspec::Type::UnixPam

Inherits:
Base
  • Object
show all
Defined in:
lib/serverspec_extra_types/types/unix_pam.rb

Instance Method Summary collapse

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', options = {})
  super(name, options)
  @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 (acc)
  accounts[acc]
end

#accountsObject



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

#authsObject



19
20
21
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 19

def auths
  inspection['auth']
end

#exists?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 15

def exists?
  get_inspection.success?
end

#get_inspectionObject

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

Returns:

  • (Boolean)


67
68
69
70
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 67

def has_account?(, control = nil, args = nil)
  acc = self.()
  check(acc, control, args)
end

#has_auth?(auth, control = nil, args = nil) ⇒ Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


59
60
61
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 59

def include?(inc)
  !self.include(inc).nil?
end

#includesObject



51
52
53
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 51

def includes
  inspection['include']
end

#inspectionObject



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

#passwordsObject



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

#sessionsObject



27
28
29
# File 'lib/serverspec_extra_types/types/unix_pam.rb', line 27

def sessions
  inspection['session']
end