Class: Compliance::Fetcher
- Inherits:
-
Fetchers::Url
- Object
- Fetchers::Url
- Compliance::Fetcher
- Defined in:
- lib/bundles/inspec-compliance/target.rb
Constant Summary
Constants inherited from Fetchers::Url
Fetchers::Url::GITHUB_URL_REGEX, Fetchers::Url::GITHUB_URL_WITH_TREE_REGEX, Fetchers::Url::MIME_TYPES
Instance Attribute Summary
Attributes inherited from Fetchers::Url
Class Method Summary collapse
Instance Method Summary collapse
-
#resolved_source ⇒ Object
We want to save compliance: in the lockfile rather than url: to make sure we go back through the ComplianceAPI handling.
- #to_s ⇒ Object
Methods inherited from Fetchers::Url
#cache_key, #fetch, #initialize, resolve_from_string, transform
Constructor Details
This class inherits a constructor from Fetchers::Url
Class Method Details
.resolve(target) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bundles/inspec-compliance/target.rb', line 17 def self.resolve(target) uri = if target.is_a?(String) && URI(target).scheme == 'compliance' URI(target) elsif target.respond_to?(:key?) && target.key?(:compliance) URI("compliance://#{target[:compliance]}") end return nil if uri.nil? # check if we have a compliance token config = Compliance::Configuration.new if config['token'].nil? fail Inspec::FetcherFailure, <<EOF Cannot fetch #{uri} because your compliance token has not been configured. Please login using inspec compliance login https://your_compliance_server --user admin --insecure --token 'PASTE TOKEN HERE' EOF end # verifies that the target e.g base/ssh exists profile = uri.host + uri.path if !Compliance::API.exist?(config, profile) fail Inpsec::FetcherFailure, "The compliance profile #{profile} was not found on the configured compliance server" end new(target_url(profile, config), config) rescue URI::Error => _e nil end |
.target_url(profile, config) ⇒ Object
50 51 52 53 |
# File 'lib/bundles/inspec-compliance/target.rb', line 50 def self.target_url(profile, config) owner, id = profile.split('/') "#{config['server']}/owners/#{owner}/compliance/#{id}/tar" end |
Instance Method Details
#resolved_source ⇒ Object
We want to save compliance: in the lockfile rather than url: to make sure we go back through the ComplianceAPI handling.
59 60 61 |
# File 'lib/bundles/inspec-compliance/target.rb', line 59 def resolved_source { compliance: supermarket_profile_name } end |
#to_s ⇒ Object
63 64 65 |
# File 'lib/bundles/inspec-compliance/target.rb', line 63 def to_s 'Chef Compliance Profile Loader' end |