mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
Allow to switch off the license check
similar to the approach in chef/chef: https://github.com/chef/chef/pull/8354/files#diff-847fc1c7c0af04a65c570c6f4c3381e9R25 Signed-off-by: Artem Sidorenko <artem.sidorenko@t-systems.com>
This commit is contained in:
parent
c0643c33ee
commit
9d03fd7882
3 changed files with 27 additions and 21 deletions
|
@ -9,4 +9,4 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|||
|
||||
require 'inspec'
|
||||
require 'inspec/cli'
|
||||
Inspec::InspecCLI.start(ARGV)
|
||||
Inspec::InspecCLI.start(ARGV, enforce_license: true)
|
||||
|
|
|
@ -23,6 +23,32 @@ module Inspec
|
|||
attr_accessor :inspec_cli_command
|
||||
end
|
||||
|
||||
def self.start(given_args = ARGV, config = {})
|
||||
check_license! if config[:enforce_license] || config[:enforce_license].nil?
|
||||
|
||||
super(given_args, config)
|
||||
end
|
||||
|
||||
# EULA acceptance
|
||||
def self.check_license!
|
||||
allowed_commands = ['-h', '--help', 'help', '-v', '--version', 'version']
|
||||
|
||||
require 'license_acceptance/acceptor'
|
||||
begin
|
||||
if (allowed_commands & ARGV.map(&:downcase)).empty? && # Did they use a non-exempt command?
|
||||
!ARGV.empty? # Did they supply at least one command?
|
||||
LicenseAcceptance::Acceptor.check_and_persist(
|
||||
'inspec',
|
||||
Inspec::VERSION,
|
||||
logger: Inspec::Log,
|
||||
)
|
||||
end
|
||||
rescue LicenseAcceptance::LicenseNotAcceptedError
|
||||
Inspec::Log.error 'InSpec cannot execute without accepting the license'
|
||||
Inspec::UI.new.exit(:license_not_accepted)
|
||||
end
|
||||
end
|
||||
|
||||
# https://github.com/erikhuda/thor/issues/244
|
||||
def self.exit_on_failure?
|
||||
true
|
||||
|
|
|
@ -387,26 +387,6 @@ end
|
|||
#=====================================================================#
|
||||
|
||||
help_commands = ['-h', '--help', 'help']
|
||||
version_commands = ['-v', '--version', 'version']
|
||||
commands_exempt_from_license_check = help_commands + version_commands
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# EULA acceptance
|
||||
#---------------------------------------------------------------------#
|
||||
require 'license_acceptance/acceptor'
|
||||
begin
|
||||
if (commands_exempt_from_license_check & ARGV.map(&:downcase)).empty? && # Did they use a non-exempt command?
|
||||
!ARGV.empty? # Did they supply at least one command?
|
||||
LicenseAcceptance::Acceptor.check_and_persist(
|
||||
'inspec',
|
||||
Inspec::VERSION,
|
||||
logger: Inspec::Log,
|
||||
)
|
||||
end
|
||||
rescue LicenseAcceptance::LicenseNotAcceptedError
|
||||
Inspec::Log.error 'InSpec cannot execute without accepting the license'
|
||||
Inspec::UI.new.exit(:license_not_accepted)
|
||||
end
|
||||
|
||||
#---------------------------------------------------------------------#
|
||||
# Adjustments for help handling
|
||||
|
|
Loading…
Reference in a new issue