Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chef-cli.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/chef-cli/builtin_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
184 changes: 92 additions & 92 deletions lib/chef-cli/command/license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 21 additions & 21 deletions lib/chef-cli/licensing/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions lib/chef-cli/licensing/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/unit/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading