mirror of
https://github.com/inspec/inspec
synced 2024-11-27 07:00:39 +00:00
Merge pull request #1334 from chef/vj/compliance-upload-vendor
Vendor profile when uploading to chef-compliance
This commit is contained in:
commit
861027a140
3 changed files with 33 additions and 29 deletions
|
@ -128,6 +128,8 @@ module Compliance
|
|||
exit 1
|
||||
end
|
||||
|
||||
vendor_deps(path, options) if File.directory?(path)
|
||||
|
||||
o = options.dup
|
||||
configure_logger(o)
|
||||
# check the profile, we only allow to upload valid profiles
|
||||
|
@ -172,7 +174,6 @@ module Compliance
|
|||
# if it is a directory, tar it to tmp directory
|
||||
if File.directory?(path)
|
||||
archive_path = Dir::Tmpname.create([profile_name, '.tar.gz']) {}
|
||||
# archive_path = file.path
|
||||
puts "Generate temporary profile archive at #{archive_path}"
|
||||
profile.archive({ output: archive_path, ignore_errors: false, overwrite: true })
|
||||
else
|
||||
|
|
|
@ -146,6 +146,35 @@ module Inspec
|
|||
end
|
||||
end
|
||||
|
||||
def vendor_deps(path, opts)
|
||||
path.nil? ? path = Pathname.new(Dir.pwd) : path = Pathname.new(path)
|
||||
cache_path = path.join('vendor')
|
||||
inspec_lock = path.join('inspec.lock')
|
||||
|
||||
if (cache_path.exist? || inspec_lock.exist?) && !opts[:overwrite]
|
||||
puts 'Profile is already vendored. Use --overwrite.'
|
||||
return false
|
||||
end
|
||||
|
||||
# remove existing
|
||||
FileUtils.rm_rf(cache_path) if cache_path.exist?
|
||||
File.delete(inspec_lock) if inspec_lock.exist?
|
||||
|
||||
puts "Vendor dependencies of #{path} into #{cache_path}"
|
||||
opts[:logger] = Logger.new(STDOUT)
|
||||
opts[:logger].level = get_log_level(opts.log_level)
|
||||
opts[:cache] = Inspec::Cache.new(cache_path.to_s)
|
||||
opts[:backend] = Inspec::Backend.create(target: 'mock://')
|
||||
configure_logger(opts)
|
||||
|
||||
# vendor dependencies and generate lockfile
|
||||
profile = Inspec::Profile.for_target(path.to_s, opts)
|
||||
lockfile = profile.generate_lockfile
|
||||
File.write(inspec_lock, lockfile.to_yaml)
|
||||
rescue StandardError => e
|
||||
pretty_handle_exception(e)
|
||||
end
|
||||
|
||||
def configure_logger(o)
|
||||
#
|
||||
# TODO(ssd): This is a big gross, but this configures the
|
||||
|
|
|
@ -109,35 +109,9 @@ class Inspec::InspecCLI < Inspec::BaseCLI # rubocop:disable Metrics/ClassLength
|
|||
desc 'vendor PATH', 'Download all dependencies and generate a lockfile in a `vendor` directory'
|
||||
option :overwrite, type: :boolean, default: false,
|
||||
desc: 'Overwrite existing vendored dependencies and lockfile.'
|
||||
def vendor(path = nil) # rubocop:disable Metrics/AbcSize
|
||||
def vendor(path = nil)
|
||||
o = opts.dup
|
||||
|
||||
path.nil? ? path = Pathname.new(Dir.pwd) : path = Pathname.new(path)
|
||||
cache_path = path.join('vendor')
|
||||
inspec_lock = path.join('inspec.lock')
|
||||
|
||||
if (cache_path.exist? || inspec_lock.exist?) && !opts[:overwrite]
|
||||
puts 'Profile is already vendored. Use --overwrite.'
|
||||
return false
|
||||
end
|
||||
|
||||
# remove existing
|
||||
FileUtils.rm_rf(cache_path) if cache_path.exist?
|
||||
File.delete(inspec_lock) if inspec_lock.exist?
|
||||
|
||||
puts "Vendor dependencies of #{path} into #{cache_path}"
|
||||
o[:logger] = Logger.new(STDOUT)
|
||||
o[:logger].level = get_log_level(o.log_level)
|
||||
o[:cache] = Inspec::Cache.new(cache_path.to_s)
|
||||
o[:backend] = Inspec::Backend.create(target: 'mock://')
|
||||
configure_logger(o)
|
||||
|
||||
# vendor dependencies and generate lockfile
|
||||
profile = Inspec::Profile.for_target(path.to_s, o)
|
||||
lockfile = profile.generate_lockfile
|
||||
File.write(inspec_lock, lockfile.to_yaml)
|
||||
rescue StandardError => e
|
||||
pretty_handle_exception(e)
|
||||
vendor_deps(path, o)
|
||||
end
|
||||
|
||||
desc 'archive PATH', 'archive a profile to tar.gz (default) or zip'
|
||||
|
|
Loading…
Reference in a new issue