From 606bfb154ca0fcdeef0271df49c6945a0682c2cc Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Tue, 10 Jun 2025 16:19:35 +0530 Subject: [PATCH] Removed the chef-cli license command Signed-off-by: Ashique Saidalavi --- chef-cli.gemspec | 2 +- lib/chef-cli/builtin_commands.rb | 4 +- lib/chef-cli/command/license.rb | 184 +++++++++---------- lib/chef-cli/licensing/base.rb | 42 ++--- lib/chef-cli/licensing/config.rb | 14 +- spec/unit/cli_spec.rb | 2 +- spec/unit/command/license_spec.rb | 290 +++++++++++++++--------------- 7 files changed, 269 insertions(+), 269 deletions(-) diff --git a/chef-cli.gemspec b/chef-cli.gemspec index b640dbcb..833b9767 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -50,5 +50,5 @@ Gem::Specification.new do |gem| gem.add_dependency "diff-lcs", ">= 1.2.4", "!= 1.4.0", "< 1.6.0" # 1.4 breaks output. Used in lib/chef/util/diff gem.add_dependency "pastel", "~> 0.7" # used for policyfile differ gem.add_dependency "license-acceptance", ">= 1.0.11", "< 3" - gem.add_dependency "chef-licensing", "~> 1.0" + # gem.add_dependency "chef-licensing", "~> 1.0" end diff --git a/lib/chef-cli/builtin_commands.rb b/lib/chef-cli/builtin_commands.rb index 1b239792..4631bd11 100644 --- a/lib/chef-cli/builtin_commands.rb +++ b/lib/chef-cli/builtin_commands.rb @@ -57,6 +57,6 @@ c.builtin "describe-cookbook", :DescribeCookbook, require_path: "chef-cli/command/describe_cookbook", desc: "Prints cookbook checksum information used for cookbook identifier" - c.builtin "license", :License, require_path: "chef-cli/command/license", - desc: "Create & install a new license on the system or view installed license(s)." + # c.builtin "license", :License, require_path: "chef-cli/command/license", + # desc: "Create & install a new license on the system or view installed license(s)." end diff --git a/lib/chef-cli/command/license.rb b/lib/chef-cli/command/license.rb index 039fb34e..dfb21475 100644 --- a/lib/chef-cli/command/license.rb +++ b/lib/chef-cli/command/license.rb @@ -16,95 +16,95 @@ # limitations under the License. # -require_relative "base" -require "chef-cli/licensing/base" -require_relative "../configurable" - -module ChefCLI - module Command - - # This class will manage the license command in the chef-cli - class License < Base - - include Configurable - - MAIN_COMMAND_HELP = <<~HELP.freeze - Usage: #{ChefCLI::Dist::EXEC} license [SUBCOMMAND] - - `#{ChefCLI::Dist::EXEC} license` command will validate the existing license - or will help you interactively generate new free/trial license and activate the - commercial license the chef team has sent you through email. - HELP - - SUB_COMMANDS = [ - { name: "list", description: "List details of the license(s) installed on the system." }, - { name: "add", description: "Create & install a Free/ Trial license or install a Commercial license on the system." }, - ].freeze - - option :chef_license_key, - long: "--chef-license-key LICENSE", - description: "New license key to accept and store in the system" - - attr_accessor :ui - - def self.banner - <<~BANNER - #{MAIN_COMMAND_HELP} - Subcommands: - #{SUB_COMMANDS.map do |c| - " #{c[:name].ljust(7)}#{c[:description]}" - end.join("\n") } - - Options: - BANNER - end - - def initialize - super - - @ui = UI.new - end - - def run(params) - config_license_debug if debug? - remaining_args = parse_options(params) - return 1 unless validate_params!(remaining_args) - - if remaining_args.blank? - ChefCLI::Licensing::Base.validate - else - ChefCLI::Licensing::Base.send(remaining_args[0]) - end - rescue ChefLicensing::LicenseKeyFetcher::LicenseKeyNotFetchedError - ui.msg("License key not fetched. Please try again.") - end - - def debug? - !!config[:debug] - end - - def validate_params!(args) - if args.length > 1 - ui.err("Too many arguments") - return false - end - - valid_subcommands = SUB_COMMANDS.collect { |c| c[:name] } - args.each do |arg| - next if valid_subcommands.include?(arg) - - ui.err("Invalid option: #{arg}") - return false - end - - true - end - - private - - def config_license_debug - ChefLicensing.output = ui - end - end - end -end +# require_relative "base" +# require "chef-cli/licensing/base" +# require_relative "../configurable" + +# module ChefCLI +# module Command + +# # This class will manage the license command in the chef-cli +# class License < Base + +# include Configurable + +# MAIN_COMMAND_HELP = <<~HELP.freeze +# Usage: #{ChefCLI::Dist::EXEC} license [SUBCOMMAND] + +# `#{ChefCLI::Dist::EXEC} license` command will validate the existing license +# or will help you interactively generate new free/trial license and activate the +# commercial license the chef team has sent you through email. +# HELP + +# SUB_COMMANDS = [ +# { name: "list", description: "List details of the license(s) installed on the system." }, +# { name: "add", description: "Create & install a Free/ Trial license or install a Commercial license on the system." }, +# ].freeze + +# option :chef_license_key, +# long: "--chef-license-key LICENSE", +# description: "New license key to accept and store in the system" + +# attr_accessor :ui + +# def self.banner +# <<~BANNER +# #{MAIN_COMMAND_HELP} +# Subcommands: +# #{SUB_COMMANDS.map do |c| +# " #{c[:name].ljust(7)}#{c[:description]}" +# end.join("\n") } + +# Options: +# BANNER +# end + +# def initialize +# super + +# @ui = UI.new +# end + +# def run(params) +# config_license_debug if debug? +# remaining_args = parse_options(params) +# return 1 unless validate_params!(remaining_args) + +# if remaining_args.blank? +# ChefCLI::Licensing::Base.validate +# else +# ChefCLI::Licensing::Base.send(remaining_args[0]) +# end +# rescue ChefLicensing::LicenseKeyFetcher::LicenseKeyNotFetchedError +# ui.msg("License key not fetched. Please try again.") +# end + +# def debug? +# !!config[:debug] +# end + +# def validate_params!(args) +# if args.length > 1 +# ui.err("Too many arguments") +# return false +# end + +# valid_subcommands = SUB_COMMANDS.collect { |c| c[:name] } +# args.each do |arg| +# next if valid_subcommands.include?(arg) + +# ui.err("Invalid option: #{arg}") +# return false +# end + +# true +# end + +# private + +# def config_license_debug +# ChefLicensing.output = ui +# end +# end +# end +# end diff --git a/lib/chef-cli/licensing/base.rb b/lib/chef-cli/licensing/base.rb index 01845fd5..58be3404 100644 --- a/lib/chef-cli/licensing/base.rb +++ b/lib/chef-cli/licensing/base.rb @@ -16,27 +16,27 @@ # limitations under the License. # -require "chef-licensing" -require_relative "config" +# require "chef-licensing" +# require_relative "config" -module ChefCLI - module Licensing - class Base - class << self - def validate - ChefLicensing.fetch_and_persist.each do |license_key| - puts "License Key: #{license_key}" - end - end +# module ChefCLI +# module Licensing +# class Base +# class << self +# def validate +# ChefLicensing.fetch_and_persist.each do |license_key| +# puts "License Key: #{license_key}" +# end +# end - def list - ChefLicensing.list_license_keys_info - end +# def list +# ChefLicensing.list_license_keys_info +# end - def add - ChefLicensing.add_license - end - end - end - end -end +# def add +# ChefLicensing.add_license +# end +# end +# end +# end +# end diff --git a/lib/chef-cli/licensing/config.rb b/lib/chef-cli/licensing/config.rb index 3d3cbcf8..cfdcfb63 100644 --- a/lib/chef-cli/licensing/config.rb +++ b/lib/chef-cli/licensing/config.rb @@ -16,11 +16,11 @@ # limitations under the License. # -require "chef-licensing" +# require "chef-licensing" -ChefLicensing.configure do |config| - config.chef_product_name = "workstation" - config.chef_entitlement_id = "x6f3bc76-a94f-4b6c-bc97-4b7ed2b045c0" - config.chef_executable_name = "chef" - config.license_server_url = "https://services.chef.io/licensing" -end +# ChefLicensing.configure do |config| +# config.chef_product_name = "workstation" +# config.chef_entitlement_id = "x6f3bc76-a94f-4b6c-bc97-4b7ed2b045c0" +# config.chef_executable_name = "chef" +# config.license_server_url = "https://services.chef.io/licensing" +# end diff --git a/spec/unit/cli_spec.rb b/spec/unit/cli_spec.rb index 10e1515a..020fd54c 100644 --- a/spec/unit/cli_spec.rb +++ b/spec/unit/cli_spec.rb @@ -90,7 +90,7 @@ def mock_shell_out(exitstatus, stdout, stderr) commands_map.builtin "example", :TestCommand, require_path: "unit/fixtures/command/cli_test_command", desc: "Example subcommand for testing" - allow(ChefCLI::Licensing::Base).to receive(:validate).and_return(true) + # allow(ChefCLI::Licensing::Base).to receive(:validate).and_return(true) end context "given no arguments or options" do diff --git a/spec/unit/command/license_spec.rb b/spec/unit/command/license_spec.rb index a53a7e44..da1dadf1 100644 --- a/spec/unit/command/license_spec.rb +++ b/spec/unit/command/license_spec.rb @@ -15,148 +15,148 @@ # limitations under the License. # -require "spec_helper" -require "chef-cli/command/license" -require "shared/command_with_ui_object" -require "chef-cli/licensing/base" - -describe ChefCLI::Command::License do - it_behaves_like "a command with a UI object" - - let(:params) { [] } - let(:ui) { TestHelpers::TestUI.new } - - before do - # Disable the access of local licenses - allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:fetch_license_key_from_arg).and_return([]) - allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:fetch_license_key_from_env).and_return([]) - allow_any_instance_of(ChefLicensing::LicensingService::Local).to receive(:detected?).and_return(false) - end - - let(:command) do - c = described_class.new - c.validate_params!(params) - c.ui = ui - c - end - - it "disables debug by default" do - expect(command.debug?).to be(false) - end - - context "invalid parameters passed" do - let(:multiple_params) { %w{add list} } - let(:invalid_command) { %w{not_a_subcommand} } - - it "should fail with errors when multiple subcommands passed" do - expect(command.run(multiple_params)).to eq(1) - end - - it "should fail for invalid argument" do - expect(command.run(invalid_command)).to eq(1) - end - end - - context "license command" do - context "when pre-accepted license exists" do - let(:license_keys) { %w{tsmc-abcd} } - - before(:each) do - allow(ChefLicensing).to receive(:fetch_and_persist).and_return(license_keys) - end - - it "should be successful" do - expect { command.run(params) }.not_to raise_exception - end - - it "should return the correct license key" do - expect(command.run(params)).to eq(license_keys) - end - end - - context "when no licenses are accepted previously" do - let(:new_key) { ["tsmc-123456789"] } - before(:each) do - ChefLicensing.configure do |config| - config.license_server_url = "https://license.test" - config.chef_product_name = "chef" - config.chef_entitlement_id = "chef-entitled-id" - config.chef_executable_name = "chef" - end - - # Disable the active license check - allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:licenses_active?).and_return(false) - # Disable the UI engine - allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:append_extra_info_to_tui_engine) - # Disable the API call to fetch the license type - allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:get_license_type).and_return("free") - # Disable the overwriting to the license.yml file - allow_any_instance_of(ChefLicensing::LicenseKeyFetcher::File).to receive(:persist) - - # Mocks the user prompt to enter the license - allow_any_instance_of(ChefLicensing::LicenseKeyFetcher::Prompt).to receive(:fetch).and_return(new_key) - allow(ChefLicensing).to receive(:fetch_and_persist).and_return(new_key) - end - - it "should create and stores the new license" do - expect { command.run(params) }.not_to raise_exception - end - - it "should be same as the user entered license" do - expect(command.run(params)).to include(new_key.first) - end - end - end - - context "chef license list command" do - let(:params) { %w{list} } - let(:license_key) { "tsmn-123123" } - - before do - command.ui = ui - end - - context "when no licenses are accepted" do - before do - allow_any_instance_of(ChefLicensing::ListLicenseKeys).to receive(:fetch_license_keys).and_return([]) - allow_any_instance_of(ChefLicensing::ListLicenseKeys).to receive(:fetch_licenses_metadata).and_return([]) - end - - it "should return the correct error message" do - expect(command.run(params)).to eq([]) - end - end - - context "when there is a valid license" do - before do - allow(ChefLicensing).to receive(:list_license_keys_info).and_return(license_key) - end - - it "should print the license details" do - expect(command.run(params)).to eq(license_key) - end - end - end - - context "chef license add command" do - let(:params) { %w{add} } - let(:license_key) { ["tsmn-123123"] } - - before do - # Disable the API call to fetch the license type - allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:get_license_type).and_return("free") - # Disable the overwriting to the license.yml file - allow_any_instance_of(ChefLicensing::LicenseKeyFetcher::File).to receive(:persist) - # Mocks the user prompt to enter the license - allow_any_instance_of(ChefLicensing::LicenseKeyFetcher::Prompt).to receive(:fetch).and_return(license_key) - end - - it "should not raise any errors" do - expect { command.run(params) }.not_to raise_exception - end - - it "should create and store the new license" do - expect(command.run(params)).to include(license_key.first) - end - end -end +# require "spec_helper" +# require "chef-cli/command/license" +# require "shared/command_with_ui_object" +# require "chef-cli/licensing/base" + +# describe ChefCLI::Command::License do +# it_behaves_like "a command with a UI object" + +# let(:params) { [] } +# let(:ui) { TestHelpers::TestUI.new } + +# before do +# # Disable the access of local licenses +# allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:fetch_license_key_from_arg).and_return([]) +# allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:fetch_license_key_from_env).and_return([]) +# allow_any_instance_of(ChefLicensing::LicensingService::Local).to receive(:detected?).and_return(false) +# end + +# let(:command) do +# c = described_class.new +# c.validate_params!(params) +# c.ui = ui +# c +# end + +# it "disables debug by default" do +# expect(command.debug?).to be(false) +# end + +# context "invalid parameters passed" do +# let(:multiple_params) { %w{add list} } +# let(:invalid_command) { %w{not_a_subcommand} } + +# it "should fail with errors when multiple subcommands passed" do +# expect(command.run(multiple_params)).to eq(1) +# end + +# it "should fail for invalid argument" do +# expect(command.run(invalid_command)).to eq(1) +# end +# end + +# context "license command" do +# context "when pre-accepted license exists" do +# let(:license_keys) { %w{tsmc-abcd} } + +# before(:each) do +# allow(ChefLicensing).to receive(:fetch_and_persist).and_return(license_keys) +# end + +# it "should be successful" do +# expect { command.run(params) }.not_to raise_exception +# end + +# it "should return the correct license key" do +# expect(command.run(params)).to eq(license_keys) +# end +# end + +# context "when no licenses are accepted previously" do +# let(:new_key) { ["tsmc-123456789"] } +# before(:each) do +# ChefLicensing.configure do |config| +# config.license_server_url = "https://license.test" +# config.chef_product_name = "chef" +# config.chef_entitlement_id = "chef-entitled-id" +# config.chef_executable_name = "chef" +# end + +# # Disable the active license check +# allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:licenses_active?).and_return(false) +# # Disable the UI engine +# allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:append_extra_info_to_tui_engine) +# # Disable the API call to fetch the license type +# allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:get_license_type).and_return("free") +# # Disable the overwriting to the license.yml file +# allow_any_instance_of(ChefLicensing::LicenseKeyFetcher::File).to receive(:persist) + +# # Mocks the user prompt to enter the license +# allow_any_instance_of(ChefLicensing::LicenseKeyFetcher::Prompt).to receive(:fetch).and_return(new_key) +# allow(ChefLicensing).to receive(:fetch_and_persist).and_return(new_key) +# end + +# it "should create and stores the new license" do +# expect { command.run(params) }.not_to raise_exception +# end + +# it "should be same as the user entered license" do +# expect(command.run(params)).to include(new_key.first) +# end +# end +# end + +# context "chef license list command" do +# let(:params) { %w{list} } +# let(:license_key) { "tsmn-123123" } + +# before do +# command.ui = ui +# end + +# context "when no licenses are accepted" do +# before do +# allow_any_instance_of(ChefLicensing::ListLicenseKeys).to receive(:fetch_license_keys).and_return([]) +# allow_any_instance_of(ChefLicensing::ListLicenseKeys).to receive(:fetch_licenses_metadata).and_return([]) +# end + +# it "should return the correct error message" do +# expect(command.run(params)).to eq([]) +# end +# end + +# context "when there is a valid license" do +# before do +# allow(ChefLicensing).to receive(:list_license_keys_info).and_return(license_key) +# end + +# it "should print the license details" do +# expect(command.run(params)).to eq(license_key) +# end +# end +# end + +# context "chef license add command" do +# let(:params) { %w{add} } +# let(:license_key) { ["tsmn-123123"] } + +# before do +# # Disable the API call to fetch the license type +# allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:get_license_type).and_return("free") +# # Disable the overwriting to the license.yml file +# allow_any_instance_of(ChefLicensing::LicenseKeyFetcher::File).to receive(:persist) +# # Mocks the user prompt to enter the license +# allow_any_instance_of(ChefLicensing::LicenseKeyFetcher::Prompt).to receive(:fetch).and_return(license_key) +# end + +# it "should not raise any errors" do +# expect { command.run(params) }.not_to raise_exception +# end + +# it "should create and store the new license" do +# expect(command.run(params)).to include(license_key.first) +# end +# end +# end