gitlab-license 2.2.2 → 2.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a061df608a1fce9d44d099ca2ec27c78f57954560d014ea3810a6a104d84e76c
4
- data.tar.gz: fc39825338f1e87996be207d2d16c0ad0fe809217614b91edd10b3df0a102a13
3
+ metadata.gz: 22b0a5d5cec617462fad10a954e69a8ab0cbf2234c4c666b2bce3962387627b4
4
+ data.tar.gz: 5c74cb614cca7a0501188c219fa4dd716d6158fd79cae2a9aeef698d08d90ff9
5
5
  SHA512:
6
- metadata.gz: ef5ee9e933e196a77dee538f4222fe42eb9b68b5d8b6520e6a32e99fd5186eed592eef7062bfb55702e747b780488dfaf42d7f1e99ca6b8a6a7462c23fd9a7d8
7
- data.tar.gz: dbb5a8a59e70b4d315115a622118987c718e19f0df7686026cb43bbd189c3d22a98ed64b9f155d4c41f9e7bda656ccd306eb1060a39e72270993d390fbd329d4
6
+ metadata.gz: 8cbae440edf6fa10bb5944b63957e204e3fe6213d66d338b1cb7ce0428e2bdfc65a56b634a16c5832cd0039c568108a34c9f9c8b2da1f15e1427332355a2535a
7
+ data.tar.gz: ee7e2deda0d8f42d5453455a9d9d6d88f1b3a53d908f87323928151587a3640bdf3ad4fa7cb9d792639f88df00c0b934491d54e20233d0513b884135ea789ef1
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,25 @@
1
+ default:
2
+ image: "ruby:${RUBY_VERSION}"
3
+
4
+ cache:
5
+ key: "${CI_JOB_IMAGE}"
6
+ paths:
7
+ - vendor/ruby
8
+
9
+ before_script:
10
+ - ruby -v
11
+ - gem update --system --no-document
12
+ - bundle install -j $(nproc) --path vendor
13
+
14
+ test:
15
+ script:
16
+ - bundle exec rspec
17
+ parallel:
18
+ matrix:
19
+ - RUBY_VERSION: [ "3.0", "3.1", "3.2" ]
20
+
21
+ rubocop:
22
+ script:
23
+ - bundle exec rubocop
24
+ variables:
25
+ RUBY_VERSION: "3.0"
data/.rubocop.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
3
  require: rubocop-rspec
4
+ AllCops:
5
+ TargetRubyVersion: 2.7
4
6
 
5
7
  Metrics/BlockLength:
6
8
  ExcludedMethods: ['describe', 'context']
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-03-02 14:37:54 -0500 using RuboCop version 0.80.1.
3
+ # on 2023-12-21 18:05:17 -0500 using RuboCop version 0.80.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -8,25 +8,31 @@
8
8
 
9
9
  # Offense count: 6
10
10
  Metrics/AbcSize:
11
- Max: 36
11
+ Max: 60
12
+
13
+ # Offense count: 1
14
+ # Configuration parameters: CountComments, ExcludedMethods.
15
+ # ExcludedMethods: refine
16
+ Metrics/BlockLength:
17
+ Max: 26
12
18
 
13
19
  # Offense count: 1
14
20
  # Configuration parameters: CountComments.
15
21
  Metrics/ClassLength:
16
- Max: 129
22
+ Max: 223
17
23
 
18
24
  # Offense count: 3
19
25
  Metrics/CyclomaticComplexity:
20
- Max: 16
26
+ Max: 27
21
27
 
22
- # Offense count: 5
28
+ # Offense count: 6
23
29
  # Configuration parameters: CountComments, ExcludedMethods.
24
30
  Metrics/MethodLength:
25
- Max: 38
31
+ Max: 36
26
32
 
27
33
  # Offense count: 3
28
34
  Metrics/PerceivedComplexity:
29
- Max: 16
35
+ Max: 28
30
36
 
31
37
  # Offense count: 3
32
38
  Style/Documentation:
@@ -76,7 +82,7 @@ Style/RescueModifier:
76
82
  Exclude:
77
83
  - 'lib/gitlab/license.rb'
