chef-licensing 0.4.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -0
  3. data/chef-licensing.gemspec +35 -0
  4. data/lib/chef-licensing/api/client.rb +39 -0
  5. data/lib/chef-licensing/api/describe.rb +62 -0
  6. data/lib/chef-licensing/api/license_feature_entitlement.rb +55 -0
  7. data/lib/chef-licensing/api/license_software_entitlement.rb +53 -0
  8. data/lib/chef-licensing/api/list_licenses.rb +30 -0
  9. data/lib/chef-licensing/api/parser/client.rb +100 -0
  10. data/lib/chef-licensing/api/parser/describe.rb +118 -0
  11. data/lib/chef-licensing/cli_flags/mixlib_cli.rb +28 -0
  12. data/lib/chef-licensing/cli_flags/thor.rb +21 -0
  13. data/lib/chef-licensing/config.rb +44 -0
  14. data/lib/chef-licensing/config_fetcher/arg_fetcher.rb +38 -0
  15. data/lib/chef-licensing/config_fetcher/env_fetcher.rb +21 -0
  16. data/lib/chef-licensing/context.rb +98 -0
  17. data/lib/chef-licensing/exceptions/client_error.rb +9 -0
  18. data/lib/chef-licensing/exceptions/describe_error.rb +9 -0
  19. data/lib/chef-licensing/exceptions/error.rb +4 -0
  20. data/lib/chef-licensing/exceptions/feature_not_entitled.rb +9 -0
  21. data/lib/chef-licensing/exceptions/invalid_license.rb +10 -0
  22. data/lib/chef-licensing/exceptions/license_generation_failed.rb +9 -0
  23. data/lib/chef-licensing/exceptions/license_generation_rejected.rb +7 -0
  24. data/lib/chef-licensing/exceptions/list_licenses_error.rb +12 -0
  25. data/lib/chef-licensing/exceptions/missing_api_credentials_error.rb +7 -0
  26. data/lib/chef-licensing/exceptions/restful_client_connection_error.rb +9 -0
  27. data/lib/chef-licensing/exceptions/restful_client_error.rb +9 -0
  28. data/lib/chef-licensing/exceptions/software_not_entitled.rb +9 -0
  29. data/lib/chef-licensing/license.rb +151 -0
  30. data/lib/chef-licensing/license_key_fetcher/base.rb +28 -0
  31. data/lib/chef-licensing/license_key_fetcher/chef_licensing_interactions.yaml +534 -0
  32. data/lib/chef-licensing/license_key_fetcher/file.rb +275 -0
  33. data/lib/chef-licensing/license_key_fetcher/prompt.rb +43 -0
  34. data/lib/chef-licensing/license_key_fetcher.rb +314 -0
  35. data/lib/chef-licensing/license_key_generator.rb +47 -0
  36. data/lib/chef-licensing/license_key_validator.rb +24 -0
  37. data/lib/chef-licensing/licensing_service/local.rb +29 -0
  38. data/lib/chef-licensing/list_license_keys.rb +142 -0
  39. data/lib/chef-licensing/restful_client/base.rb +139 -0
  40. data/lib/chef-licensing/restful_client/middleware/exceptions_handler.rb +16 -0
  41. data/lib/chef-licensing/restful_client/v1.rb +17 -0
  42. data/lib/chef-licensing/tui_engine/tui_actions.rb +238 -0
  43. data/lib/chef-licensing/tui_engine/tui_engine.rb +174 -0
  44. data/lib/chef-licensing/tui_engine/tui_engine_state.rb +62 -0
  45. data/lib/chef-licensing/tui_engine/tui_exceptions.rb +17 -0
  46. data/lib/chef-licensing/tui_engine/tui_interaction.rb +17 -0
  47. data/lib/chef-licensing/tui_engine/tui_prompt.rb +117 -0
  48. data/lib/chef-licensing/tui_engine.rb +2 -0
  49. data/lib/chef-licensing/version.rb +3 -0
  50. data/lib/chef-licensing.rb +70 -0
  51. metadata +191 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 964f7cfe2142120460f62fe5d859ed5a1fee820b023a66d79d9a5e993a3f83aa
