Sha256: af030760b2b56858d746da780fc80981ff632ae420699b2a6ffbca1c773faa1a

Contents?: true

Size: 1006 Bytes

Versions: 9

Compression:

Stored size: 1006 Bytes

Contents

require "yaml"

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

    attr_reader :inputs

    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)
      # Ruby 3.1 treats YAML load as a dangerous operation by default, requiring us to declare date and time classes as permitted
      # It's not a valid option in 3.0.x
      if Gem.ruby_version >= Gem::Version.new("3.1.0")
        @inputs = ::YAML.load_file(target, permitted_classes: [Date, Time])
      else
        @inputs = ::YAML.load_file(target)
      end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
inspec-core-5.22.58 lib/inspec/secrets/yaml.rb
inspec-core-5.22.55 lib/inspec/secrets/yaml.rb
inspec-core-5.22.40 lib/inspec/secrets/yaml.rb
inspec-core-5.22.36 lib/inspec/secrets/yaml.rb
inspec-core-5.22.29 lib/inspec/secrets/yaml.rb
inspec-core-4.56.58 lib/inspec/secrets/yaml.rb
inspec-core-5.22.3 lib/inspec/secrets/yaml.rb
inspec-core-5.21.29 lib/inspec/secrets/yaml.rb
inspec-core-5.18.14 lib/inspec/secrets/yaml.rb