78
84
 
79
- # Offense count: 14
85
+ # Offense count: 28
80
86
  # Cop supports --auto-correct.
81
87
  # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
82
88
  # URISchemes: http, https
data/README.md CHANGED
@@ -27,7 +27,9 @@ To release a new version of this gem, follow these steps:
27
27
  1. [Build the gem](https://guides.rubygems.org/command-reference/#gem-build) to be published: `gem build gitlab-license.gemspec`
28
28
  1. [Publish the gem](https://guides.rubygems.org/publishing) to Rubygems: `gem push gitlab-license-2.1.0.gem`
29
29
  - Note you will need to be added as an owner in Rubygems in order to publish.
30
- - Once this is published, the new version of the gem can be installed in other projects like CustomersDot or GitLab via bundler or using `gem install` directly.
30
+ 1. Once published, the new version of the gem can be installed in projects that depend on `gitlab-license` like [CustomersDot](https://gitlab.com/gitlab-org/customers-gitlab-com) and [GitLab](https://gitlab.com/gitlab-org/gitlab).
31
+ - It is recommended to install the new version in both GitLab and CustomersDot to keep the versions aligned.
32
+ - This can be installed via bundler or using `gem install` directly.
31
33
 
32
34
  ## Usage
33
35
 
@@ -82,6 +84,10 @@ license.notify_users_at = Date.new(2016, 4, 23)
82
84
  # Not required.
83
85
  license.block_changes_at = Date.new(2016, 5, 7)
84
86
 
87
+ # If this license was created due to a subscription cancellation
88
+ # Not required.
89
+ license.generated_from_cancellation? = false
90
+
85
91
  # Restrictions bundled with this license.
86
92
  # Not required, to allow unlimited-user licenses for things like educational organizations.
87
93
  license.restrictions = {
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  class License
3
- VERSION = '2.2.2'.freeze
3
+ VERSION = '2.6.0'.freeze
4
4
  end
5
5
  end
@@ -8,13 +8,14 @@ require 'gitlab/license/encryptor'
8
8
  require 'gitlab/license/boundary'
9
9
 
10
10
  module Gitlab
11
- class License
11
+ class License # rubocop:disable Metrics/ClassLength
12
12
  class Error < StandardError; end
13
13
  class ImportError < Error; end
14
14
  class ValidationError < Error; end
15
15
 
16
16
  class << self
17
17
  attr_reader :encryption_key
18
+ attr_reader :fallback_decryption_keys
18
19
  @encryption_key = nil
19
20
 
20
21
  def encryption_key=(key)
@@ -24,6 +25,19 @@ module Gitlab
24
25
  @encryptor = nil
25
26
  end
26
27
 
28
+ def fallback_decryption_keys=(keys)
29
+ unless keys
30
+ @fallback_decryption_keys = nil
31
+ return
32
+ end
33
+
34
+ unless keys.is_a?(Enumerable) && keys.all? { |key| key.is_a?(OpenSSL::PKey::RSA) }
35
+ raise ArgumentError, 'Invalid fallback RSA encryption keys provided.'
36
+ end
37
+
38
+ @fallback_decryption_keys = Array(keys)
39
+ end
40
+
27
41
  def encryptor
28
42
  @encryptor ||= Encryptor.new(encryption_key)
29
43
  end
@@ -33,11 +47,7 @@ module Gitlab
33
47
 
34
48
  data = Boundary.remove_boundary(data)
35
49
 
36
- begin
37
- license_json = encryptor.decrypt(data)
38
- rescue Encryptor::Error
39
- raise ImportError, 'License data could not be decrypted.'
40
- end
50
+ license_json = decrypt_with_fallback_keys(data)
41
51
 
42
52
  begin
43
53
  attributes = JSON.parse(license_json)
@@ -47,6 +57,20 @@ module Gitlab
47
57
 
48
58
  new(attributes)
49
59
  end
60
+
61
+ def decrypt_with_fallback_keys(data)
62
+ keys_to_try = Array(encryption_key)
63
+ keys_to_try += fallback_decryption_keys if fallback_decryption_keys
64
+
65
+ keys_to_try.each do |decryption_key|
66
+ decryptor = Encryptor.new(decryption_key)
67
+ return decryptor.decrypt(data)
68
+ rescue Encryptor::Error
69
+ next
70
+ end
71
+
72
+ raise ImportError, 'License data could not be decrypted.'
73
+ end
50
74
  end
51
75
 
52
76
  attr_reader :version
@@ -54,7 +78,8 @@ module Gitlab
54
78
  :notify_users_at, :block_changes_at, :last_synced_at, :next_sync_at,
55
79
  :activated_at, :restrictions, :cloud_licensing_enabled,
56
80
  :offline_cloud_licensing_enabled, :auto_renew_enabled, :seat_reconciliation_enabled,
57
- :operational_metrics_enabled, :generated_from_customers_dot
81
+ :operational_metrics_enabled, :generated_from_customers_dot,
82
+ :generated_from_cancellation, :temporary_extension, :contract_overages_allowed
58
83
 
59
84
  alias_method :issued_at, :starts_at
60
85
  alias_method :issued_at=, :starts_at=
@@ -145,6 +170,10 @@ module Gitlab
145
170
  offline_cloud_licensing_enabled == true
146
171
  end
147
172
 
173
+ def contract_overages_allowed?
174
+ contract_overages_allowed == true
175
+ end
176
+
148
177
  def auto_renew?
149
178
  auto_renew_enabled == true
150
179
  end
@@ -161,6 +190,10 @@ module Gitlab
161
190
  generated_from_customers_dot == true
162
191
  end
163
192
 
193
+ def generated_from_cancellation?
194
+ generated_from_cancellation == true
195
+ end
196
+
164
197
  def gl_team_license?
165
198
  licensee['Company'].to_s.match?(/GitLab/i) && licensee['Email'].to_s.end_with?('@gitlab.com')
166
199
  end
@@ -169,6 +202,10 @@ module Gitlab
169
202
  licensee['Company'].to_s.match?(/GitLab/i) && licensee['Email'].to_s.end_with?('@jihulab.com')
170
203
  end
171
204
 
205
+ def temporary_extension?
206
+ temporary_extension == true
207
+ end
208
+
172
209
  def restricted?(key = nil)
173
210
  if key
174
211
  restricted? && restrictions.has_key?(key)
@@ -201,8 +238,12 @@ module Gitlab
201
238
  hash['auto_renew_enabled'] = auto_renew?
202
239
  hash['seat_reconciliation_enabled'] = seat_reconciliation?
203
240
  hash['operational_metrics_enabled'] = operational_metrics?
241
+ hash['contract_overages_allowed'] = contract_overages_allowed?
204
242
 
205
243
  hash['generated_from_customers_dot'] = generated_from_customers_dot?
244
+ hash['generated_from_cancellation'] = generated_from_cancellation?
245
+
246
+ hash['temporary_extension'] = temporary_extension?
206
247
 
207
248
  hash['restrictions'] = restrictions if restricted?
208
249
 
@@ -252,10 +293,14 @@ module Gitlab
252
293
  seat_reconciliation_enabled
253
294
  operational_metrics_enabled
254
295
  generated_from_customers_dot
296
+ generated_from_cancellation
297
+ temporary_extension
255
298
  ].each do |attr_name|
256
299
  public_send("#{attr_name}=", attributes[attr_name] == true)
257
300
  end
258
301
 
302
+ @contract_overages_allowed = attributes['contract_overages_allowed'] != false
303
+
259
304
  restrictions = attributes['restrictions']
260
305
  if restrictions&.is_a?(Hash)
261
306
  restrictions = restrictions.transform_keys(&:to_sym)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-license
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Douwe Maan
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2023-05-05 00:00:00.000000000 Z
13
+ date: 2024-11-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -106,6 +106,7 @@ extensions: []
106
106
  extra_rdoc_files: []
107
107
  files:
108
108
  - ".gitignore"
109
+ - ".gitlab-ci.yml"
109
110
  - ".rspec"
110
111
  - ".rubocop.yml"
111
112
  - ".rubocop_todo.yml"