chef-licensing 0.4.44 → 1.0.0

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 (27) hide show
  1. checksums.yaml +4 -4
  2. data/chef-licensing.gemspec +6 -3
  3. data/lib/chef-licensing/config.rb +9 -1
  4. data/lib/chef-licensing/context.rb +36 -1
  5. data/lib/chef-licensing/exceptions/invalid_file_format_version.rb +10 -0
  6. data/lib/chef-licensing/exceptions/license_file_corrupted.rb +9 -0
  7. data/lib/chef-licensing/exceptions/unsupported_content_type.rb +9 -0
  8. data/lib/chef-licensing/license.rb +5 -1
  9. data/lib/chef-licensing/license_key_fetcher/chef_licensing_interactions.yaml +85 -234
  10. data/lib/chef-licensing/license_key_fetcher/file.rb +71 -14
  11. data/lib/chef-licensing/license_key_fetcher/license_file/base.rb +63 -0
  12. data/lib/chef-licensing/license_key_fetcher/license_file/v3.rb +12 -0
  13. data/lib/chef-licensing/license_key_fetcher/license_file/v4.rb +27 -0
  14. data/lib/chef-licensing/license_key_fetcher.rb +45 -20
  15. data/lib/chef-licensing/list_license_keys.rb +9 -3
  16. data/lib/chef-licensing/restful_client/base.rb +62 -26
  17. data/lib/chef-licensing/restful_client/middleware/content_type_validator.rb +24 -0
  18. data/lib/chef-licensing/restful_client/middleware/exceptions_handler.rb +1 -3
  19. data/lib/chef-licensing/restful_client/v1.rb +0 -2
  20. data/lib/chef-licensing/tui_engine/tui_actions.rb +11 -88
  21. data/lib/chef-licensing/version.rb +1 -1
  22. data/lib/chef-licensing.rb +5 -0
  23. metadata +16 -13
  24. data/LICENSE +0 -1
  25. data/lib/chef-licensing/exceptions/license_generation_failed.rb +0 -9
  26. data/lib/chef-licensing/exceptions/license_generation_rejected.rb +0 -7
  27. data/lib/chef-licensing/license_key_generator.rb +0 -47
@@ -1,8 +1,5 @@
1
1
  require_relative "../license_key_validator"
2
- require_relative "../license_key_generator"
3
2
  require_relative "../exceptions/invalid_license"
4
- require_relative "../exceptions/license_generation_failed"
5
- require_relative "../exceptions/license_generation_rejected"
6
3
  require_relative "../license_key_fetcher/base"
7
4
  require_relative "../config"
8
5
  require_relative "../context"
@@ -46,9 +43,12 @@ module ChefLicensing
46
43
  def is_license_allowed?(input)
47
44
  client_api_call(license_id)
48
45
  self.license_type = get_license_type
46
+ # When user enters the license via TUI, we need to check if the license type is commercial to display warnings.
47
+ input[:is_commercial] = license_type == :commercial ? true : false
48
+ input[:license_type] = license_type
49
49
  if license_restricted?(license_type)
50
50
  # Existing license keys needs to be fetcher to show details of existing license of license type which is restricted.
51
- # However, if user is trying to add free license, and user has active trial license, we fetch the trial license key
51
+ # However, if user is trying to add Free Tier License, and user has active trial license, we fetch the trial license key
52
52
  if license_type == :free && LicenseKeyFetcher::File.user_has_active_trial_license?(@opts)
53
53
  existing_license_keys_in_file = LicenseKeyFetcher::File.fetch_license_keys_based_on_type(:trial, @opts)
54
54
  else
@@ -69,65 +69,24 @@ module ChefLicensing
69
69
  input[:license_expiration_date] = Date.parse(license.expiration_date).strftime("%a, %d %b %Y")
70
70
  input[:number_of_days_in_expiration] = license.number_of_days_in_expiration
71
71
  "about_to_expire"
72
+ elsif license.exhausted? && (license.license_type.downcase == "commercial" || license.license_type.downcase == "free")
73
+ input[:license_type] = license.license_type
74
+ "exhausted_license"
72
75
  else
