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
-
.resolve(target) ⇒ Object
rubocop:disable PerceivedComplexity.
- .target_url(profile, config) ⇒ Object
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
rubocop:disable PerceivedComplexity
16 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 49 50 51 52 53 54 |
# File 'lib/bundles/inspec-compliance/target.rb', line 16 def self.resolve(target) # rubocop:disable PerceivedComplexity 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? if config['server_type'] == 'automate' server = 'automate' msg = 'inspec compliance login_automate https://your_automate_server --user USER --ent ENT --dctoken DCTOKEN or --usertoken USERTOKEN' else server = 'compliance' msg = "inspec compliance login https://your_compliance_server --user admin --insecure --token 'PASTE TOKEN HERE' " end fail Inspec::FetcherFailure, "\nCannot fetch \#{uri} because your \#{server} token has not been\nconfigured.\n\nPlease login using\n\n\#{msg}\n" end # verifies that the target e.g base/ssh exists profile = uri.host + uri.path if !Compliance::API.exist?(config, profile) fail Inspec::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
56 57 58 59 60 61 62 63 64 |
# File 'lib/bundles/inspec-compliance/target.rb', line 56 def self.target_url(profile, config) if config['server_type'] == 'automate' target = "#{config['server']}/#{profile}/tar" else owner, id = profile.split('/') target = "#{config['server']}/owners/#{owner}/compliance/#{id}/tar" end target 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.
70 71 72 |
# File 'lib/bundles/inspec-compliance/target.rb', line 70 def resolved_source { compliance: supermarket_profile_name } end |
#to_s ⇒ Object
74 75 76 |
# File 'lib/bundles/inspec-compliance/target.rb', line 74 def to_s 'Chef Compliance Profile Loader' end |