Sha256: 55599e23ed9213e6b6eff71197e6e1bde253191809051a256cbc662325db320c

Contents?: true

Size: 1.17 KB

Versions: 21

Compression:

Stored size: 1.17 KB

Contents

# encoding: utf-8
# author: Christoph Hartmann
# author: Dominik Richter

require 'uri'
require 'inspec/fetcher'
require 'fetchers/url'

# InSpec Target Helper for Chef Compliance
# reuses UrlHelper, but it knows the target server and the access token already
# similar to `inspec exec http://localhost:2134/owners/%base%/compliance/%ssh%/tar --user %token%`
module Compliance
  class Fetcher < Fetchers::Url
    name 'compliance'
    priority 500

    def self.resolve(target, _opts = {})
      # check for local scheme compliance://
      uri = URI(target)
      return nil unless URI(uri).scheme == 'compliance'

      # check if we have a compliance token
      config = Compliance::Configuration.new
      return nil if config['token'].nil?

      # verifies that the target e.g base/ssh exists
      profile = uri.host + uri.path
      Compliance::API.exist?(config, profile)
      super(target_url(config, profile), config)
    rescue URI::Error => _e
      nil
    end

    def self.target_url(config, profile)
      owner, id = profile.split('/')
      "#{config['server']}/owners/#{owner}/compliance/#{id}/tar"
    end

    def to_s
      'Chef Compliance Profile Loader'
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
inspec-0.30.0 lib/bundles/inspec-compliance/target.rb
inspec-0.29.0 lib/bundles/inspec-compliance/target.rb
inspec-0.28.1 lib/bundles/inspec-compliance/target.rb
inspec-0.28.0 lib/bundles/inspec-compliance/target.rb
inspec-0.27.1 lib/bundles/inspec-compliance/target.rb
inspec-0.27.0 lib/bundles/inspec-compliance/target.rb
inspec-0.26.0 lib/bundles/inspec-compliance/target.rb
inspec-0.25.0 lib/bundles/inspec-compliance/target.rb
inspec-0.24.0 lib/bundles/inspec-compliance/target.rb
inspec-0.23 lib/bundles/inspec-compliance/target.rb
inspec-0.22.1 lib/bundles/inspec-compliance/target.rb
inspec-0.22.0 lib/bundles/inspec-compliance/target.rb
inspec-0.21.6 lib/bundles/inspec-compliance/target.rb
inspec-0.21.5 lib/bundles/inspec-compliance/target.rb
inspec-0.21.4 lib/bundles/inspec-compliance/target.rb
inspec-0.21.3 lib/bundles/inspec-compliance/target.rb
inspec-0.21.2 lib/bundles/inspec-compliance/target.rb
inspec-0.21.1 lib/bundles/inspec-compliance/target.rb
inspec-0.21.0 lib/bundles/inspec-compliance/target.rb
inspec-0.20.1 lib/bundles/inspec-compliance/target.rb