gitlab-license 1.0.0 → 2.2.1

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
- SHA1:
3
- metadata.gz: e600286328afecad44667c1a380d86af1ca51fb2
4
- data.tar.gz: 311f32e1169d3c29420b20c44a0184ee3c6451e2
2
+ SHA256:
3
+ metadata.gz: e97f77de6b6b6e0b4910b0b892cc038dcf0c9103b65fc80a2fb27298a6be1140
4
+ data.tar.gz: 5c2a31361536c8a6eb4b87511ed41bdd889bf56239f28cdee43d2287c924b41e
5
5
  SHA512:
6
- metadata.gz: 9b2bce8a31af79ad4fe1cd51735b90ac3c33b847cd3ae6dc70de5ebdfe1c2b16e305dd8aa0e4e8688adba86a08190a53b12c152e8b0384b3a4121622439649c5
7
- data.tar.gz: 77a65ca5a2db684afb50bfa1d18c35470c702f53f2b7e11301a6d94597e657617faada7a7ea6c3c67e56be5243bb550916092545979be175fdf59b23c915c621
6
+ metadata.gz: f4724c22299fcfd99440b0f653db6cf58e884bdf52335733136793e716aaa830cc2c25a393d4d809af46e5f098c02b3432afaa4407180b523f9e8f2f400f35dc
7
+ data.tar.gz: 99989f3f28e4fd3c04b866780c5565458620dd9bb15ba6407cd41f586dae70b198271f66f7cb40853b026d8a02ca68c4db1f2a32eac14eb1e919a7c20fb0b5a8
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ require: rubocop-rspec
4
+
5
+ Metrics/BlockLength:
6
+ ExcludedMethods: ['describe', 'context']
7
+
8
+ Style/Alias:
9
+ EnforcedStyle: prefer_alias_method
10
+ Enabled: true
11
+
12
+ Style/HashEachMethods:
13
+ Enabled: true
14
+
15
+ Style/HashTransformKeys:
16
+ Enabled: true
17
+
18
+ Style/HashTransformValues:
19
+ Enabled: true
20
+
21
+ RSpec/MultipleExpectations:
22
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,84 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2020-03-02 14:37:54 -0500 using RuboCop version 0.80.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 6
10
+ Metrics/AbcSize:
11
+ Max: 36
12
+
13
+ # Offense count: 1
14
+ # Configuration parameters: CountComments.
15
+ Metrics/ClassLength:
16
+ Max: 129
17
+
18
+ # Offense count: 3
19
+ Metrics/CyclomaticComplexity:
20
+ Max: 16
21
+
22
+ # Offense count: 5
23
+ # Configuration parameters: CountComments, ExcludedMethods.
24
+ Metrics/MethodLength:
25
+ Max: 38
26
+
27
+ # Offense count: 3
28
+ Metrics/PerceivedComplexity:
29
+ Max: 16
30
+
31
+ # Offense count: 3
32
+ Style/Documentation:
33
+ Exclude:
34
+ - 'spec/**/*'
35
+ - 'test/**/*'
36
+ - 'lib/gitlab/license.rb'
37
+ - 'lib/gitlab/license/boundary.rb'
38
+ - 'lib/gitlab/license/encryptor.rb'
39
+
40
+ # Offense count: 12
41
+ # Cop supports --auto-correct.
42
+ # Configuration parameters: EnforcedStyle.
43
+ # SupportedStyles: always, always_true, never
44
+ Style/FrozenStringLiteralComment:
45
+ Exclude:
46
+ - 'Gemfile'
47
+ - 'Rakefile'
48
+ - 'bin/console'
49
+ - 'gitlab-license.gemspec'
50
+ - 'lib/gitlab/license.rb'
51
+ - 'lib/gitlab/license/boundary.rb'
52
+ - 'lib/gitlab/license/encryptor.rb'
53
+ - 'lib/gitlab/license/version.rb'
54
+ - 'spec/gitlab/license/boundary_spec.rb'
55
+ - 'spec/gitlab/license/encryptor_spec.rb'
56
+ - 'spec/gitlab/license_spec.rb'
57
+ - 'spec/spec_helper.rb'
58
+
59
+ # Offense count: 1
60
+ # Configuration parameters: MinBodyLength.
61
+ Style/GuardClause:
62
+ Exclude:
63
+ - 'lib/gitlab/license.rb'
64
+
65
+ # Offense count: 1
66
+ # Cop supports --auto-correct.
67
+ # Configuration parameters: EnforcedStyle.
68
+ # SupportedStyles: short, verbose
69
+ Style/PreferredHashMethods:
70
+ Exclude:
71
+ - 'lib/gitlab/license.rb'
72
+
73
+ # Offense count: 1
74
+ # Cop supports --auto-correct.
75
+ Style/RescueModifier:
76
+ Exclude:
77
+ - 'lib/gitlab/license.rb'
78
+
79
+ # Offense count: 14
80
+ # Cop supports --auto-correct.
81
+ # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
82
+ # URISchemes: http, https
83
+ Layout/LineLength:
84
+ Max: 104
data/README.md CHANGED
@@ -18,6 +18,17 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install gitlab-license
20
20
 
