Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure we use the mock backend when we upload profiles #3370

Merged
merged 1 commit into from Sep 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/bundles/inspec-compliance/cli.rb
Expand Up @@ -149,6 +149,12 @@ def upload(path) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Percei

o = options.dup
configure_logger(o)

# only run against the mock backend, otherwise we run against the local system
o[:backend] = Inspec::Backend.create(target: 'mock://')
o[:check_mode] = true
o[:vendor_cache] = Inspec::Cache.new(o[:vendor_cache])

# check the profile, we only allow to upload valid profiles
profile = Inspec::Profile.for_target(path, o)

Expand Down Expand Up @@ -190,7 +196,9 @@ def upload(path) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Percei
end

# if it is a directory, tar it to tmp directory
generated = false
if File.directory?(path)
generated = true
archive_path = Dir::Tmpname.create([profile_name, '.tar.gz']) {}
puts "Generate temporary profile archive at #{archive_path}"
profile.archive({ output: archive_path, ignore_errors: false, overwrite: true })
Expand All @@ -208,6 +216,9 @@ def upload(path) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Percei
end
success, msg = Compliance::API.upload(config, config['owner'], pname, archive_path)

# delete temp file if it was temporary generated
File.delete(archive_path) if generated && File.exist?(archive_path)

if success
puts 'Successfully uploaded profile'
else
Expand Down