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 =
"1.0.0"
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.
64
65
66
|
# File 'lib/gitlab/license.rb', line 64
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
#block_changes_at ⇒ Object
Returns the value of attribute block_changes_at.
58
59
60
|
# File 'lib/gitlab/license.rb', line 58
def block_changes_at
@block_changes_at
end
|
#expires_at ⇒ Object
Returns the value of attribute expires_at.
57
58
59
|
# File 'lib/gitlab/license.rb', line 57
def expires_at
@expires_at
end
|
#licensee ⇒ Object
Returns the value of attribute licensee.
57
58
59
|
# File 'lib/gitlab/license.rb', line 57
def licensee
@licensee
end
|
#notify_admins_at ⇒ Object
Returns the value of attribute notify_admins_at.
58
59
60
|
# File 'lib/gitlab/license.rb', line 58
def notify_admins_at
@notify_admins_at
end
|
#notify_users_at ⇒ Object
Returns the value of attribute notify_users_at.
58
59
60
|
# File 'lib/gitlab/license.rb', line 58
def notify_users_at
@notify_users_at
end
|
#restrictions ⇒ Object
Returns the value of attribute restrictions.
59
60
61
|
# File 'lib/gitlab/license.rb', line 59
def restrictions
@restrictions
end
|
#starts_at ⇒ Object
Also known as:
issued_at
Returns the value of attribute starts_at.
57
58
59
|
# File 'lib/gitlab/license.rb', line 57
def starts_at
@starts_at
end
|
#version ⇒ Object
Returns the value of attribute version.
56
57
58
|
# File 'lib/gitlab/license.rb', line 56
def version
@version
end
|
Class Method Details
.encryptor ⇒ Object
29
30
31
|
# File 'lib/gitlab/license.rb', line 29
def encryptor
@encryptor ||= Encryptor.new(self.encryption_key)
end
|
.import(data) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/gitlab/license.rb', line 33
def import(data)
if data.nil?
raise ImportError, "No license data."
end
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
#attributes ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/gitlab/license.rb', line 124
def attributes
hash = {}
hash["version"] = self.version
hash["licensee"] = self.licensee
hash["issued_at"] = self.starts_at
hash["expires_at"] = self.expires_at if self.will_expire?
hash["notify_admins_at"] = self.notify_admins_at if self.will_notify_admins?
hash["notify_users_at"] = self.notify_users_at if self.will_notify_users?
hash["block_changes_at"] = self.block_changes_at if self.will_block_changes?
hash["restrictions"] = self.restrictions if self.restricted?
hash
end
|
#block_changes? ⇒ Boolean
112
113
114
|
# File 'lib/gitlab/license.rb', line 112
def block_changes?
will_block_changes? && Date.today >= self.block_changes_at
end
|
#expired? ⇒ Boolean
100
101
102
|
# File 'lib/gitlab/license.rb', line 100
def expired?
will_expire? && Date.today >= self.expires_at
end
|
#export(boundary: nil) ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/gitlab/license.rb', line 148
def export(boundary: nil)
validate!
data = self.class.encryptor.encrypt(self.to_json)
if boundary
data = Boundary.add_boundary(data, boundary)
end
data
end
|
#notify_admins? ⇒ Boolean
104
105
106
|
# File 'lib/gitlab/license.rb', line 104
def notify_admins?
will_notify_admins? && Date.today >= self.notify_admins_at
end
|
#notify_users? ⇒ Boolean
108
109
110
|
# File 'lib/gitlab/license.rb', line 108
def notify_users?
will_notify_users? && Date.today >= self.notify_users_at
end
|
#restricted?(key = nil) ⇒ Boolean
116
117
118
119
120
121
122
|
# File 'lib/gitlab/license.rb', line 116
def restricted?(key = nil)
if key
restricted? && restrictions.has_key?(key)
else
restrictions && restrictions.length >= 1
end
end
|
#to_json ⇒ Object
144
145
146
|
# File 'lib/gitlab/license.rb', line 144
def to_json
JSON.dump(self.attributes)
end
|
#valid? ⇒ Boolean
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/gitlab/license.rb', line 68
def valid?
return false if !licensee || !licensee.is_a?(Hash) || licensee.length == 0
return false if !starts_at || !starts_at.is_a?(Date)
return false if expires_at && !expires_at.is_a?(Date)
return false if notify_admins_at && !notify_admins_at.is_a?(Date)
return false if notify_users_at && !notify_users_at.is_a?(Date)
return false if block_changes_at && !block_changes_at.is_a?(Date)
return false if restrictions && !restrictions.is_a?(Hash)
true
end
|
#validate! ⇒ Object
80
81
82
|
# File 'lib/gitlab/license.rb', line 80
def validate!
raise ValidationError, "License is invalid" unless valid?
end
|
#will_block_changes? ⇒ Boolean
96
97
98
|
# File 'lib/gitlab/license.rb', line 96
def will_block_changes?
self.block_changes_at
end
|
#will_expire? ⇒ Boolean
84
85
86
|
# File 'lib/gitlab/license.rb', line 84
def will_expire?
self.expires_at
end
|
#will_notify_admins? ⇒ Boolean
88
89
90
|
# File 'lib/gitlab/license.rb', line 88
def will_notify_admins?
self.notify_admins_at
end
|
#will_notify_users? ⇒ Boolean
92
93
94
|
# File 'lib/gitlab/license.rb', line 92
def will_notify_users?
self.notify_users_at
end
|