73
76
  "active"
74
77
  end
75
78
  end
76
79
 
77
- def is_user_name_valid?(input)
78
- user_name = input[:gather_user_last_name_for_license_generation] || input[:gather_user_first_name_for_license_generation]
79
- (user_name =~ /\A[a-zA-Z]{1,16}\Z/) == 0
80
- end
81
-
82
- def is_email_valid?(input)
83
- (input[:gather_user_email_for_license_generation] =~ URI::MailTo::EMAIL_REGEXP) == 0
84
- end
85
-
86
- def is_company_name_valid?(input)
87
- (input[:gather_user_company_for_license_generation] =~ /\A[a-zA-Z0-9][a-zA-Z0-9\W_]{2,15}\z/) == 0
88
- end
89
-
90
- def is_phone_no_valid?(input)
91
- # No validation
92
- # Optional field
93
- true
94
- end
95
-
96
- def generate_trial_license(input)
97
- generate_license(input, :trial)
98
- end
99
-
100
- def generate_free_license(input)
101
- generate_license(input, :free)
80
+ def is_run_allowed_on_license_exhausted?(input)
81
+ input[:license_type].downcase == "commercial"
102
82
  end
103
83
 
104
84
  def fetch_license_id(input)
105
85
  license_id
106
86
  end
107
87
 
108
- def fetch_license_failure_error_msg(input)
109
- error_msg
110
- end
111
-
112
- def fetch_license_failure_rejection_msg(input)
113
- rejection_msg
114
- end
115
-
116
- def select_license_generation_based_on_type(inputs)
117
- if inputs.key? :free_license_selection
118
- inputs[:license_type] = :free
119
- "free"
120
- elsif inputs.key? :trial_license_selection
121
- inputs[:license_type] = :trial
122
- "trial"
123
- else
124
- inputs[:license_type] = :commercial
125
- "commercial"
126
- end
127
- end
128
-
129
- def license_generation_rejected?(inputs)
130
- !!rejection_msg
88
+ def is_commercial_license?(input)
89
+ input[:is_commercial]
131
90
  end
132
91
 
133
92
  def fetch_invalid_license_msg(input)
@@ -138,20 +97,6 @@ module ChefLicensing
138
97
  ChefLicensing::ListLicenseKeys.display_overview({ license_keys: [license_id] })
139
98
  end
140
99
 
141
- def clear_license_type_selection(inputs)
142
- inputs.delete(:free_license_selection)
143
- inputs.delete(:trial_license_selection)
144
- inputs.delete(:commercial_license_selection)
145
- end
146
-
147
- def are_user_details_present?(inputs)
148
- inputs.key?(:gather_user_first_name_for_license_generation) &&
149
- inputs.key?(:gather_user_last_name_for_license_generation) &&
150
- inputs.key?(:gather_user_email_for_license_generation) &&
151
- inputs.key?(:gather_user_company_for_license_generation) &&
152
- inputs.key?(:gather_user_phone_no_for_license_generation)
153
- end
154
-
155
100
  def set_license_info(input)
156
101
  self.license_id = input[:license_id]
157
102
  self.license_type = input[:license_type]
@@ -191,28 +136,6 @@ module ChefLicensing
191
136
 
192
137
  attr_accessor :opts
193
138
 
194
- def generate_license(inputs, license_type)
195
- spinner = TTY::Spinner.new(":spinner [Running] License generation in progress...", format: :dots, clear: true, output: output)
196
- spinner.auto_spin # Start the spinner
197
- self.license_id = ChefLicensing::LicenseKeyGenerator.send("generate_#{license_type}_license!",
198
- first_name: inputs[:gather_user_first_name_for_license_generation],
199
- last_name: inputs[:gather_user_last_name_for_license_generation],
200
- email_id: inputs[:gather_user_email_for_license_generation],
201
- product: ChefLicensing::Config.chef_product_name&.capitalize,
202
- company: inputs[:gather_user_company_for_license_generation],
203
- phone: inputs[:gather_user_phone_no_for_license_generation])
204
- spinner.success # Stop the spinner
205
- true
206
- rescue ChefLicensing::LicenseGenerationFailed => e
207
- spinner.error # Stop the spinner
208
- self.error_msg = e.message
209
- false
210
- rescue ChefLicensing::LicenseGenerationRejected => e
211
- spinner.error # Stop the spinner
212
- self.rejection_msg = e.message
213
- false
214
- end
215
-
216
139
  def get_license(license_key)
