Class: Inspec::Resources::SshConfig

Inherits:
Object
  • Object
show all
Includes:
FileReader
Defined in:
lib/inspec/resources/ssh_config.rb

Direct Known Subclasses

SshdConfig

Instance Method Summary collapse

Methods included from FileReader

#read_file_content

Constructor Details

#initialize(conf_path = nil, type = nil) ⇒ SshConfig

Returns a new instance of SshConfig.



21
22
23
24
25
26
# File 'lib/inspec/resources/ssh_config.rb', line 21

def initialize(conf_path = nil, type = nil)
  @conf_path = conf_path || "/etc/ssh/ssh_config"
  typename = (@conf_path.include?("sshd") ? "Server" : "Client")
  @type = type || "SSH #{typename} configuration #{conf_path}"
  read_content
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/inspec/resources/ssh_config.rb', line 46

def method_missing(name)
  param = read_params[name.to_s.downcase]
  return nil if param.nil?
  # extract first value if we have only one value in array
  return param[0] if param.length == 1

  param
end

Instance Method Details

#contentObject



28
29
30
# File 'lib/inspec/resources/ssh_config.rb', line 28

def content
  read_content
end

#convert_hash(hash) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/inspec/resources/ssh_config.rb', line 38

def convert_hash(hash)
  new_hash = {}
  hash.each do |k, v|
    new_hash[k.downcase] = v
  end
  new_hash
end

#params(*opts) ⇒ Object



32
33
34
35
36
# File 'lib/inspec/resources/ssh_config.rb', line 32

def params(*opts)
  opts.inject(read_params) do |res, nxt|
    res.respond_to?(:key) ? res[nxt] : nil
  end
end

#to_sObject



55
56
57
# File 'lib/inspec/resources/ssh_config.rb', line 55

def to_s
  "SSH Configuration"
end