Skip to content

Commit

Permalink
Raise exception if no token is set when using the chef-automate fetch…
Browse files Browse the repository at this point in the history
…er (#249)

The chef-automate fetcher uses the data_collector token settings but
does not check to ensure it's set before passing it to InSpec for
Fetcher purposes. This causes InSpec to create a data-collector-token
header with a nil value, and then Net::HTTP will toss an ugly error
when trying to call `#strip` on nil.

InSpec should validate inputs too, but this will help catch this issue
in the audit cookbook and provide a better error message. This was
found in the Chef sales demo environments.

Signed-off-by: Adam Leff <adam@leff.co>
  • Loading branch information
adamleff authored Jun 22, 2017
1 parent c329aa7 commit c822a05
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions files/default/vendor/chef-automate/fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def self.resolve(target)
url = URI(dc[:server_url])
url.path = profile_path
profile_fetch_url = url.to_s

raise 'No data-collector token set, which is required by the chef-automate fetcher. ' \
'Set the `data_collector.token` configuration parameter in your client.rb ' \
'or use the "chef-server-automate" reporter which does not require any ' \
'data-collector settings and uses Chef Server to fetch profiles.' if dc[:token].nil?

config = {
'token' => dc[:token],
}
Expand Down

0 comments on commit c822a05

Please sign in to comment.