217
140
  spinner = TTY::Spinner.new(":spinner [Running] License validation in progress...", format: :dots, clear: true, output: output)
218
141
  spinner.auto_spin # Start the spinner
@@ -1,3 +1,3 @@
1
1
  module ChefLicensing
2
- VERSION = "0.4.44".freeze
2
+ VERSION = "1.0.0".freeze
3
3
  end
@@ -8,6 +8,7 @@ require "chef-licensing/exceptions/software_not_entitled"
8
8
  require "chef-licensing/exceptions/client_error"
9
9
  require "chef-licensing/api/client"
10
10
  require "chef-licensing/license_key_fetcher/prompt"
11
+ require "chef-licensing/context"
11
12
 
12
13
  module ChefLicensing
13
14
  class << self
@@ -66,5 +67,9 @@ module ChefLicensing
66
67
  def add_license
67
68
  ChefLicensing::LicenseKeyFetcher.add_license
68
69
  end
70
+
71
+ def license_context
72
+ ChefLicensing::Context.license
73
+ end
69
74
  end
70
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-licensing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.44
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Inspec Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-11 00:00:00.000000000 Z
11
+ date: 2024-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-config
@@ -79,9 +79,9 @@ dependencies:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
81
  version: '7.0'
82
- - - ">="
82
+ - - "<"
83
83
  - !ruby/object:Gem::Version
84
- version: 7.0.4.2
84
+ version: '7.1'
85
85
  type: :runtime
86
86
  prerelease: false
87
87
  version_requirements: !ruby/object:Gem::Requirement
@@ -89,9 +89,9 @@ dependencies:
89
89
  - - "~>"
90
90
  - !ruby/object:Gem::Version
91
91
  version: '7.0'
92
- - - ">="
92
+ - - "<"
93
93
  - !ruby/object:Gem::Version
94
- version: 7.0.4.2
94
+ version: '7.1'
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: tty-spinner
97
97
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +114,6 @@ executables: []
114
114
  extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
- - LICENSE
118
117
  - chef-licensing.gemspec
119
118
  - lib/chef-licensing.rb
120
119
  - lib/chef-licensing/api/client.rb
@@ -134,25 +133,29 @@ files:
134
133
  - lib/chef-licensing/exceptions/describe_error.rb
135
134
  - lib/chef-licensing/exceptions/error.rb
136
135
  - lib/chef-licensing/exceptions/feature_not_entitled.rb
136
+ - lib/chef-licensing/exceptions/invalid_file_format_version.rb
137
137
  - lib/chef-licensing/exceptions/invalid_license.rb
138
- - lib/chef-licensing/exceptions/license_generation_failed.rb
139
- - lib/chef-licensing/exceptions/license_generation_rejected.rb
138
+ - lib/chef-licensing/exceptions/license_file_corrupted.rb
140
139
  - lib/chef-licensing/exceptions/list_licenses_error.rb
141
140
  - lib/chef-licensing/exceptions/missing_api_credentials_error.rb
142
141
  - lib/chef-licensing/exceptions/restful_client_connection_error.rb
143
142
  - lib/chef-licensing/exceptions/restful_client_error.rb
144
143
  - lib/chef-licensing/exceptions/software_not_entitled.rb
144
+ - lib/chef-licensing/exceptions/unsupported_content_type.rb
145
145
  - lib/chef-licensing/license.rb
146
146
  - lib/chef-licensing/license_key_fetcher.rb
147
147
  - lib/chef-licensing/license_key_fetcher/base.rb
148
148
  - lib/chef-licensing/license_key_fetcher/chef_licensing_interactions.yaml
149
149
  - lib/chef-licensing/license_key_fetcher/file.rb
