skull_island 2.0.3 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,7 +31,8 @@ module SkullIsland
31
31
  # rubocop:disable Metrics/CyclomaticComplexity
32
32
  # rubocop:disable Metrics/PerceivedComplexity
33
33
  # rubocop:disable Metrics/AbcSize
34
- def self.batch_import(data, verbose: false, test: false, project: nil, time: nil)
34
+ # rubocop:disable Layout/LineLength
35
+ def self.batch_import(data, verbose: false, test: false, project: nil, time: nil, cleanup: true)
35
36
  raise(Exceptions::InvalidArguments) unless data.is_a?(Array)
36
37
 
37
38
  known_ids = []
@@ -59,17 +60,22 @@ module SkullIsland
59
60
  known_ids << resource.id
60
61
  end
61
62
 
62
- cleanup_except(project, known_ids) if project
63
+ cleanup_except(project, known_ids) if project && cleanup
64
+
65
+ known_ids
63
66
  end
64
67
  # rubocop:enable Metrics/CyclomaticComplexity
65
68
  # rubocop:enable Metrics/PerceivedComplexity
66
69
  # rubocop:enable Metrics/AbcSize
70
+ # rubocop:enable Layout/LineLength
67
71
 
68
72
  # Provides a collection of related {Plugin} instances
69
73
  def plugins
70
74
  Plugin.where(:route, self, api_client: api_client)
71
75
  end
72
76
 
77
+ # rubocop:disable Metrics/CyclomaticComplexity
78
+ # rubocop:disable Metrics/PerceivedComplexity
73
79
  # rubocop:disable Metrics/AbcSize
74
80
  def export(options = {})