21
+ ## Release
22
+
23
+ To release a new version of this gem, follow these steps:
24
+
25
+ 1. Bump the `VERSION` constant in [`lib/gitlab/license/version.rb`](https://dev.gitlab.org/gitlab/gitlab-license/-/blob/master/lib/gitlab/license/version.rb#L3). This is typically merged as part of the feature MR.
26
+ 1. Create a [new release](https://dev.gitlab.org/gitlab/gitlab-license/-/releases) in the project (e.g. `v2.1.0`). For more details on creating a new release, refer to the [documentation](https://dev.gitlab.org/help/user/project/releases/index.md#create-a-release).
27
+ 1. [Build the gem](https://guides.rubygems.org/command-reference/#gem-build) to be published: `gem build gitlab-license.gemspec`
28
+ 1. [Publish the gem](https://guides.rubygems.org/publishing) to Rubygems: `gem push gitlab-license-2.1.0.gem`
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.
31
+
21
32
  ## Usage
22
33
 
23
34
  ```ruby
@@ -48,17 +59,17 @@ license.licensee = {
48
59
  "Email" => "douwe@gitlab.com"
49
60
  }
50
61
 
51
- # The date the license starts.
62
+ # The date the license starts.
52
63
  # Required.
53
64
  license.starts_at = Date.new(2015, 4, 24)
54
- # The date the license expires.
65
+ # The date the license expires.
55
66
  # Not required, to allow lifetime licenses.
56
67
  license.expires_at = Date.new(2016, 4, 23)
57
68
 
58
69
  # The below dates are hardcoded in the license so that you can play with the
59
70
  # period after which there are "repercussions" to license expiration.
60
71
 
61
- # The date admins will be notified about the license's pending expiration.
72
+ # The date admins will be notified about the license's pending expiration.
62
73
  # Not required.
63
74
  license.notify_admins_at = Date.new(2016, 4, 19)
64
75
 
@@ -66,7 +77,7 @@ license.notify_admins_at = Date.new(2016, 4, 19)
66
77
  # Not required.
67
78
  license.notify_users_at = Date.new(2016, 4, 23)
68
79
 
69
- # The date "changes" like code pushes, issue or merge request creation
80
+ # The date "changes" like code pushes, issue or merge request creation
70
81
  # or modification and project creation will be blocked.
71
82
  # Not required.
72
83
  license.block_changes_at = Date.new(2016, 5, 7)
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "gitlab/license"
3
+ require 'bundler/setup'
4
+ require 'gitlab/license'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "gitlab/license"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -1,24 +1,28 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'gitlab/license/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "gitlab-license"
6
+ spec.name = 'gitlab-license'
8
7
  spec.version = Gitlab::License::VERSION
9
- spec.authors = ["Douwe Maan"]
10
- spec.email = ["douwe@gitlab.com"]
8
+ spec.authors = ['Douwe Maan', 'Stan Hu', 'Tyler Amos']
9
+ spec.email = ['douwe@gitlab.com', 'stanhu@gitlab.com', 'tamos@gitlab.com']
11
10
 
12
- spec.summary = %q{gitlab-license helps you generate, verify and enforce software licenses.}
13
- spec.homepage = "https://gitlab.com/gitlab-org/gitlab-license"
14
- spec.license = "MIT"
11
+ spec.summary = 'gitlab-license helps you generate, verify and enforce software licenses.'
12
+ spec.homepage = 'https://dev.gitlab.org/gitlab/gitlab-license'
13
+ spec.license = 'MIT'
15
14
 
16
15
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.bindir = "exe"
16
+ spec.bindir = 'exe'
18
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
- spec.require_paths = ["lib"]
18
+ spec.require_paths = ['lib']
20
19
 
21
- spec.add_development_dependency "bundler", "~> 1.9"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "byebug"
20
+ spec.required_ruby_version = '>= 2.3.0'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.9'
23
+ spec.add_development_dependency 'byebug'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.9'
26
+ spec.add_development_dependency 'rubocop', '~> 0.80.1'
27
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.38.1'
24
28
  end
@@ -15,9 +15,9 @@ module Gitlab
15
15
 
16
16
  padding = total_padding / 2.0
17
17
  [
18
- "-" * padding.ceil,
18
+ '-' * padding.ceil,
19
19
  message,
20
- "-" * padding.floor
20
+ '-' * padding.floor
21
21
  ].join
22
22
  end
23
23
 
@@ -8,17 +8,13 @@ module Gitlab
8
8
  attr_accessor :key
9
9
 
10
10
  def initialize(key)
11
- if key && !key.is_a?(OpenSSL::PKey::RSA)
12
- raise KeyError, "No RSA encryption key provided."
13
- end
11
+ raise KeyError, 'No RSA encryption key provided.' if key && !key.is_a?(OpenSSL::PKey::RSA)
14
12
 
15
13
  @key = key
16
14
  end
17
15
 
18
16
  def encrypt(data)
19
- unless key.private?
20
- raise KeyError, "Provided key is not a private key."
21
- end
17
+ raise KeyError, 'Provided key is not a private key.' unless key.private?
22
18
 
23
19
  # Encrypt the data using symmetric AES encryption.
24
20
  cipher = OpenSSL::Cipher::AES128.new(:CBC)
@@ -29,12 +25,12 @@ module Gitlab
29
25
  encrypted_data = cipher.update(data) + cipher.final
30
26
 
31
27
  # Encrypt the AES key using asymmetric RSA encryption.
32
- encrypted_key = self.key.private_encrypt(aes_key)
28
+ encrypted_key = key.private_encrypt(aes_key)
33
29
 
34
30
  encryption_data = {
35
- "data" => Base64.encode64(encrypted_data),
36
- "key" => Base64.encode64(encrypted_key),
37
- "iv" => Base64.encode64(aes_iv)
31
+ 'data' => Base64.encode64(encrypted_data),
32
+ 'key' => Base64.encode64(encrypted_key),
33
+ 'iv' => Base64.encode64(aes_iv)
38
34
  }
39
35
 
40
36
  json_data = JSON.dump(encryption_data)
@@ -42,31 +38,29 @@ module Gitlab
42
38
  end
43
39
 
44
40
  def decrypt(data)
45
- unless key.public?
46
- raise KeyError, "Provided key is not a public key."
47
- end
41
+ raise KeyError, 'Provided key is not a public key.' unless key.public?
48
42
 
49
43
  json_data = Base64.decode64(data.chomp)
50
44
 
51
45
  begin
52
46
  encryption_data = JSON.parse(json_data)
53
47
  rescue JSON::ParserError
54
- raise DecryptionError, "Encryption data is invalid JSON."
48
+ raise DecryptionError, 'Encryption data is invalid JSON.'
55
49
  end
56
50
 
57
- unless %w(data key iv).all? { |key| encryption_data[key] }
58
- raise DecryptionError, "Required field missing from encryption data."
51
+ unless %w[data key iv].all? { |key| encryption_data[key] }
52
+ raise DecryptionError, 'Required field missing from encryption data.'
59
53
  end
60
54
 
61
- encrypted_data = Base64.decode64(encryption_data["data"])
62
- encrypted_key = Base64.decode64(encryption_data["key"])
63
- aes_iv = Base64.decode64(encryption_data["iv"])
55
+ encrypted_data = Base64.decode64(encryption_data['data'])
56
+ encrypted_key = Base64.decode64(encryption_data['key'])
57
+ aes_iv = Base64.decode64(encryption_data['iv'])
64
58
 
65
59
  begin
66
60
  # Decrypt the AES key using asymmetric RSA encryption.
67
61
  aes_key = self.key.public_decrypt(encrypted_key)
68
62
  rescue OpenSSL::PKey::RSAError
69
- raise DecryptionError, "AES encryption key could not be decrypted."
63
+ raise DecryptionError, 'AES encryption key could not be decrypted.'
70
64
  end
71
65
 
72
66
  # Decrypt the data using symmetric AES encryption.
@@ -74,21 +68,21 @@ module Gitlab
74
68
  cipher.decrypt
75
69
 
76
70
  begin
77
- cipher.key = aes_key
71
+ cipher.key = aes_key
78
72
  rescue OpenSSL::Cipher::CipherError
79
- raise DecryptionError, "AES encryption key is invalid."
73
+ raise DecryptionError, 'AES encryption key is invalid.'
80
74
  end
81
75
 
82
76
  begin
83
- cipher.iv = aes_iv
77
+ cipher.iv = aes_iv
84
78
  rescue OpenSSL::Cipher::CipherError
85
- raise DecryptionError, "AES IV is invalid."
79
+ raise DecryptionError, 'AES IV is invalid.'
86
80
  end
87
81
 
88
82
  begin
89
83
  data = cipher.update(encrypted_data) + cipher.final
90
84
  rescue OpenSSL::Cipher::CipherError
91
- raise DecryptionError, "Data could not be decrypted."
85
+ raise DecryptionError, 'Data could not be decrypted.'
92
86
  end
93
87
 
94
88
  data
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  class License
3
- VERSION = "1.0.0"
3
+ VERSION = '2.2.1'.freeze
4
4
  end
5
5
  end
@@ -1,11 +1,11 @@
1
- require "openssl"
2
- require "date"
3
- require "json"
4
- require "base64"
1
+ require 'openssl'
2
+ require 'date'
3
+ require 'json'
4
+ require 'base64'
5
5
 
6
- require "gitlab/license/version"
7
- require "gitlab/license/encryptor"
8
- require "gitlab/license/boundary"
6
+ require 'gitlab/license/version'
7
+ require 'gitlab/license/encryptor'
8
+ require 'gitlab/license/boundary'
9
9
 
10
10
  module Gitlab
11
11
  class License
@@ -18,35 +18,31 @@ module Gitlab
18
18
  @encryption_key = nil
19
19
 
20
20
  def encryption_key=(key)
21
- if key && !key.is_a?(OpenSSL::PKey::RSA)
22
- raise ArgumentError, "No RSA encryption key provided."
23
- end
21
+ raise ArgumentError, 'No RSA encryption key provided.' if key && !key.is_a?(OpenSSL::PKey::RSA)
24
22
 
25
23
  @encryption_key = key
26
24
  @encryptor = nil
27
25
  end
28
26
 
29
27
  def encryptor
30
- @encryptor ||= Encryptor.new(self.encryption_key)
28
+ @encryptor ||= Encryptor.new(encryption_key)
31
29
  end
32
30
 
33
31
  def import(data)
34
- if data.nil?
35
- raise ImportError, "No license data."
36
- end
32
+ raise ImportError, 'No license data.' if data.nil?
37
33
 
38
34
  data = Boundary.remove_boundary(data)
39
35
 
40
36
  begin
41
37
  license_json = encryptor.decrypt(data)
42
38
  rescue Encryptor::Error
43
- raise ImportError, "License data could not be decrypted."
39
+ raise ImportError, 'License data could not be decrypted.'
44
40
  end
45
41
 
46
42
  begin
47
43
  attributes = JSON.parse(license_json)
48
44
  rescue JSON::ParseError
49
- raise ImportError, "License data is invalid JSON."
45
+ raise ImportError, 'License data is invalid JSON.'
50
46
  end
51
47
 
52
48
  new(attributes)
@@ -54,9 +50,11 @@ module Gitlab
54
50
  end
55
51
 
56
52
  attr_reader :version
57
- attr_accessor :licensee, :starts_at, :expires_at
58
- attr_accessor :notify_admins_at, :notify_users_at, :block_changes_at
59
- attr_accessor :restrictions
53
+ attr_accessor :licensee, :starts_at, :expires_at, :notify_admins_at,
54
+ :notify_users_at, :block_changes_at, :last_synced_at, :next_sync_at,
55
+ :activated_at, :restrictions, :cloud_licensing_enabled,
56
+ :offline_cloud_licensing_enabled, :auto_renew_enabled, :seat_reconciliation_enabled,
57
+ :operational_metrics_enabled, :generated_from_customers_dot
60
58
 
61
59
  alias_method :issued_at, :starts_at
62
60
  alias_method :issued_at=, :starts_at=
@@ -66,51 +64,109 @@ module Gitlab
66
64
  end
67
65
 
68
66
  def valid?
69
- return false if !licensee || !licensee.is_a?(Hash) || licensee.length == 0
70
- return false if !starts_at || !starts_at.is_a?(Date)
71
- return false if expires_at && !expires_at.is_a?(Date)
72
- return false if notify_admins_at && !notify_admins_at.is_a?(Date)
73
- return false if notify_users_at && !notify_users_at.is_a?(Date)
74
- return false if block_changes_at && !block_changes_at.is_a?(Date)
75
- return false if restrictions && !restrictions.is_a?(Hash)
76
-
77
- true
67
+ if !licensee || !licensee.is_a?(Hash) || licensee.empty?
68
+ false
69
+ elsif !starts_at || !starts_at.is_a?(Date)
70
+ false
71
+ elsif !expires_at && !gl_team_license? && !jh_team_license?
72
+ false
73
+ elsif expires_at && !expires_at.is_a?(Date)
74
+ false
75
+ elsif notify_admins_at && !notify_admins_at.is_a?(Date)
76
+ false
77
+ elsif notify_users_at && !notify_users_at.is_a?(Date)
78
+ false
79
+ elsif block_changes_at && !block_changes_at.is_a?(Date)
80
+ false
81
+ elsif last_synced_at && !last_synced_at.is_a?(DateTime)
82
+ false
83
+ elsif next_sync_at && !next_sync_at.is_a?(DateTime)
84
+ false
85
+ elsif activated_at && !activated_at.is_a?(DateTime)
86
+ false
87
+ elsif restrictions && !restrictions.is_a?(Hash)
88
+ false
89
+ elsif !cloud_licensing? && offline_cloud_licensing?
90
+ false
91
+ else
92
+ true
93
+ end
78
94
  end
79
95
 
80
96
  def validate!
81
- raise ValidationError, "License is invalid" unless valid?
97
+ raise ValidationError, 'License is invalid' unless valid?
82
98
  end
83
99
 
84
100
  def will_expire?
85
- self.expires_at
101
+ expires_at
86
102
  end
87
103
 
88
104
  def will_notify_admins?
89
- self.notify_admins_at
105
+ notify_admins_at
90
106
  end
91
107
 
92
108
  def will_notify_users?
93
- self.notify_users_at
109
+ notify_users_at
94
110
  end
95
111
 
96
112
  def will_block_changes?
97
- self.block_changes_at
113
+ block_changes_at
114
+ end
115
+
116
+ def will_sync?
117
+ next_sync_at
118
+ end
119
+
120
+ def activated?
121
+ activated_at
98
122
  end
99
123
 
100
124
  def expired?
101
- will_expire? && Date.today >= self.expires_at
125
+ will_expire? && Date.today >= expires_at
102
126
  end
103
127
 
104
128
  def notify_admins?
105
- will_notify_admins? && Date.today >= self.notify_admins_at
129
+ will_notify_admins? && Date.today >= notify_admins_at
106
130
  end
107
131
 
108
132
  def notify_users?
109
- will_notify_users? && Date.today >= self.notify_users_at
133
+ will_notify_users? && Date.today >= notify_users_at
110
134
  end
111
135
 
112
136
  def block_changes?
113
- will_block_changes? && Date.today >= self.block_changes_at
137
+ will_block_changes? && Date.today >= block_changes_at
138
+ end
139
+
140
+ def cloud_licensing?
141
+ cloud_licensing_enabled == true
142
+ end
143
+
144
+ def offline_cloud_licensing?
145
+ offline_cloud_licensing_enabled == true
146
+ end
147
+
148
+ def auto_renew?
149
+ auto_renew_enabled == true
150
+ end
151
+
152
+ def seat_reconciliation?
153
+ seat_reconciliation_enabled == true
154
+ end
155
+
156
+ def operational_metrics?
157
+ operational_metrics_enabled == true
158
+ end
159
+
160
+ def generated_from_customers_dot?
161
+ generated_from_customers_dot == true
162
+ end
163
+
164
+ def gl_team_license?
165
+ licensee['Company'].to_s.match?(/GitLab/i) && licensee['Email'].to_s.end_with?('@gitlab.com')
166
+ end
167
+
168
+ def jh_team_license?
169
+ licensee['Company'].to_s.match?(/GitLab/i) && licensee['Email'].to_s.end_with?('@jihulab.com')
114
170
  end
115
171
 
116
172
  def restricted?(key = nil)
@@ -124,35 +180,45 @@ module Gitlab
124
180
  def attributes
125
181
  hash = {}
126
182
 
127
- hash["version"] = self.version
128
- hash["licensee"] = self.licensee
183
+ hash['version'] = version
184
+ hash['licensee'] = licensee
129
185
 
130
186
  # `issued_at` is the legacy name for starts_at.
131
187
  # TODO: Move to starts_at in a next version.
132
- hash["issued_at"] = self.starts_at
133
- hash["expires_at"] = self.expires_at if self.will_expire?
188
+ hash['issued_at'] = starts_at
189
+ hash['expires_at'] = expires_at if will_expire?
190
+
191
+ hash['notify_admins_at'] = notify_admins_at if will_notify_admins?
192
+ hash['notify_users_at'] = notify_users_at if will_notify_users?
193
+ hash['block_changes_at'] = block_changes_at if will_block_changes?
194
+
195
+ hash['next_sync_at'] = next_sync_at if will_sync?
196
+ hash['last_synced_at'] = last_synced_at if will_sync?
197
+ hash['activated_at'] = activated_at if activated?
134
198
 
135
- hash["notify_admins_at"] = self.notify_admins_at if self.will_notify_admins?
136
- hash["notify_users_at"] = self.notify_users_at if self.will_notify_users?
137
- hash["block_changes_at"] = self.block_changes_at if self.will_block_changes?
199
+ hash['cloud_licensing_enabled'] = cloud_licensing?
200
+ hash['offline_cloud_licensing_enabled'] = offline_cloud_licensing?
201
+ hash['auto_renew_enabled'] = auto_renew?
202
+ hash['seat_reconciliation_enabled'] = seat_reconciliation?
203
+ hash['operational_metrics_enabled'] = operational_metrics?
138
204
 
139
- hash["restrictions"] = self.restrictions if self.restricted?
205
+ hash['generated_from_customers_dot'] = generated_from_customers_dot?
206
+
207
+ hash['restrictions'] = restrictions if restricted?
140
208
 
141
209
  hash
142
210
  end
143
211
 
144
- def to_json
145
- JSON.dump(self.attributes)
212
+ def to_json(*_args)
213
+ JSON.dump(attributes)
146
214
  end
147
215
 
148
216
  def export(boundary: nil)
149
217
  validate!
150
218
 
151
- data = self.class.encryptor.encrypt(self.to_json)
219
+ data = self.class.encryptor.encrypt(to_json)
152
220
 
153
- if boundary
154
- data = Boundary.add_boundary(data, boundary)
155
- end
221
+ data = Boundary.add_boundary(data, boundary) if boundary
156
222
 
157
223
  data
158
224
  end
@@ -160,33 +226,53 @@ module Gitlab
160
226
  private
161
227
 
162
228
  def load_attributes(attributes)
163
- attributes = Hash[attributes.map { |k, v| [k.to_s, v] }]
229
+ attributes = attributes.transform_keys(&:to_s)
164
230
 
165
- version = attributes["version"] || 1
166
- unless version && version == 1
167
- raise ArgumentError, "Version is too new"
168
- end
231
+ version = attributes['version'] || 1
232
+ raise ArgumentError, 'Version is too new' unless version && version == 1
169
233
 
170
234
  @version = version
171
235
 
172
- @licensee = attributes["licensee"]
236
+ @licensee = attributes['licensee']
173
237
 
174
238
  # `issued_at` is the legacy name for starts_at.
175
239
  # TODO: Move to starts_at in a next version.
176
- %w(issued_at expires_at notify_admins_at notify_users_at block_changes_at).each do |attr|
177
- value = attributes[attr]
178
- value = Date.parse(value) rescue nil if value.is_a?(String)
240
+ %w[issued_at expires_at notify_admins_at notify_users_at block_changes_at].each do |attr_name|
241
+ set_date_attribute(attr_name, attributes[attr_name])
242
+ end
179
243
 
180
- next unless value
244
+ %w[last_synced_at next_sync_at activated_at].each do |attr_name|
245
+ set_datetime_attribute(attr_name, attributes[attr_name])
246
+ end
181
247
 
182
- send("#{attr}=", value)
248
+ %w[
249
+ cloud_licensing_enabled
250
+ offline_cloud_licensing_enabled
251
+ auto_renew_enabled
252
+ seat_reconciliation_enabled
253
+ operational_metrics_enabled
254
+ generated_from_customers_dot
255
+ ].each do |attr_name|
256
+ public_send("#{attr_name}=", attributes[attr_name] == true)
183
257
  end
184
258
 
185
- restrictions = attributes["restrictions"]
186
- if restrictions && restrictions.is_a?(Hash)
187
- restrictions = Hash[restrictions.map { |k, v| [k.to_sym, v] }]
259
+ restrictions = attributes['restrictions']
260
+ if restrictions&.is_a?(Hash)
261
+ restrictions = restrictions.transform_keys(&:to_sym)
188
262
  @restrictions = restrictions
189
263
  end
190
264
  end
265
+
266
+ def set_date_attribute(attr_name, value, date_class = Date)
267
+ value = date_class.parse(value) rescue nil if value.is_a?(String)
268
+
269
+ return unless value
270
+
271
+ public_send("#{attr_name}=", value)
272
+ end
273
+
274
+ def set_datetime_attribute(attr_name, value)
275
+ set_date_attribute(attr_name, value, DateTime)
276
+ end
191
277
  end
192
278
  end
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-license
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Douwe Maan
8
- autorequire:
8
+ - Stan Hu
9
+ - Tyler Amos
10
+ autorequire:
9
11
  bindir: exe
10
12
  cert_chain: []
11
- date: 2016-07-12 00:00:00.000000000 Z
13
+ date: 2022-08-04 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: bundler
@@ -24,6 +26,20 @@ dependencies:
24
26
  - - "~>"
25
27
  - !ruby/object:Gem::Version
26
28
  version: '1.9'
29
+ - !ruby/object:Gem::Dependency
30
+ name: byebug
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
27
43
  - !ruby/object:Gem::Dependency
28
44
  name: rake
29
45
  requirement: !ruby/object:Gem::Requirement
@@ -39,28 +55,60 @@ dependencies:
39
55
  - !ruby/object:Gem::Version
40
56
  version: '10.0'
41
57
  - !ruby/object:Gem::Dependency
42
- name: byebug
58
+ name: rspec
43
59
  requirement: !ruby/object:Gem::Requirement
44
60
  requirements:
45
- - - ">="
61
+ - - "~>"
46
62
  - !ruby/object:Gem::Version
47
- version: '0'
63
+ version: '3.9'
48
64
  type: :development
49
65
  prerelease: false
50
66
  version_requirements: !ruby/object:Gem::Requirement
51
67
  requirements:
52
- - - ">="
68
+ - - "~>"
53
69
  - !ruby/object:Gem::Version
54
- version: '0'
55
- description:
70
+ version: '3.9'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rubocop
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: 0.80.1
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: 0.80.1
85
+ - !ruby/object:Gem::Dependency
86
+ name: rubocop-rspec
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: 1.38.1
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: 1.38.1
99
+ description:
56
100
  email:
57
101
  - douwe@gitlab.com
102
+ - stanhu@gitlab.com
103
+ - tamos@gitlab.com
58
104
  executables: []
59
105
  extensions: []
60
106
  extra_rdoc_files: []
61
107
  files:
62
108
  - ".gitignore"
63
109
  - ".rspec"
110
+ - ".rubocop.yml"
111
+ - ".rubocop_todo.yml"
64
112
  - ".travis.yml"
65
113
  - Gemfile
66
114
  - LICENSE.txt
@@ -73,11 +121,11 @@ files:
73
121
  - lib/gitlab/license/boundary.rb
74
122
  - lib/gitlab/license/encryptor.rb
75
123
  - lib/gitlab/license/version.rb
76
- homepage: https://gitlab.com/gitlab-org/gitlab-license
124
+ homepage: https://dev.gitlab.org/gitlab/gitlab-license
77
125
  licenses:
78
126
  - MIT
79
127
  metadata: {}
80
- post_install_message:
128
+ post_install_message:
81
129
  rdoc_options: []
82
130
  require_paths:
83
131
  - lib
@@ -85,16 +133,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
133
  requirements:
86
134
  - - ">="
87
135
  - !ruby/object:Gem::Version
88
- version: '0'
136
+ version: 2.3.0
89
137
  required_rubygems_version: !ruby/object:Gem::Requirement
90
138
  requirements:
91
139
  - - ">="
92
140
  - !ruby/object:Gem::Version
93
141
  version: '0'
94
142
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 2.4.8
97
- signing_key:
143
+ rubygems_version: 3.2.33
144
+ signing_key:
98
145
  specification_version: 4
99
146
  summary: gitlab-license helps you generate, verify and enforce software licenses.
100
147
  test_files: []