Enable persistence of license key and license server url in file when passed via test kitchen

Signed-off-by: Nik08 <nikita.mathur@progress.com>
This commit is contained in:
Nik08 2024-09-16 17:32:47 +05:30
parent 7bd146d793
commit d30cfdc3df
2 changed files with 6 additions and 2 deletions

View file

@ -171,6 +171,8 @@ module Inspec
if Inspec::Dist::EXEC_NAME == "inspec"
if Inspec::Telemetry::RunContextProbe.guess_run_context == "test-kitchen"
configure_licensing_config_for_kitchen(@conf)
# Persist the license key in file when passed via test-kitchen
ChefLicensing.fetch_and_persist if @conf[:chef_license_key]
end
ChefLicensing.check_software_entitlement!
end
@ -188,6 +190,9 @@ module Inspec
Inspec::Telemetry.run_starting(runner: self, conf: @conf)
load
run_tests(with)
rescue ChefLicensing::LicenseKeyFetcher::LicenseKeyNotFetchedError
Inspec::Log.error "#{Inspec::Dist::PRODUCT_NAME} cannot execute without valid licenses."
Inspec::UI.new.exit(:license_not_set)
rescue ChefLicensing::SoftwareNotEntitled
Inspec::Log.error "License is not entitled to use InSpec."
Inspec::UI.new.exit(:license_not_entitled)

View file

@ -15,8 +15,7 @@ def configure_licensing_config_for_kitchen(opts = {})
# Reset Chef License server via kitchen when passed in kitchen.yml
opts["chef_license_server"] = opts["chef_license_server"].join(",") if opts["chef_license_server"].is_a? Array
unless opts["chef_license_server"].nil? || opts["chef_license_server"].empty?
config.license_server_url_check_in_file = true
config.license_server_url = opts["chef_license_server"]
ENV["CHEF_LICENSE_SERVER"] = opts["chef_license_server"]
end
end
# Reset Chef License key via kitchen when passed in kitchen.yml