gitlab-license 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4443c1a2d8d2c828a5be70bcdd91f51809e035f
4
- data.tar.gz: 8df685a6f8ba0552e75cea00c0fe47827957caee
3
+ metadata.gz: 458edee6f3e0f3ef81ae4734cc63af70a667f383
4
+ data.tar.gz: 4adc60bab3dac96bee869135a3896731bf71a5d0
5
5
  SHA512:
6
- metadata.gz: 049eedc4ade354fc031b15b7d56b2d1bf0d51c554e1139637ee61e69404c938a2be0fa618307e249b12c1b23c052230dd18769b8269142dcb899134af1d14e88
7
- data.tar.gz: 380a1aa9d305d8e0c8f9e0b129b04b8159b09c7ef276d5a961e2ee480c87f19f221a8cd21c09952082edc1eb7114a057147d17740acd87506aadee70f52a5641
6
+ metadata.gz: 369ed3f123ac2cc4ea140234597f89d05c65f178f7c8e3312a2de17e3554c8838e473b1e6e76af54ee56963465283451a732c8bec4d44b04138ecad1ed72d86f
7
+ data.tar.gz: aec729297882d8ca53352a78fefec5748e83a18b40aea8734ac83a492d70fd6e0cccb2f841206505b4d38eb234500dd577ed116b8ff19794df3fd0f54f439a62
@@ -5,6 +5,7 @@ require "base64"
5
5
 
6
6
  require "gitlab/license/version"
7
7
  require "gitlab/license/encryptor"
8
+ require "gitlab/license/boundary"
8
9
 
9
10
  module Gitlab
10
11
  class License
@@ -29,6 +30,12 @@ module Gitlab
29
30
  end
30
31
 
31
32
  def import(data)
33
+ if data.nil?
34
+ raise ImportError, "No license data."
35
+ end
36
+
37
+ data = Boundary.remove_boundary(data)
38
+
32
39
  begin
33
40
  license_json = encryptor.decrypt(data)
34
41
  rescue Encryptor::Error
@@ -40,7 +47,7 @@ module Gitlab
40
47
  rescue JSON::ParseError
41
48
  raise ImportError, "License data is invalid JSON."
42
49
  end
43
-
50
+
44
51
  new(attributes)
45
52
  end
46
53
  end
@@ -113,7 +120,7 @@ module Gitlab
113
120
  end
114
121
  end
115
122
 
116
- def attributes
123
+ def attributes
117
124
  hash = {}
118
125
 
119
126
  hash["version"] = self.version
@@ -137,10 +144,16 @@ module Gitlab
137
144
  JSON.dump(self.attributes)
138
145
  end
139
146
 
140
- def export
147
+ def export(boundary: nil)
141
148
  validate!
142
149
 
143
- self.class.encryptor.encrypt(self.to_json)
150
+ data = self.class.encryptor.encrypt(self.to_json)
151
+
152
+ if boundary
153
+ data = Boundary.add_boundary(data, boundary)
154
+ end
155
+
156
+ data
144
157
  end
145
158
 
146
159
  private
@@ -162,7 +175,7 @@ module Gitlab
162
175
  %w(issued_at expires_at notify_admins_at notify_users_at block_changes_at).each do |attr|
163
176
  value = attributes[attr]
164
177
  value = Date.parse(value) rescue nil if value.is_a?(String)
165
-
178
+
166
179
  next unless value
167
180
 
168
181
  send("#{attr}=", value)
@@ -0,0 +1,40 @@
1
+ module Gitlab
2
+ class License
3
+ module Boundary
4
+ BOUNDARY_START = /(\A|\r?\n)-*BEGIN .+? LICENSE-*\r?\n/.freeze
5
+ BOUNDARY_END = /\r?\n-*END .+? LICENSE-*(\r?\n|\z)/.freeze
6
+
7
+ class << self
8
+ def add_boundary(data, product_name)
9
+ data = remove_boundary(data)
10
+
11
+ product_name.upcase!
12
+
13
+ pad = lambda do |message, width|
14
+ total_padding = [width - message.length, 0].max
15
+
16
+ padding = total_padding / 2.0
17
+ [
18
+ "-" * padding.ceil,
19
+ message,
20
+ "-" * padding.floor
21
+ ].join
22
+ end
23
+
24
+ [
25
+ pad.call("BEGIN #{product_name} LICENSE", 60),
26
+ data.strip,
27
+ pad.call("END #{product_name} LICENSE", 60)
28
+ ].join("\n")
29
+ end
30
+
31
+ def remove_boundary(data)
32
+ after_boundary = data.split(BOUNDARY_START).last
33
+ in_boundary = after_boundary.split(BOUNDARY_END).first
34
+
35
+ in_boundary
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  class License
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-license
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Douwe Maan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-21 00:00:00.000000000 Z
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,6 +70,7 @@ files:
70
70
  - bin/setup
71
71
  - gitlab-license.gemspec
72
72
  - lib/gitlab/license.rb
73
+ - lib/gitlab/license/boundary.rb
73
74
  - lib/gitlab/license/encryptor.rb
74
75
  - lib/gitlab/license/version.rb
75
76
  homepage: https://gitlab.com/gitlab-org/gitlab-license
@@ -92,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  version: '0'
93
94
  requirements: []
94
95
  rubyforge_project:
95
- rubygems_version: 2.2.2
96
+ rubygems_version: 2.4.8
96
97
  signing_key:
97
98
  specification_version: 4
98
99
  summary: gitlab-license helps you generate, verify and enforce software licenses.