75
81
  hash = {
@@ -95,6 +101,8 @@ module SkullIsland
95
101
  end
96
102
  hash.reject { |_, value| value.nil? }
97
103
  end
104
+ # rubocop:enable Metrics/CyclomaticComplexity
105
+ # rubocop:enable Metrics/PerceivedComplexity
98
106
  # rubocop:enable Metrics/AbcSize
99
107
 
100
108
  def modified_existing?
@@ -10,14 +10,16 @@ module SkullIsland
10
10
  include Helpers::Meta
11
11
 
12
12
  property :name
13
- property :retries
13
+ property :retries, validate: true
14
14
  property :protocol, validate: true, required: true
15
15
  property :host, validate: true, required: true
16
16
  property :port, validate: true, required: true
17
+ property :tls_verify, type: :boolean
17
18
  property :path
18
19
  property :connect_timeout, validate: true
19
20
  property :write_timeout, validate: true
20
21
  property :read_timeout, validate: true
22
+ property :ca_certificates, validate: true, preprocess: true, postprocess: true
21
23
  property :client_certificate, validate: true, preprocess: true, postprocess: true
22
24
  property :created_at, read_only: true, postprocess: true
23
25
  property :updated_at, read_only: true, postprocess: true
@@ -42,23 +44,32 @@ module SkullIsland
42
44
  resource.connect_timeout = rdata['connect_timeout'] if rdata['connect_timeout']
43
45
  resource.write_timeout = rdata['write_timeout'] if rdata['write_timeout']
44
46
  resource.read_timeout = rdata['read_timeout'] if rdata['read_timeout']
47
+ resource.tls_verify = rdata['tls_verify'] if rdata['tls_verify']
45
48
  resource.delayed_set(:client_certificate, rdata) if rdata['client_certificate']
49
+ resource.delayed_set(:ca_certificates, rdata) if rdata['ca_certificates']
46
50
  resource.tags = rdata['tags'] if rdata['tags']
47
51
  resource.project = project if project
48
52
  resource.import_time = (time || Time.now.utc.to_i) if project
49
53
  resource.import_update_or_skip(index: index, verbose: verbose, test: test)
50
54
  known_ids << resource.id
51
55
 
52
- Route.batch_import(
56
+ previous_routes = resource.routes.dup
57
+
58
+ added_routes = Route.batch_import(
53
59
  (rdata['routes'] || []).map { |r| r.merge('service' => { 'id' => resource.id }) },
54
60
  verbose: verbose,
55
61
  test: test,
56
62
  project: project,
57
- time: time
63
+ time: time,
64
+ cleanup: false
58
65
  )
66
+
67
+ Route.cleanup_except(project, added_routes, previous_routes)
59
68
  end
60
69
 
61
70
  cleanup_except(project, known_ids) if project
71
+
72
+ known_ids
62
73
  end
63
74
  # rubocop:enable Metrics/CyclomaticComplexity
64
75
  # rubocop:enable Metrics/PerceivedComplexity
@@ -87,6 +98,8 @@ module SkullIsland
87
98
  Plugin.where(:service, self, api_client: api_client)
88
99
  end
89
100
 
101
+ # rubocop:disable Metrics/CyclomaticComplexity
102
+ # rubocop:disable Metrics/PerceivedComplexity
90
103
  # rubocop:disable Metrics/AbcSize
91
104
  def export(options = {})
92
105
  hash = {
@@ -102,7 +115,15 @@ module SkullIsland
102
115
  }
103
116
  hash['routes'] = routes.collect { |route| route.export(exclude: 'service') }
104
117
  hash['tags'] = tags unless tags.empty?
105
- hash['client_certificate'] = client_certificate if client_certificate
118
+ if client_certificate&.name
119
+ hash['client_certificate'] = "<%= lookup :certificate, '#{client_certificate.name}' %>"
120
+ elsif client_certificate
121
+ hash['client_certificate'] = { 'id' => client_certificate.id }
122
+ end
123
+ if ca_certificates && !ca_certificates.empty?
124
+ hash['ca_certificates'] = export_ca_certificates
125
+ end
126
+ hash['tls_verify'] = tls_verify if [true, false].include?(tls_verify)
106
127
  [*options[:exclude]].each do |exclude|
107
128
  hash.delete(exclude.to_s)
108
129
  end
@@ -111,12 +132,14 @@ module SkullIsland
111
132
  end
112
133
  hash.reject { |_, value| value.nil? }
113
134
  end
135
+ # rubocop:enable Metrics/CyclomaticComplexity
136
+ # rubocop:enable Metrics/PerceivedComplexity
114
137
  # rubocop:enable Metrics/AbcSize
115
138
 
116
139
  def modified_existing?
117
140
  return false unless new?
118
141
 
119
- # Find routes of the same name
142
+ # Find services of the same name
120
143
  same_name = self.class.where(:name, name)
121
144
 
122
145
  existing = same_name.size == 1 ? same_name.first : nil
@@ -146,6 +169,33 @@ module SkullIsland
146
169
 
147
170
  private
148
171
 
172
+ def export_ca_certificates
173
+ ca_certificates.map do |cacert|
174
+ cacert.name ? "<%= lookup :ca_certificate, '#{cacert.name}', raw: true %>" : cacert.id
175
+ end
176
+ end
177
+
178
+ def postprocess_ca_certificates(value)
179
+ if value.respond_to?(:to_a)
180
+ value.to_a.map do |cacert|
181
+ CACertificate.new(
182
+ entity: { 'id' => cacert },
183
+ lazy: true,
184
+ tainted: false,
185
+ api_client: api_client
186
+ )
187
+ end
188
+ else
189
+ value
190
+ end
191
+ end
192
+
193
+ def preprocess_ca_certificates(input)
194
+ input.to_a.map do |cacert|
195
+ cacert.is_a?(String) ? cacert : cacert.id
196
+ end
197
+ end
198
+
149
199
  def postprocess_client_certificate(value)
150
200
  if value.is_a?(Hash)
151
201
  Certificate.new(
@@ -160,13 +210,31 @@ module SkullIsland
160
210
  end
161
211
 
162
212
  def preprocess_client_certificate(input)
163
- if input.is_a?(Hash)
213
+ case input
214
+ when Hash
164
215
  input
216
+ when String
217
+ { 'id' => input }
165
218
  else
166
219
  { 'id' => input.id }
167
220
  end
168
221
  end
169
222
 
223
+ # Validates {#ca_certificates} on set
224
+ def validate_ca_certificates(value)
225
+ # only Arrays (or Enumarables) are supported
226
+ return false unless value.is_a?(Array) || value.respond_to?(:to_a)
227
+
228
+ # Can only contain a array of Strings or CACertificates
229
+ value.to_a.reject { |v| v.is_a?(String) || v.is_a?(CACertificate) }.empty?
230
+ end
231
+
232
+ # Used to validate {#client_certificate} on set
233
+ def validate_client_certificate(value)
234
+ # only Strings, Hashes, or Certificates are allowed
235
+ value.is_a?(String) || value.is_a?(Hash) || value.is_a?(Certificate)
236
+ end
237
+
170
238
  # Used to validate {#protocol} on set
171
239
  def validate_protocol(value)
172
240
  # only HTTP and HTTPS are allowed
@@ -185,6 +253,12 @@ module SkullIsland
185
253
  value.is_a?(Integer) && value.positive? && (1...65_535).cover?(value)
186
254
  end
187
255
 
256
+ # Used to validate {#retries} on set
257
+ def validate_retries(value)
258
+ # only positive Integers of the right value are allowed
259
+ value.is_a?(Integer) && value.positive? && (1...65_535).cover?(value)
260
+ end
261
+
188
262
  # Used to validate {#connect_timeout} on set
189
263
  def validate_connect_timeout(value)
190
264
  # only positive Integers are allowed
@@ -65,6 +65,8 @@ module SkullIsland
65
65
  end
66
66
 
67
67
  cleanup_except(project, known_ids) if project
68
+
69
+ known_ids
68
70
  end
69
71
  # rubocop:enable Metrics/CyclomaticComplexity
70
72
  # rubocop:enable Metrics/PerceivedComplexity
@@ -38,6 +38,8 @@ module SkullIsland
38
38
  end
39
39
 
40
40
  cleanup_except(project, known_ids) if project
41
+
42
+ known_ids
41
43
  end
42
44
  # rubocop:enable Metrics/CyclomaticComplexity
43
45
  # rubocop:enable Metrics/PerceivedComplexity
@@ -49,7 +51,7 @@ module SkullIsland
49
51
  end
50
52
 
51
53
  def self.get(id, options = {})
52
- if options[:upstream]&.is_a?(Upstream)
54
+ if options[:upstream].is_a?(Upstream)
53
55
  options[:upstream].target(id)
54
56
  elsif options[:upstream]
55
57
  upstream_opts = options.merge(lazy: true)
@@ -106,9 +108,10 @@ module SkullIsland
106
108
  end
107
109
 
108
110
  def preprocess_upstream(input)
109
- if input.is_a?(Hash)
111
+ case input
112
+ when Hash
110
113
  input
111
- elsif input.is_a?(String)
114
+ when String
112
115
  { 'id' => input }
113
116
  else
114
117
  { 'id' => input.id }
@@ -34,7 +34,7 @@ module SkullIsland
34
34
  valid = name.is_a? String
35
35
  begin
36
36
  u = URI.parse(name)
37
- valid = false unless u.class == URI::HTTP || u.class == URI::HTTPS
37
+ valid = false unless u.is_a?(URI::HTTP) || u.is_a?(URI::HTTPS)
38
38
  rescue URI::InvalidURIError
39
39
  valid = false
40
40
  end
@@ -24,7 +24,7 @@ module SkullIsland
24
24
  def validate_tags(value)
25
25
  # allow only valid hostnames
26
26
  value.each do |tag|
27
- return false unless tag.is_a?(String) && tag.match?(/^[\w_\-\.~]+$/)
27
+ return false unless tag.is_a?(String) && tag.match?(/^[\w_\-.~]+$/)
28
28
  end
29
29
  true
30
30
  end
@@ -3,7 +3,7 @@
3
3
  module SkullIsland
4
4
  VERSION = [
5
5
  2, # Major
6
- 0, # Minor
7
- 3 # Patch
6
+ 2, # Minor
7
+ 2 # Patch
8
8
  ].join('.')
9
9
  end
data/skull_island.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.email = ['jonathan.gnagy@gmail.com']
12
12
 
13
13
  spec.summary = 'Ruby SDK for Kong'
14
- spec.description = 'A Ruby SDK for Kong 0.14.x'
14
+ spec.description = 'A Ruby SDK for Kong'
15
15
  spec.homepage = 'https://github.com/jgnagy/skull_island'
16
16
  spec.license = 'MIT'
17
17
 
@@ -31,12 +31,12 @@ Gem::Specification.new do |spec|
31
31
  spec.add_runtime_dependency 'json', '~> 2.1'
32
32
  spec.add_runtime_dependency 'linguistics', '~> 2.1'
33
33
  spec.add_runtime_dependency 'rest-client', '~> 2.1'
34
- spec.add_runtime_dependency 'thor', '~> 0.20'
34
+ spec.add_runtime_dependency 'thor', '~> 1.0'
35
35
  spec.add_runtime_dependency 'will_paginate', '~> 3.1'
36
36
 
37
37
  spec.add_development_dependency 'bundler', '~> 2.0'
38
38
  spec.add_development_dependency 'coveralls', '~> 0.7'
39
- spec.add_development_dependency 'rake', '~> 12.0'
39
+ spec.add_development_dependency 'rake', '~> 13.0'
40
40
  spec.add_development_dependency 'rspec', '~> 3.0'
41
41
  spec.add_development_dependency 'rubocop', '~> 0.50'
42
42
  spec.add_development_dependency 'simplecov', '~> 0.17'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skull_island
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gnagy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-02 00:00:00.000000000 Z
11
+ date: 2021-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deepsort
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.20'
89
+ version: '1.0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.20'
96
+ version: '1.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: will_paginate
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '12.0'
145
+ version: '13.0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '12.0'
152
+ version: '13.0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rspec
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -220,7 +220,7 @@ dependencies:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
222
  version: 0.9.20
223
- description: A Ruby SDK for Kong 0.14.x
223
+ description: A Ruby SDK for Kong
224
224
  email:
225
225
  - jonathan.gnagy@gmail.com
226
226
  executables:
@@ -306,8 +306,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
306
306
  - !ruby/object:Gem::Version
307
307
  version: '0'
308
308
  requirements: []
309
- rubyforge_project:
310
- rubygems_version: 2.7.7
309
+ rubygems_version: 3.0.8
311
310
  signing_key:
312
311
  specification_version: 4
313
312
  summary: Ruby SDK for Kong