Changes in approach of using license context within Inspec

Signed-off-by: Nik08 <nikita.mathur@progress.com>
This commit is contained in:
Nik08 2023-11-22 17:30:33 +05:30
parent c9b1018e0f
commit 2d755f9f1b
4 changed files with 6 additions and 24 deletions

View file

@ -57,4 +57,4 @@ group :deploy do
gem "inquirer"
end
gem "chef-licensing", git: "https://github.com/chef/chef-licensing", glob: "components/ruby/*.gemspec", branch: "nm/fetch_and_persist_api_changes"
gem "chef-licensing", git: "https://github.com/chef/chef-licensing", glob: "components/ruby/*.gemspec", branch: "nm/license-context-changes"

View file

@ -6,7 +6,6 @@ require "inspec/config"
require "inspec/dist"
require "inspec/utils/deprecation/global_method"
require "inspec/utils/licensing_config"
require "inspec/license_context"
# Allow end of options during array type parsing
# https://github.com/erikhuda/thor/issues/631
@ -45,12 +44,10 @@ module Inspec
allowed_commands = ["-h", "--help", "help", "-v", "--version", "version", "license"]
begin
if (allowed_commands & ARGV.map(&:downcase)).empty? && !ARGV.empty?
licenses_context = ChefLicensing.fetch_and_persist
# cache license_context object
Inspec::LicenseContext.cached = licenses_context.first
license_keys = ChefLicensing.fetch_and_persist
# Only if EULA acceptance or license key args are present. And licenses are successfully persisted, do clean exit.
if ARGV.select { |arg| !(arg.include? "--chef-license") }.empty? && !licenses_context.empty?
if ARGV.select { |arg| !(arg.include? "--chef-license") }.empty? && !license_keys.empty?
Inspec::UI.new.exit
end
end

View file

@ -1,15 +0,0 @@
module Inspec
class LicenseContext
# Returns license_context object used by InSpec
# Returns cached license_context
def self.cached
@license_context ||= nil
end
# Caches license_context
def self.cached=(license_context)
@license_context ||= license_context
end
end
end

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require "inspec/license_context"
require "chef-licensing"
module Inspec
class LicenseDataCollector
@ -124,9 +124,9 @@ module Inspec
private
# TODO: fetch the already cached license object
def license
@license ||= Inspec::LicenseContext.cached
# TBD Need to confirm on this implementation from arch team
@license ||= ChefLicensing.license_context
end
end