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
Defined Under Namespace
Modules: Boundary
Classes: Encryptor, Error, ImportError, ValidationError
Constant Summary
collapse
- VERSION =
'2.1.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.
62
63
64
|
# File 'lib/gitlab/license.rb', line 62
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
|
Instance Attribute Details
#activated_at ⇒ Object
Returns the value of attribute activated_at.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def activated_at
@activated_at
end
|
#auto_renew_enabled ⇒ Object
Returns the value of attribute auto_renew_enabled.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def auto_renew_enabled
@auto_renew_enabled
end
|
#block_changes_at ⇒ Object
Returns the value of attribute block_changes_at.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def block_changes_at
@block_changes_at
end
|
#cloud_licensing_enabled ⇒ Object
Returns the value of attribute cloud_licensing_enabled.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def cloud_licensing_enabled
@cloud_licensing_enabled
end
|
#expires_at ⇒ Object
Returns the value of attribute expires_at.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def expires_at
@expires_at
end
|
#generated_from_customers_dot ⇒ Object
Returns the value of attribute generated_from_customers_dot.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def generated_from_customers_dot
@generated_from_customers_dot
end
|
#last_synced_at ⇒ Object
Returns the value of attribute last_synced_at.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def last_synced_at
@last_synced_at
end
|
#licensee ⇒ Object
Returns the value of attribute licensee.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def licensee
@licensee
end
|
#next_sync_at ⇒ Object
Returns the value of attribute next_sync_at.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def next_sync_at
@next_sync_at
end
|
#notify_admins_at ⇒ Object
Returns the value of attribute notify_admins_at.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def notify_admins_at
@notify_admins_at
end
|
#notify_users_at ⇒ Object
Returns the value of attribute notify_users_at.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def notify_users_at
@notify_users_at
end
|
#offline_cloud_licensing_enabled ⇒ Object
Returns the value of attribute offline_cloud_licensing_enabled.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def offline_cloud_licensing_enabled
@offline_cloud_licensing_enabled
end
|
#operational_metrics_enabled ⇒ Object
Returns the value of attribute operational_metrics_enabled.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def operational_metrics_enabled
@operational_metrics_enabled
end
|
#restrictions ⇒ Object
Returns the value of attribute restrictions.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def restrictions
@restrictions
end
|
#seat_reconciliation_enabled ⇒ Object
Returns the value of attribute seat_reconciliation_enabled.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def seat_reconciliation_enabled
@seat_reconciliation_enabled
end
|
#starts_at ⇒ Object
Also known as:
issued_at
Returns the value of attribute starts_at.
53
54
55
|
# File 'lib/gitlab/license.rb', line 53
def starts_at
@starts_at
end
|
#version ⇒ Object
Returns the value of attribute version.
52
53
54
|
# File 'lib/gitlab/license.rb', line 52
def version
@version
end
|
Class Method Details
.encryptor ⇒ Object
27
28
29
|
# File 'lib/gitlab/license.rb', line 27
def encryptor
@encryptor ||= Encryptor.new(encryption_key)
end
|
.import(data) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/gitlab/license.rb', line 31
def import(data)
raise ImportError, 'No license data.' if data.nil?
data = Boundary.remove_boundary(data)
begin
license_json = encryptor.decrypt(data)
rescue Encryptor::Error
raise ImportError, 'License data could not be decrypted.'
end
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
118
119
120
|
# File 'lib/gitlab/license.rb', line 118
def activated?
activated_at
end
|
#attributes ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# File 'lib/gitlab/license.rb', line 170
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['generated_from_customers_dot'] = generated_from_customers_dot?
hash['restrictions'] = restrictions if restricted?
hash
end
|
#auto_renew? ⇒ Boolean
146
147
148
|
# File 'lib/gitlab/license.rb', line 146
def auto_renew?
auto_renew_enabled == true
end
|
#block_changes? ⇒ Boolean
134
135
136
|
# File 'lib/gitlab/license.rb', line 134
def block_changes?
will_block_changes? && Date.today >= block_changes_at
end
|
#cloud_licensing? ⇒ Boolean
138
139
140
|
# File 'lib/gitlab/license.rb', line 138
def cloud_licensing?
cloud_licensing_enabled == true
end
|
#expired? ⇒ Boolean
122
123
124
|
# File 'lib/gitlab/license.rb', line 122
def expired?
will_expire? && Date.today >= expires_at
end
|
#export(boundary: nil) ⇒ Object
206
207
208
209
210
211
212
213
214
|
# File 'lib/gitlab/license.rb', line 206
def export(boundary: nil)
validate!
data = self.class.encryptor.encrypt(to_json)
data = Boundary.add_boundary(data, boundary) if boundary
data
end
|
#generated_from_customers_dot? ⇒ Boolean
158
159
160
|
# File 'lib/gitlab/license.rb', line 158
def generated_from_customers_dot?
generated_from_customers_dot == true
end
|
#notify_admins? ⇒ Boolean
126
127
128
|
# File 'lib/gitlab/license.rb', line 126
def notify_admins?
will_notify_admins? && Date.today >= notify_admins_at
end
|
#notify_users? ⇒ Boolean
130
131
132
|
# File 'lib/gitlab/license.rb', line 130
def notify_users?
will_notify_users? && Date.today >= notify_users_at
end
|
#offline_cloud_licensing? ⇒ Boolean
142
143
144
|
# File 'lib/gitlab/license.rb', line 142
def offline_cloud_licensing?
offline_cloud_licensing_enabled == true
end
|
#operational_metrics? ⇒ Boolean
154
155
156
|
# File 'lib/gitlab/license.rb', line 154
def operational_metrics?
operational_metrics_enabled == true
end
|
#restricted?(key = nil) ⇒ Boolean
162
163
164
165
166
167
168
|
# File 'lib/gitlab/license.rb', line 162
def restricted?(key = nil)
if key
restricted? && restrictions.has_key?(key)
else
restrictions && restrictions.length >= 1
end
end
|
#seat_reconciliation? ⇒ Boolean
150
151
152
|
# File 'lib/gitlab/license.rb', line 150
def seat_reconciliation?
seat_reconciliation_enabled == true
end
|
#to_json(*_args) ⇒ Object
202
203
204
|
# File 'lib/gitlab/license.rb', line 202
def to_json(*_args)
JSON.dump(attributes)
end
|
#valid? ⇒ Boolean
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/gitlab/license.rb', line 66
def valid?
if !licensee || !licensee.is_a?(Hash) || licensee.empty?
false
elsif !starts_at || !starts_at.is_a?(Date)
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
94
95
96
|
# File 'lib/gitlab/license.rb', line 94
def validate!
raise ValidationError, 'License is invalid' unless valid?
end
|
#will_block_changes? ⇒ Boolean
110
111
112
|
# File 'lib/gitlab/license.rb', line 110
def will_block_changes?
block_changes_at
end
|
#will_expire? ⇒ Boolean
98
99
100
|
# File 'lib/gitlab/license.rb', line 98
def will_expire?
expires_at
end
|
#will_notify_admins? ⇒ Boolean
102
103
104
|
# File 'lib/gitlab/license.rb', line 102
def will_notify_admins?
notify_admins_at
end
|
#will_notify_users? ⇒ Boolean
106
107
108
|
# File 'lib/gitlab/license.rb', line 106
def will_notify_users?
notify_users_at
end
|
#will_sync? ⇒ Boolean
114
115
116
|
# File 'lib/gitlab/license.rb', line 114
def will_sync?
next_sync_at
end
|