Class: Secrets::YAML

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/secrets/yaml.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ YAML

array of yaml file paths



19
20
21
22
23
24
25
26
27
28
# File 'lib/inspec/secrets/yaml.rb', line 19

def initialize(target)
  @attributes = ::YAML.load_file(target)

  if @attributes == false || !@attributes.is_a?(Hash)
    Inspec::Log.warn("#{self.class} unable to parse #{target}: invalid YAML or contents is not a Hash")
    @attributes = nil
  end
rescue => e
  raise "Error reading InSpec attributes: #{e}"
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



9
10
11
# File 'lib/inspec/secrets/yaml.rb', line 9

def attributes
  @attributes
end

Class Method Details

.resolve(target) ⇒ Object



11
12
13
14
15
16
# File 'lib/inspec/secrets/yaml.rb', line 11

def self.resolve(target)
  unless target.is_a?(String) && File.file?(target) && ['.yml', '.yaml'].include?(File.extname(target).downcase)
    return nil
  end
  new(target)
end