Class: Gitlab::License
- Inherits:
-
Object
show all
- Defined in:
- lib/gitlab/license.rb,
lib/gitlab/license/version.rb,
lib/gitlab/license/boundary.rb,
lib/gitlab/license/encryptor.rb
Overview
rubocop:disable Metrics/ClassLength
Defined Under Namespace
Modules: Boundary
Classes: Encryptor, Error, ImportError, ValidationError
Constant Summary
collapse
- VERSION =
'2.6.0'.freeze
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = {}) ⇒ License
Returns a new instance of License.
87
88
89
|
# File 'lib/gitlab/license.rb', line 87
def initialize(attributes = {})
load_attributes(attributes)
end
|
Class Attribute Details
.encryption_key ⇒ Object
Returns the value of attribute encryption_key.
17
18
19
|
# File 'lib/gitlab/license.rb', line 17
def encryption_key
@encryption_key
end
|
.fallback_decryption_keys ⇒ Object
Returns the value of attribute fallback_decryption_keys.
18
19
20
|
# File 'lib/gitlab/license.rb', line 18
def fallback_decryption_keys
@fallback_decryption_keys
end
|
Instance Attribute Details
#activated_at ⇒ Object
Returns the value of attribute activated_at.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def activated_at
@activated_at
end
|
#auto_renew_enabled ⇒ Object
Returns the value of attribute auto_renew_enabled.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def auto_renew_enabled
@auto_renew_enabled
end
|
#block_changes_at ⇒ Object
Returns the value of attribute block_changes_at.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def block_changes_at
@block_changes_at
end
|
#cloud_licensing_enabled ⇒ Object
Returns the value of attribute cloud_licensing_enabled.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def cloud_licensing_enabled
@cloud_licensing_enabled
end
|
#contract_overages_allowed ⇒ Object
Returns the value of attribute contract_overages_allowed.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def contract_overages_allowed
@contract_overages_allowed
end
|
#expires_at ⇒ Object
Returns the value of attribute expires_at.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def expires_at
@expires_at
end
|
#generated_from_cancellation ⇒ Object
Returns the value of attribute generated_from_cancellation.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def generated_from_cancellation
@generated_from_cancellation
end
|
#generated_from_customers_dot ⇒ Object
Returns the value of attribute generated_from_customers_dot.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def generated_from_customers_dot
@generated_from_customers_dot
end
|
#last_synced_at ⇒ Object
Returns the value of attribute last_synced_at.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def last_synced_at
@last_synced_at
end
|
#licensee ⇒ Object
Returns the value of attribute licensee.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def licensee
@licensee
end
|
#next_sync_at ⇒ Object
Returns the value of attribute next_sync_at.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def next_sync_at
@next_sync_at
end
|
#notify_admins_at ⇒ Object
Returns the value of attribute notify_admins_at.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def notify_admins_at
@notify_admins_at
end
|
#notify_users_at ⇒ Object
Returns the value of attribute notify_users_at.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def notify_users_at
@notify_users_at
end
|
#offline_cloud_licensing_enabled ⇒ Object
Returns the value of attribute offline_cloud_licensing_enabled.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def offline_cloud_licensing_enabled
@offline_cloud_licensing_enabled
end
|
#operational_metrics_enabled ⇒ Object
Returns the value of attribute operational_metrics_enabled.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def operational_metrics_enabled
@operational_metrics_enabled
end
|
#restrictions ⇒ Object
Returns the value of attribute restrictions.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def restrictions
@restrictions
end
|
#seat_reconciliation_enabled ⇒ Object
Returns the value of attribute seat_reconciliation_enabled.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def seat_reconciliation_enabled
@seat_reconciliation_enabled
end
|
#starts_at ⇒ Object
Also known as:
issued_at
Returns the value of attribute starts_at.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def starts_at
@starts_at
end
|
#temporary_extension ⇒ Object
Returns the value of attribute temporary_extension.
77
78
79
|
# File 'lib/gitlab/license.rb', line 77
def temporary_extension
@temporary_extension
end
|
#version ⇒ Object
Returns the value of attribute version.
76
77
78
|
# File 'lib/gitlab/license.rb', line 76
def version
@version
end
|
Class Method Details
.decrypt_with_fallback_keys(data) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/gitlab/license.rb', line 61
def decrypt_with_fallback_keys(data)
keys_to_try = Array(encryption_key)
keys_to_try += fallback_decryption_keys if fallback_decryption_keys
keys_to_try.each do |decryption_key|
decryptor = Encryptor.new(decryption_key)
return decryptor.decrypt(data)
rescue Encryptor::Error
next
end
raise ImportError, 'License data could not be decrypted.'
end
|
.encryptor ⇒ Object
41
42
43
|
# File 'lib/gitlab/license.rb', line 41
def encryptor
@encryptor ||= Encryptor.new(encryption_key)
end
|
.import(data) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/gitlab/license.rb', line 45
def import(data)
raise ImportError, 'No license data.' if data.nil?
data = Boundary.remove_boundary(data)
license_json = decrypt_with_fallback_keys(data)
begin
attributes = JSON.parse(license_json)
rescue JSON::ParseError
raise ImportError, 'License data is invalid JSON.'
end
new(attributes)
end
|
Instance Method Details
#activated? ⇒ Boolean
145
146
147
|
# File 'lib/gitlab/license.rb', line 145
def activated?
activated_at
end
|
#attributes ⇒ Object
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
# File 'lib/gitlab/license.rb', line 217
def attributes
hash = {}
hash['version'] = version
hash['licensee'] = licensee
hash['issued_at'] = starts_at
hash['expires_at'] = expires_at if will_expire?
hash['notify_admins_at'] = notify_admins_at if will_notify_admins?
hash['notify_users_at'] = notify_users_at if will_notify_users?
hash['block_changes_at'] = block_changes_at if will_block_changes?
hash['next_sync_at'] = next_sync_at if will_sync?
hash['last_synced_at'] = last_synced_at if will_sync?
hash['activated_at'] = activated_at if activated?
hash['cloud_licensing_enabled'] = cloud_licensing?
hash['offline_cloud_licensing_enabled'] = offline_cloud_licensing?
hash['auto_renew_enabled'] = auto_renew?
hash['seat_reconciliation_enabled'] = seat_reconciliation?
hash['operational_metrics_enabled'] = operational_metrics?
hash['contract_overages_allowed'] = contract_overages_allowed?
hash['generated_from_customers_dot'] = generated_from_customers_dot?
hash['generated_from_cancellation'] = generated_from_cancellation?
hash['temporary_extension'] = temporary_extension?
hash['restrictions'] = restrictions if restricted?
hash
end
|
#auto_renew? ⇒ Boolean
177
178
179
|
# File 'lib/gitlab/license.rb', line 177
def auto_renew?
auto_renew_enabled == true
end
|
#block_changes? ⇒ Boolean
161
162
163
|
# File 'lib/gitlab/license.rb', line 161
def block_changes?
will_block_changes? && Date.today >= block_changes_at
end
|
#cloud_licensing? ⇒ Boolean
165
166
167
|
# File 'lib/gitlab/license.rb', line 165
def cloud_licensing?
cloud_licensing_enabled == true
end
|
#contract_overages_allowed? ⇒ Boolean
173
174
175
|
# File 'lib/gitlab/license.rb', line 173
def contract_overages_allowed?
contract_overages_allowed == true
end
|
#expired? ⇒ Boolean
149
150
151
|
# File 'lib/gitlab/license.rb', line 149
def expired?
will_expire? && Date.today >= expires_at
end
|
#export(boundary: nil) ⇒ Object
257
258
259
260
261
262
263
264
265
|
# File 'lib/gitlab/license.rb', line 257
def export(boundary: nil)
validate!
data = self.class.encryptor.encrypt(to_json)
data = Boundary.add_boundary(data, boundary) if boundary
data
end
|
#generated_from_cancellation? ⇒ Boolean
193
194
195
|
# File 'lib/gitlab/license.rb', line 193
def generated_from_cancellation?
generated_from_cancellation == true
end
|
#generated_from_customers_dot? ⇒ Boolean
189
190
191
|
# File 'lib/gitlab/license.rb', line 189
def generated_from_customers_dot?
generated_from_customers_dot == true
end
|
#gl_team_license? ⇒ Boolean
197
198
199
|
# File 'lib/gitlab/license.rb', line 197
def gl_team_license?
licensee['Company'].to_s.match?(/GitLab/i) && licensee['Email'].to_s.end_with?('@gitlab.com')
end
|
#jh_team_license? ⇒ Boolean
201
202
203
|
# File 'lib/gitlab/license.rb', line 201
def jh_team_license?
licensee['Company'].to_s.match?(/GitLab/i) && licensee['Email'].to_s.end_with?('@jihulab.com')
end
|
#notify_admins? ⇒ Boolean
153
154
155
|
# File 'lib/gitlab/license.rb', line 153
def notify_admins?
will_notify_admins? && Date.today >= notify_admins_at
end
|
#notify_users? ⇒ Boolean
157
158
159
|
# File 'lib/gitlab/license.rb', line 157
def notify_users?
will_notify_users? && Date.today >= notify_users_at
end
|
#offline_cloud_licensing? ⇒ Boolean
169
170
171
|
# File 'lib/gitlab/license.rb', line 169
def offline_cloud_licensing?
offline_cloud_licensing_enabled == true
end
|
#operational_metrics? ⇒ Boolean
185
186
187
|
# File 'lib/gitlab/license.rb', line 185
def operational_metrics?
operational_metrics_enabled == true
end
|
#restricted?(key = nil) ⇒ Boolean
209
210
211
212
213
214
215
|
# File 'lib/gitlab/license.rb', line 209
def restricted?(key = nil)
if key
restricted? && restrictions.has_key?(key)
else
restrictions && restrictions.length >= 1
end
end
|
#seat_reconciliation? ⇒ Boolean
181
182
183
|
# File 'lib/gitlab/license.rb', line 181
def seat_reconciliation?
seat_reconciliation_enabled == true
end
|
#temporary_extension? ⇒ Boolean
205
206
207
|
# File 'lib/gitlab/license.rb', line 205
def temporary_extension?
temporary_extension == true
end
|
#to_json(*_args) ⇒ Object
253
254
255
|
# File 'lib/gitlab/license.rb', line 253
def to_json(*_args)
JSON.dump(attributes)
end
|
#valid? ⇒ Boolean
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/gitlab/license.rb', line 91
def valid?
if !licensee || !licensee.is_a?(Hash) || licensee.empty?
false
elsif !starts_at || !starts_at.is_a?(Date)
false
elsif !expires_at && !gl_team_license? && !jh_team_license?
false
elsif expires_at && !expires_at.is_a?(Date)
false
elsif notify_admins_at && !notify_admins_at.is_a?(Date)
false
elsif notify_users_at && !notify_users_at.is_a?(Date)
false
elsif block_changes_at && !block_changes_at.is_a?(Date)
false
elsif last_synced_at && !last_synced_at.is_a?(DateTime)
false
elsif next_sync_at && !next_sync_at.is_a?(DateTime)
false
elsif activated_at && !activated_at.is_a?(DateTime)
false
elsif restrictions && !restrictions.is_a?(Hash)
false
elsif !cloud_licensing? && offline_cloud_licensing?
false
else
true
end
end
|
#validate! ⇒ Object
121
122
123
|
# File 'lib/gitlab/license.rb', line 121
def validate!
raise ValidationError, 'License is invalid' unless valid?
end
|
#will_block_changes? ⇒ Boolean
137
138
139
|
# File 'lib/gitlab/license.rb', line 137
def will_block_changes?
block_changes_at
end
|
#will_expire? ⇒ Boolean
125
126
127
|
# File 'lib/gitlab/license.rb', line 125
def will_expire?
expires_at
end
|
#will_notify_admins? ⇒ Boolean
129
130
131
|
# File 'lib/gitlab/license.rb', line 129
def will_notify_admins?
notify_admins_at
end
|
#will_notify_users? ⇒ Boolean
133
134
135
|
# File 'lib/gitlab/license.rb', line 133
def will_notify_users?
notify_users_at
end
|
#will_sync? ⇒ Boolean
141
142
143
|
# File 'lib/gitlab/license.rb', line 141
def will_sync?
next_sync_at
end
|