150
+ - lib/chef-licensing/license_key_fetcher/license_file/base.rb
151
+ - lib/chef-licensing/license_key_fetcher/license_file/v3.rb
152
+ - lib/chef-licensing/license_key_fetcher/license_file/v4.rb
150
153
  - lib/chef-licensing/license_key_fetcher/prompt.rb
151
- - lib/chef-licensing/license_key_generator.rb
152
154
  - lib/chef-licensing/license_key_validator.rb
153
155
  - lib/chef-licensing/licensing_service/local.rb
154
156
  - lib/chef-licensing/list_license_keys.rb
155
157
  - lib/chef-licensing/restful_client/base.rb
158
+ - lib/chef-licensing/restful_client/middleware/content_type_validator.rb
156
159
  - lib/chef-licensing/restful_client/middleware/exceptions_handler.rb
157
160
  - lib/chef-licensing/restful_client/v1.rb
158
161
  - lib/chef-licensing/tui_engine.rb
@@ -165,7 +168,7 @@ files:
165
168
  - lib/chef-licensing/version.rb
166
169
  homepage: https://github.com/chef/chef-licensing
167
170
  licenses:
168
- - LicenseRef-LICENSE
171
+ - Apache-2.0
169
172
  metadata:
170
173
  homepage_uri: https://github.com/chef/chef-licensing
171
174
  source_code_uri: https://github.com/chef/chef-licensing
@@ -177,14 +180,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
180
  requirements:
178
181
  - - ">="
179
182
  - !ruby/object:Gem::Version
180
- version: 2.3.0
183
+ version: 3.1.0
181
184
  required_rubygems_version: !ruby/object:Gem::Requirement
182
185
  requirements:
183
186
  - - ">="
184
187
  - !ruby/object:Gem::Version
185
188
  version: '0'
186
189
  requirements: []
187
- rubygems_version: 3.1.4
190
+ rubygems_version: 3.2.3
188
191
  signing_key:
189
192
  specification_version: 4
190
193
  summary: Chef License storage, generation, and entitlement
data/LICENSE DELETED
@@ -1 +0,0 @@
1
- Proprietary code. All rights reserved.
@@ -1,9 +0,0 @@
1
- require_relative "error"
2
-
3
- module ChefLicensing
4
- class LicenseGenerationFailed < Error
5
- def message
6
- super || "License Generation Failed"
7
- end
8
- end
9
- end
@@ -1,7 +0,0 @@
1
- module ChefLicensing
2
- class LicenseGenerationRejected < Error
3
- def message
4
- super || "License Generation Rejected"
5
- end
6
- end
7
- end
@@ -1,47 +0,0 @@
1
- require_relative "restful_client/v1"
2
- require_relative "exceptions/license_generation_failed"
3
-
4
- module ChefLicensing
5
- class LicenseKeyGenerator
6
- attr_reader :payload
7
-
8
- class << self
9
- # @param [Hash] KWARGS keys accepted are [first_name, last_name, email_id, product, company, phone]
10
- def generate_trial_license!(kwargs)
11
- new(kwargs).generate_trial_license!
12
- end
13
-
14
- def generate_free_license!(kwargs)
15
- new(kwargs).generate_free_license!
16
- end
17
- end
18
-
19
- def initialize(kwargs, restful_client: ChefLicensing::RestfulClient::V1)
20
- # TODO: validate kwargs
21
- @payload = build_payload_from(kwargs)
22
- @restful_client = restful_client.new
23
- end
24
-
25
- def generate_trial_license!
26
- response = @restful_client.generate_trial_license(payload)
27
- # need some logic around delivery
28
- # how the delivery is decided?
29
- response.licenseId
30
- rescue RestfulClientError => e
31
- raise ChefLicensing::LicenseGenerationFailed, e.message
32
- end
33
-
34
- def generate_free_license!
35
- response = @restful_client.generate_free_license(payload)
36
- response.licenseId
37
- rescue RestfulClientError => e
38
- raise ChefLicensing::LicenseGenerationFailed, e.message
39
- end
40
-
41
- private
42
-
43
- def build_payload_from(kwargs)
44
- kwargs.slice(:first_name, :last_name, :email_id, :product, :company, :phone)
45
- end
46
- end
47
- end