Sha256: d1a2ebc2089f0d86c9b49affaae4fb861177cf05a1b1e29f4738b27d7f53ad46

Contents?: true

Size: 753 Bytes

Versions: 6

Compression:

Stored size: 753 Bytes

Contents

# encoding: utf-8

require 'yaml'

module Secrets
  class YAML < Inspec.secrets(1)
    name 'yaml'

    attr_reader :attributes

    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

    # array of yaml file paths
    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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
inspec-2.1.81 lib/inspec/secrets/yaml.rb
inspec-2.1.21 lib/inspec/secrets/yaml.rb
inspec-2.1.10 lib/inspec/secrets/yaml.rb
inspec-2.0.32 lib/inspec/secrets/yaml.rb
inspec-2.0.17 lib/inspec/secrets/yaml.rb
inspec-1.51.15 lib/inspec/secrets/yaml.rb