4
+ data.tar.gz: 51459f83f1c053b6da1ef961e550951ed709e1f87cc5ff8dc8e84f2ac3a1f76d
5
+ SHA512:
6
+ metadata.gz: 57a658f34d4d126b60311613f0ca6b8973fd29b3be180cc7082023c51aeef4f02ce2fa8f132e18ae2574137d97fe1da27f3ad2bd66e787d038fd4ded954d07c5
7
+ data.tar.gz: aaa6881007ef1f2377dfe2cce95cf46114a2743d0568e2776777d9ebafe6c49af540c29d2b97678dade43e0634dc018d89bd719f19bc6102189bb957f6f60d45
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ Proprietary code. All rights reserved.
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "chef-licensing/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "chef-licensing"
7
+ spec.version = ChefLicensing::VERSION
8
+ spec.authors = ["Inspec Team"]
9
+ spec.email = ["inspec@progress.com"]
10
+ spec.license = "LicenseRef-LICENSE"
11
+
12
+ spec.summary = %q{Chef License storage, generation, and entitlement}
13
+ spec.description = %q{Ruby library to support CLI tools that use Progress Chef license storage, generation, and entitlement.}
14
+ spec.homepage = "https://github.com/chef/chef-licensing"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/chef/chef-licensing"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ spec.files =
22
+ Dir.glob("{{lib,etc}/**/*,LICENSE,chef-licensing.gemspec}")
23
+ .reject { |f| File.directory?(f) }
24
+
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "chef-config", ">= 15"
30
+ spec.add_dependency "tty-prompt", "~> 0.23"
31
+ spec.add_dependency "faraday", ">= 1", "< 3"
32
+ spec.add_dependency "faraday-http-cache"
33
+ spec.add_dependency "activesupport", "~> 7.0", ">= 7.0.4.2"
34
+ spec.add_dependency "tty-spinner", "~> 0.9.3"
35
+ end
@@ -0,0 +1,39 @@
1
+ require_relative "../restful_client/v1"
2
+ require_relative "../exceptions/client_error"
3
+ require_relative "../license"
4
+ require_relative "../config"
5
+
6
+ module ChefLicensing
7
+ module Api
8
+ class Client
9
+ attr_reader :license_keys, :entitlement_id
10
+
11
+ class << self
12
+ def info(opts = {})
13
+ new(opts).info
14
+ end
15
+ end
16
+
17
+ def initialize(opts = {})
18
+ @license_keys = opts[:license_keys] || raise(ArgumentError, "Missing Params: `license_keys`")
19
+ @restful_client = opts[:restful_client] ? opts[:restful_client].new : ChefLicensing::RestfulClient::V1.new
20
+ end
21
+
22
+ def info
23
+ response = restful_client.client(license_keys: license_keys.join(","), entitlement_id: ChefLicensing::Config.chef_entitlement_id)
24
+ if response.data
25
+ ChefLicensing::License.new(
26
+ data: response.data,
27
+ api_parser: ChefLicensing::Api::Parser::Client
28
+ )
29
+ else
30
+ raise(ChefLicensing::ClientError, response.message)
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ attr_reader :restful_client
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,62 @@
1
+ require_relative "../restful_client/v1"
2
+ require_relative "../exceptions/describe_error"
3
+ require_relative "../license"
4
+ require_relative "../config"
5
+ require "ostruct" unless defined?(OpenStruct)
6
+
7
+ module ChefLicensing
8
+ module Api
9
+ class Describe
10
+ attr_reader :license_keys
11
+
12
+ class << self
13
+ def list(opts = {})
14
+ new(opts).list
15
+ end
16
+ end
17
+
18
+ def initialize(opts = {})
19
+ @license_keys = opts[:license_keys] || raise(ArgumentError, "Missing Params: `license_keys`")
20
+ @restful_client = opts[:restful_client] ? opts[:restful_client].new : ChefLicensing::RestfulClient::V1.new
21
+ end
22
+
23
+ def list
24
+ response_data = get_describe_api_response_data
25
+
26
+ list_of_licenses = []
27
+
28
+ response_data.license.each do |license|
29
+ # license object created to be fed to parser
30
+ license_object = OpenStruct.new({
31
+ "license" => license,
32
+ "assets" => response_data.Assets,
33
+ "features" => response_data.Features,
34
+ "software" => response_data.Software,
35
+ })
36
+
37
+ list_of_licenses << ChefLicensing::License.new(
38
+ data: license_object,
39
+ product_name: ChefLicensing::Config.chef_product_name,
40
+ api_parser: ChefLicensing::Api::Parser::Describe
41
+ )
42
+ end
43
+ # returns list of license data model object
44
+ list_of_licenses
45
+ end
46
+
47
+ private
48
+
49
+ attr_reader :restful_client
50
+
51
+ def get_describe_api_response_data
52
+ response = restful_client.describe(license_keys: license_keys.join(","), entitlement_id: ChefLicensing::Config.chef_entitlement_id)
53
+
54
+ raise(ChefLicensing::DescribeError, response.message) unless response.data
55
+
56
+ raise(ChefLicensing::DescribeError, "No license details found for the given license keys") unless response.data&.license.is_a?(Array) || response.data.license&.any?
57
+
58
+ response.data
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,55 @@
1
+ require_relative "../restful_client/v1"
2
+
3
+ module ChefLicensing
4
+ module Api
5
+ class LicenseFeatureEntitlement
6
+ attr_reader :license_keys
7
+
8
+ class << self
9
+ def check_entitlement!(license_keys: [], feature_name: nil, feature_id: nil)
10
+ new(license_keys: license_keys, feature_name: feature_name , feature_id: feature_id).check_entitlement!
11
+ end
12
+ end
13
+
14
+ def initialize(license_keys: [], feature_name: nil, feature_id: nil, restful_client: ChefLicensing::RestfulClient::V1)
15
+ license_keys || raise(ArgumentError, "Missing Params: `license_keys`")
16
+ @license_keys = license_keys.is_a?(Array) ? license_keys : [license_keys]
17
+ @feature_name = feature_name
18
+ @feature_id = feature_id
19
+ raise ArgumentError, "Either of `feature_id` or `feature_name` should be provided" if feature_name.nil? && feature_id.nil?
20
+
21
+ @restful_client = restful_client.new
22
+ end
23
+
24
+ def check_entitlement!
25
+ response = make_request
26
+ response.data.entitled || raise(ChefLicensing::FeatureNotEntitled)
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :restful_client, :feature_id, :feature_name
32
+
33
+ def make_request
34
+ payload = build_payload
35
+ if feature_name
36
+ restful_client.feature_by_name(payload)
37
+ else
38
+ restful_client.feature_by_id(payload)
39
+ end
40
+ end
41
+
42
+ def build_payload
43
+ {
44
+ licenseIds: license_keys,
45
+ }.tap do |payload|
46
+ if feature_name
47
+ payload[:featureName] = feature_name
48
+ else
49
+ payload[:featureGuid] = feature_id
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,53 @@
1
+ require_relative "../restful_client/v1"
2
+
3
+ module ChefLicensing
4
+ module Api
5
+ class LicenseSoftwareEntitlement
6
+ attr_reader :license_keys
7
+
8
+ def self.check!(license_keys: [], software_entitlement_name: nil, software_entitlement_id: nil)
9
+ new(license_keys: license_keys, software_entitlement_name: software_entitlement_name, software_entitlement_id: software_entitlement_id).check!
10
+ end
11
+
12
+ def initialize(license_keys: [], software_entitlement_name: nil, software_entitlement_id: nil, restful_client: ChefLicensing::RestfulClient::V1)
13
+ @license_keys = license_keys
14
+ @entitlement_id = software_entitlement_id
15
+ @entitlement_name = software_entitlement_name
16
+
17
+ raise ArgumentError, "Either of `software_entitlement_id` or `software_entitlement_name` should be provided" if software_entitlement_name.nil? && software_entitlement_id.nil?
18
+
19
+ @restful_client = restful_client.new
20
+ end
21
+
22
+ def check!
23
+ response = make_request
24
+ response.data.entitled || raise(ChefLicensing::SoftwareNotEntitled)
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :restful_client, :entitlement_id, :entitlement_name
30
+
31
+ def make_request
32
+ payload = build_payload
33
+ if entitlement_name
34
+ restful_client.entitlement_by_name(payload)
35
+ else
36
+ restful_client.entitlement_by_id(payload)
37
+ end
38
+ end
39
+
40
+ def build_payload
41
+ {
42
+ licenseIds: license_keys,
43
+ }.tap do |payload|
44
+ if entitlement_name
45
+ payload[:entitlementName] = entitlement_name
46
+ else
47
+ payload[:entitlementGuid] = entitlement_id
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,30 @@
1
+ require_relative "../restful_client/v1"
2
+ require_relative "../exceptions/list_licenses_error"
3
+ require_relative "../config"
4
+
5
+ module ChefLicensing
6
+ module Api
7
+ class ListLicenses
8
+ class << self
9
+ def info(opts = {})
10
+ new(opts).info
11
+ end
12
+ end
13
+
14
+ def initialize(opts = {})
15
+ @restful_client = opts[:restful_client] ? opts[:restful_client].new : ChefLicensing::RestfulClient::V1.new
16
+ end
17
+
18
+ def info
19
+ response = restful_client.list_licenses
20
+ raise ChefLicensing::ListLicensesError.new(response.message, response.status_code) unless response.status_code == 200 && response.data
21
+
22
+ response.data
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :restful_client
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,100 @@
1
+ require "ostruct" unless defined?(OpenStruct)
2
+ module ChefLicensing
3
+ module Api
4
+ module Parser
5
+ class Client
6
+
7
+ # Uses response from /client API
8
+ # This parser formats the response which will enable creation of license data object.
9
+
10
+ attr_reader :data, :client_data
11
+
12
+ def initialize(data)
13
+ # API call response
14
+ @data = data
15
+ @client_data = data.client || OpenStruct.new({})
16
+ end
17
+
18
+ def parse_id
19
+ nil
20
+ end
21
+
22
+ def parse_license_type
23
+ client_data.license
24
+ end
25
+
26
+ def parse_status
27
+ client_data.status
28
+ end
29
+
30
+ # Parse expiration details
31
+
32
+ def parse_expiration_date
33
+ client_data.changesOn
34
+ end
35
+
36
+ def parse_license_expiration_status
37
+ client_data.changesTo
38
+ end
39
+
40
+ # Parse usage details
41
+ def parse_limits
42
+ if data.client.nil? || data.client.empty?
43
+ []
44
+ else
45
+ [{
46
+ "usage_status" => client_data.usage,
47
+ "usage_limit" => client_data.limit,
48
+ "usage_measure" => client_data.measure,
49
+ "used" => client_data.used,
50
+ }]
51
+ end
52
+ end
53
+
54
+ # Parse entitlements
55
+
56
+ def parse_feature_entitlements
57
+ features = []
58
+ features_data = data.features || []
59
+ features_data.each do |feature|
60
+ feature_info = {
61
+ "id" => feature.id,
62
+ "name" => feature.name,
63
+ }
64
+ features << feature_info
65
+ end
66
+ features
67
+ end
68
+
69
+ def parse_software_entitlements
70
+ if data.entitlement.nil? || data.entitlement.empty?
71
+ []
72
+ else
73
+ require "date"
74
+ entitlement_status = (data.entitlement.end >= Date.today.to_s) ? "Active" : "Expired"
75
+ # sending status based on end date
76
+ [{
77
+ "id" => data.entitlement.id,
78
+ "name" => data.entitlement.name,
79
+ "entitled" => data.entitlement.entitled,
80
+ "status" => entitlement_status,
81
+ }]
82
+ end
83
+ end
84
+
85
+ def parse_asset_entitlements
86
+ assets = []
87
+ assets_data = data.assets || []
88
+ assets_data.each do |asset|
89
+ asset_info = {
90
+ "id" => asset.id,
91
+ "name" => asset.name,
92
+ }
93
+ assets << asset_info
94
+ end
95
+ assets
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,118 @@
1
+ require "ostruct" unless defined?(OpenStruct)
2
+ module ChefLicensing
3
+ module Api
4
+ module Parser
5
+ class Describe
6
+
7
+ # Uses response from /describe API
8
+ # This parser formats the response which will enable creation of license data object.
9
+
10
+ attr_reader :data, :license_data
11
+
12
+ def initialize(data)
13
+ @data = data
14
+ @license_data = data.license || OpenStruct.new({})
15
+ end
16
+
17
+ def parse_id
18
+ license_data.licenseKey
19
+ end
20
+
21
+ def parse_license_type
22
+ license_data.licenseType
23
+ end
24
+
25
+ def parse_status
26
+ license_data.status
27
+ end
28
+
29
+ # Parse expiration details
30
+
31
+ def parse_expiration_date
32
+ license_data.end
33
+ end
34
+
35
+ def parse_license_expiration_status
36
+ nil
37
+ end
38
+
39
+ # Parse usage details
40
+
41
+ def parse_limits
42
+ limits = []
43
+ limits_data = license_data.limits || []
44
+ limits_data.each do |limit|
45
+ limit_details = {
46
+ "usage_status" => limit.status,
47
+ "usage_limit" => limit.amount,
48
+ "usage_measure" => limit.measure,
49
+ "used" => limit.used,
50
+ "software" => limit.software,
51
+ }
52
+ limits << limit_details
53
+ end
54
+ limits
55
+ end
56
+
57
+ # Parse entitlements
58
+
59
+ def parse_feature_entitlements
60
+ features = []
61
+ features_data = data.features || []
62
+ features_data.each do |feature|
63
+ feature.from.each do |from_info|
64
+ if from_info.license == parse_id
65
+ feature_details = {
66
+ "status" => from_info.status,
67
+ "entitled" => feature.entitled,
68
+ "id" => feature.id,
69
+ "name" => feature.name,
70
+ }
71
+ features << feature_details
72
+ end
73
+ end
74
+ end
75
+ features
76
+ end
77
+
78
+ def parse_software_entitlements
79
+ softwares = []
80
+ softwares_data = data.software || []
81
+ softwares_data.select do |software|
82
+ software.from.each do |from_info|
83
+ if from_info.license == parse_id
84
+ software_details = {
85
+ "status" => from_info.status,
86
+ "entitled" => software.entitled,
87
+ "id" => software.id,
88
+ "name" => software.name,
89
+ }
90
+ softwares << software_details
91
+ end
92
+ end
93
+ end
94
+ softwares
95
+ end
96
+
97
+ def parse_asset_entitlements
98
+ assets = []
99
+ assets_data = data.assets || []
100
+ assets_data.select do |asset|
101
+ asset.from.each do |from_info|
102
+ if from_info.license == parse_id
103
+ asset_details = {
104
+ "status" => from_info.status,
105
+ "entitled" => asset.entitled,
106
+ "id" => asset.id,
107
+ "name" => asset.name,
108
+ }
109
+ assets << asset_details
110
+ end
111
+ end
112
+ end
113
+ assets
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,28 @@
1
+ begin
2
+ require "mixlib/cli" unless defined?(Mixlib::CLI)
3
+ rescue
4
+ raise "Must have mixlib-cli gem installed to use this mixin"
5
+ end
6
+
7
+ module ChefLicensing
8
+ module CLIFlags
9
+
10
+ module MixlibCLI
11
+
12
+ def self.included(klass)
13
+ # TBD need to confirm the name of the option
14
+ klass.option :chef_license_key,
15
+ long: "--chef-license-key KEY",
16
+ description: "Add a new Chef License Key to the license store. Ignores duplicates (not applicable to local licensing service)",
17
+ required: false
18
+
19
+ klass.option :chef_license_server,
20
+ long: "--chef-license-server URL",
21
+ description: "Add a custom Chef License Server URL. Overrides the global license server URL.",
22
+ required: false
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ begin
2
+ require "thor" unless defined?(Thor)
3
+ rescue
4
+ raise "Must have thor gem installed to use this mixin"
5
+ end
6
+
7
+ module ChefLicensing
8
+ module CLIFlags
9
+ module Thor
10
+ def self.included(klass)
11
+ # TBD need to confirm the name of the option
12
+ klass.class_option :chef_license_key,
13
+ type: :string,
14
+ desc: "Add a new Chef License Key to the license store. Ignores duplicates (not applicable to local licensing service)"
15
+ klass.class_option :chef_license_server,
16
+ type: :string,
17
+ desc: "Add a custom Chef License Server URL. Overrides the global license server URL."
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,44 @@
1
+ require "singleton" unless defined?(Singleton)
2
+ require "logger"
3
+ require_relative "config_fetcher/arg_fetcher"
4
+ require_relative "config_fetcher/env_fetcher"
5
+ require_relative "license_key_fetcher/file"
6
+
7
+ # Config class handles all configuration related to chef-licensing
8
+ # Values can be set via block, environment variable or command line argument
9
+
10
+ # Licensing service detection
11
+ require_relative "licensing_service/local"
12
+
13
+ module ChefLicensing
14
+ class Config
15
+ class << self
16
+ attr_writer :license_server_url, :logger, :output, :license_server_url_check_in_file
17
+
18
+ # is_local_license_service is used by context class
19
+ attr_accessor :is_local_license_service, :chef_entitlement_id, :chef_product_name, :chef_executable_name
20
+
21
+ def license_server_url(opts = {})
22
+ return @license_server_url if @license_server_url && @license_server_url_check_in_file
23
+
24
+ license_server_url_from_system = ChefLicensing::ArgFetcher.fetch_value("--chef-license-server", :string) || ChefLicensing::EnvFetcher.fetch_value("CHEF_LICENSE_SERVER", :string)
25
+
26
+ @license_server_url = ChefLicensing::LicenseKeyFetcher::File.fetch_or_persist_url(@license_server_url, license_server_url_from_system, opts)
27
+ @license_server_url_check_in_file = true
28
+ @license_server_url
29
+ end
30
+
31
+ def logger
32
+ return @logger if @logger
33
+
34
+ @logger = Logger.new(STDERR)
35
+ @logger.level = Logger::INFO
36
+ @logger
37
+ end
38
+
39
+ def output
40
+ @output ||= STDOUT
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,38 @@
1
+ module ChefLicensing
2
+ class ArgFetcher
3
+
4
+ def initialize(argv = ARGV)
5
+ @argv = argv
6
+ end
7
+
8
+ def fetch_value(arg_name, arg_type = :string)
9
+ case arg_type
10
+ when :boolean
11
+ @argv.include?(arg_name)
12
+ when :string
13
+ # TODO: Refactor this code to use some library in near future
14
+ # There were some issues with OptionParser, so we are using this
15
+ # custom code for now.
16
+
17
+ # Currently, we are supporting two ways of passing arguments:
18
+ # 1. --chef-license-server foo
19
+ # 2. --chef-license-server=foo
20
+
21
+ # Check if argument is passed as: --chef-license-server foo
22
+ arg_value = @argv.include?(arg_name) ? @argv[@argv.index(arg_name) + 1] : nil
23
+
24
+ # Check if argument is passed as: --chef-license-server=foo
25
+ # only if arg_value is nil
26
+ if arg_value.nil?
27
+ arg_value = @argv.select { |arg| arg.start_with?("#{arg_name}=") }.first
28
+ arg_value = arg_value.split("=").last if arg_value
29
+ end
30
+ arg_value
31
+ end
32
+ end
33
+
34
+ def self.fetch_value(arg_name, arg_type = :string)
35
+ new.fetch_value(arg_name, arg_type)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ module ChefLicensing
2
+ class EnvFetcher
3
+
4
+ def initialize(env = ENV)
5
+ @env = env
6
+ end
7
+
8
+ def fetch_value(env_name, env_type = :string)
9
+ case env_type
10
+ when :boolean
11
+ @env.key?(env_name)
12
+ when :string
13
+ @env.fetch(env_name, nil)
14
+ end
15
+ end
16
+
17
+ def self.fetch_value(env_name, env_type = :string)
18
+ new.fetch_value(env_name, env_type)
19
+ end
20
+ end
21
+ end