skull_island 2.0.5 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ace4a2181bc52769f759dc35b0a3798e46c6d91ac1c1ea47e84e61e8bd4d3b93
4
- data.tar.gz: 5c44345918531e4d74301643266014fb9e09cf1c8d3edf34e8cea138de667c22
3
+ metadata.gz: 17234eaf013609bf69fd1bb6be226d2da41c5c2d720fcf7c8aab6320bed7be49
4
+ data.tar.gz: bb19cf537906e3fce0b577e75261eb9ca5cba7039086b89b07dbdb69d1b4cd61
5
5
  SHA512:
6
- metadata.gz: a6567a75f0a9f0348468457f367cbc172d108d94c2f0e19be5006346e6877c6fd75f95b0e3a46830c7756edbc0f309bfc6857e629242f076ae6e1cb42b6f4bf8
7
- data.tar.gz: 374cdb852610fc7409554ca6e1fecaf161702f68cbb1eef3076da798cfb9e70ece3e3811525b72a8f990adfc5f079e7ce8875f102f6ee0c293cf355e9f4b0496
6
+ metadata.gz: 481f50743c1f3dad36f04426c2bb791484d11503df91744233f6da4789429f7b0c469ad919a25402de17da33ad03c744afb5aa60f04d11f89e96d3410e31982e
7
+ data.tar.gz: c2e8109e0ae1bdb10f0a8fa707ef8a0fac48266a4cb034d8092f86215d583fe164e57cef4b343a09cd6b0fc5a2241bd8a191e809b860f18712b5b03ae04544d2
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.5
3
+ NewCops: enable
3
4
 
4
5
  Metrics/MethodLength:
5
6
  Max: 50
@@ -13,6 +14,14 @@ Layout/LineLength:
13
14
  Layout/SpaceAroundMethodCallOperator:
14
15
  Enabled: true
15
16
 
17
+ Lint/ConstantDefinitionInBlock:
18
+ Exclude:
19
+ - 'spec/**/*_spec.rb'
20
+ - 'spec/spec_helper.rb'
21
+
22
+ Lint/MissingSuper:
23
+ Enabled: false
24
+
16
25
  Lint/RaiseException:
17
26
  Enabled: true
18
27
 
@@ -20,7 +29,7 @@ Lint/StructNewOverride:
20
29
  Enabled: true
21
30
 
22
31
  Metrics/ClassLength:
23
- Max: 190
32
+ Max: 200
24
33
 
25
34
  Metrics/ModuleLength:
26
35
  Max: 175
@@ -28,12 +37,13 @@ Metrics/ModuleLength:
28
37
  - 'lib/skull_island/helpers/resource.rb'
29
38
 
30
39
  Metrics/CyclomaticComplexity:
31
- Max: 7
40
+ Max: 8
32
41
 
33
42
  Metrics/ParameterLists:
34
43
  Max: 6
35
44
 
36
45
  Metrics/PerceivedComplexity:
46
+ Max: 8
37
47
  Exclude:
38
48
  - 'lib/skull_island/cli.rb'
39
49
 
@@ -71,5 +81,8 @@ Style/NumericLiterals:
71
81
  Exclude:
72
82
  - 'spec/**/*_spec.rb'
73
83
 
84
+ Style/OptionalBooleanParameter:
85
+ Enabled: false
86
+
74
87
  Style/SlicingWithRange:
75
88
  Enabled: true
@@ -11,4 +11,5 @@ deploy:
11
11
  gem: skull_island
12
12
  on:
13
13
  tags: true
14
+ rvm: 2.6
14
15
  repo: jgnagy/skull_island
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- skull_island (2.0.5)
4
+ skull_island (2.2.0)
5
5
  deepsort (~> 0.4)
6
6
  erubi (~> 1.8)
7
7
  json (~> 2.1)
@@ -13,15 +13,15 @@ PATH
13
13
  GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
- activesupport (5.2.4.3)
16
+ activesupport (5.2.4.4)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
18
  i18n (>= 0.7, < 2)
19
19
  minitest (~> 5.1)
20
20
  tzinfo (~> 1.1)
21
21
  addressable (2.7.0)
22
22
  public_suffix (>= 2.0.2, < 5.0)
23
- ast (2.4.0)
24
- concurrent-ruby (1.1.6)
23
+ ast (2.4.1)
24
+ concurrent-ruby (1.1.7)
25
25
  coveralls (0.7.1)
26
26
  multi_json (~> 1.3)
27
27
  rest-client
@@ -29,19 +29,17 @@ GEM
29
29
  term-ansicolor
30
30
  thor
31
31
  deepsort (0.4.5)
32
- diff-lcs (1.3)
33
- docile (1.3.2)
32
+ diff-lcs (1.4.4)
33
+ docile (1.3.3)
34
34
  domain_name (0.5.20190701)
35
35
  unf (>= 0.0.5, < 1.0.0)
36
36
  erubi (1.10.0)
37
- ethon (0.12.0)
38
- ffi (>= 1.3.0)
39
- faraday (1.0.1)
37
+ faraday (1.1.0)
40
38
  multipart-post (>= 1.2, < 3)
39
+ ruby2_keywords
41
40
  faraday_middleware (1.0.0)
42
41
  faraday (~> 1.0)
43
- ffi (1.12.2)
44
- gh (0.17.0)
42
+ gh (0.18.0)
45
43
  activesupport (~> 5.0)
46
44
  addressable (~> 2.4)
47
45
  faraday (~> 1.0)
@@ -53,9 +51,10 @@ GEM
53
51
  http-accept (1.7.0)
54
52
  http-cookie (1.0.3)
55
53
  domain_name (~> 0.5)
56
- i18n (1.8.2)
54
+ i18n (1.8.5)
57
55
  concurrent-ruby (~> 1.0)
58
- json (2.3.0)
56
+ json (2.4.1)
57
+ json_pure (2.4.1)
59
58
  launchy (2.4.3)
60
59
  addressable (~> 2.3)
61
60
  linguistics (2.1.0)
@@ -63,78 +62,83 @@ GEM
63
62
  loggability (0.17.0)
64
63
  mime-types (3.3.1)
65
64
  mime-types-data (~> 3.2015)
66
- mime-types-data (3.2020.0512)
67
- minitest (5.14.1)
68
- multi_json (1.14.1)
65
+ mime-types-data (3.2020.1104)
66
+ minitest (5.14.2)
67
+ multi_json (1.15.0)
69
68
  multipart-post (2.1.1)
70
69
  net-http-persistent (2.9.4)
71
70
  net-http-pipeline (1.0.1)
72
71
  netrc (0.11.0)
73
- parallel (1.19.1)
74
- parser (2.7.1.2)
75
- ast (~> 2.4.0)
76
- public_suffix (4.0.5)
72
+ parallel (1.20.1)
73
+ parser (2.7.2.0)
74
+ ast (~> 2.4.1)
75
+ public_suffix (4.0.6)
77
76
  pusher-client (0.6.2)
78
77
  json
79
78
  websocket (~> 1.0)
80
79
  rainbow (3.0.0)
81
80
  rake (13.0.1)
81
+ regexp_parser (2.0.0)
82
82
  rest-client (2.1.0)
83
83
  http-accept (>= 1.7.0, < 2.0)
84
84
  http-cookie (>= 1.0.2, < 2.0)
85
85
  mime-types (>= 1.16, < 4.0)
86
86
  netrc (~> 0.8)
87
87
  rexml (3.2.4)
88
- rspec (3.9.0)
89
- rspec-core (~> 3.9.0)
90
- rspec-expectations (~> 3.9.0)
91
- rspec-mocks (~> 3.9.0)
92
- rspec-core (3.9.2)
93
- rspec-support (~> 3.9.3)
94
- rspec-expectations (3.9.2)
88
+ rspec (3.10.0)
89
+ rspec-core (~> 3.10.0)
90
+ rspec-expectations (~> 3.10.0)
91
+ rspec-mocks (~> 3.10.0)
92
+ rspec-core (3.10.0)
93
+ rspec-support (~> 3.10.0)
94
+ rspec-expectations (3.10.0)
95
95
  diff-lcs (>= 1.2.0, < 2.0)
96
- rspec-support (~> 3.9.0)
97
- rspec-mocks (3.9.1)
96
+ rspec-support (~> 3.10.0)
97
+ rspec-mocks (3.10.0)
98
98
  diff-lcs (>= 1.2.0, < 2.0)
99
- rspec-support (~> 3.9.0)
100
- rspec-support (3.9.3)
101
- rubocop (0.83.0)
99
+ rspec-support (~> 3.10.0)
100
+ rspec-support (3.10.0)
101
+ rubocop (0.93.1)
102
102
  parallel (~> 1.10)
103
- parser (>= 2.7.0.1)
103
+ parser (>= 2.7.1.5)
104
104
  rainbow (>= 2.2.2, < 4.0)
105
+ regexp_parser (>= 1.8)
105
106
  rexml
107
+ rubocop-ast (>= 0.6.0)
106
108
  ruby-progressbar (~> 1.7)
107
109
  unicode-display_width (>= 1.4.0, < 2.0)
110
+ rubocop-ast (1.3.0)
111
+ parser (>= 2.7.1.5)
108
112
  ruby-progressbar (1.10.1)
109
- simplecov (0.18.5)
113
+ ruby2_keywords (0.0.2)
114
+ simplecov (0.20.0)
110
115
  docile (~> 1.1)
111
116
  simplecov-html (~> 0.11)
112
- simplecov-html (0.12.2)
117
+ simplecov_json_formatter (~> 0.1)
118
+ simplecov-html (0.12.3)
119
+ simplecov_json_formatter (0.1.2)
113
120
  sync (0.5.0)
114
121
  term-ansicolor (1.7.1)
115
122
  tins (~> 1.0)
116
123
  thor (0.20.3)
117
124
  thread_safe (0.3.6)
118
- tins (1.25.0)
125
+ tins (1.26.0)
119
126
  sync
120
- travis (1.9.1)
127
+ travis (1.10.0)
121
128
  faraday (~> 1.0)
122
129
  faraday_middleware (~> 1.0)
123
130
  gh (~> 0.13)
124
131
  highline (~> 2.0)
125
- json (~> 2.3)
132
+ json_pure (~> 2.3)
126
133
  launchy (~> 2.1, < 2.5.0)
127
134
  pusher-client (~> 0.4)
128
- typhoeus (~> 0.6, >= 0.6.8)
129
- typhoeus (0.8.0)
130
- ethon (>= 0.8.0)
131
- tzinfo (1.2.7)
135
+ tzinfo (1.2.9)
132
136
  thread_safe (~> 0.1)
133
137
  unf (0.1.4)
134
138
  unf_ext
135
139
  unf_ext (0.0.7.7)
136
140
  unicode-display_width (1.7.0)
137
- websocket (1.2.8)
141
+ websocket (1.2.9)
138
142
  will_paginate (3.3.0)
139
143
  yard (0.9.25)
140
144
 
@@ -30,7 +30,7 @@ module SkullIsland
30
30
 
31
31
  validate_server_version
32
32
 
33
- output = { 'version' => '2.0' }
33
+ output = { 'version' => '2.2' }
34
34
  output['project'] = options['project'] if options['project']
35
35
 
36
36
  [
@@ -43,7 +43,7 @@ module SkullIsland
43
43
  ].each { |clname| export_class(clname, output) }
44
44
 
45
45
  if output_file == '-'
46
- STDOUT.puts output.to_yaml
46
+ $stdout.puts output.to_yaml
47
47
  else
48
48
  File.write(full_filename, output.to_yaml)
49
49
  end
@@ -96,7 +96,7 @@ module SkullIsland
96
96
 
97
97
  if output_file == '-'
98
98
  warn '[INFO] Outputting to STDOUT' if options['verbose']
99
- STDOUT.puts output.to_yaml
99
+ $stdout.puts output.to_yaml
100
100
  else
101
101
  full_filename = File.expand_path(output_file)
102
102
  dirname = File.dirname(full_filename)
@@ -175,7 +175,7 @@ module SkullIsland
175
175
  def acquire_input(input_file, verbose = false)
176
176
  if input_file == '-'
177
177
  warn '[INFO] Reading from STDIN' if verbose
178
- STDIN.read
178
+ $stdin.read
179
179
  else
180
180
  full_filename = File.expand_path(input_file)
181
181
  unless File.exist?(full_filename) && File.ftype(full_filename) == 'file'
@@ -191,7 +191,7 @@ module SkullIsland
191
191
  end
192
192
 
193
193
  def validate_config_version(version)
194
- if version && ['1.1', '1.2', '1.4', '1.5', '2.0'].include?(version)
194
+ if version && ['1.1', '1.2', '1.4', '1.5', '2.0', '2.1', '2.2'].include?(version)
195
195
  validate_server_version
196
196
  elsif version && ['0.14', '1.0'].include?(version)
197
197
  warn '[CRITICAL] Config version is too old. Try `migrate` instead of `import`.'
@@ -213,8 +213,12 @@ module SkullIsland
213
213
 
214
214
  def validate_server_version
215
215
  server_version = SkullIsland::APIClient.about_service['version']
216
- if server_version.match?(/^2.0/)
216
+ case server_version
217
+ when /^2.[12]/
217
218
  true
219
+ when /^2.0/
220
+ warn "[WARN] Older server version #{server_version} detected! " \
221
+ 'You may encounter Service resource API exceptions.'
218
222
  else
219
223
  warn '[CRITICAL] Server version mismatch!'
220
224
  exit 1
@@ -44,7 +44,7 @@ module SkullIsland
44
44
  end
45
45
 
46
46
  def project=(project_id)
47
- unless project_id.is_a?(String) && project_id.match?(/^[\w_\-\.~]+$/)
47
+ unless project_id.is_a?(String) && project_id.match?(/^[\w_\-.~]+$/)
48
48
  raise Exceptions::InvalidArguments, 'project'
49
49
  end
50
50
 
@@ -16,6 +16,8 @@ module SkullIsland
16
16
 
17
17
  # rubocop:disable Style/GuardClause
18
18
  # rubocop:disable Security/Eval
19
+ # The delayed_set method allows a second phase of Erb templating immediately
20
+ # before sending data to the API. This allows the `lookup` function to work dynamically
19
21
  def delayed_set(property, data, key = property.to_s)
20
22
  if data[key]
21
23
  value = recursive_erubi(data[key])
@@ -27,11 +29,12 @@ module SkullIsland
27
29
  end
28
30
 
29
31
  def recursive_erubi(data)
30
- if data.is_a?(String)
32
+ case data
33
+ when String
31
34
  eval(Erubi::Engine.new(data).src)
32
- elsif data.is_a?(Array)
35
+ when Array
33
36
  data.map { |item| recursive_erubi(item) }
34
- elsif data.is_a?(Hash)
37
+ when Hash
35
38
  data.map { |k, v| [k, recursive_erubi(v)] }.to_h
36
39
  else
37
40
  data
@@ -72,7 +75,7 @@ module SkullIsland
72
75
  end
73
76
 
74
77
  def host_regex
75
- /^(([\w]|[\w][\w\-]*[\w])\.)*([\w]|[\w][\w\-]*[\w])$/
78
+ /^((\w|\w[\w\-]*\w)\.)*(\w|\w[\w\-]*\w)$/
76
79
  end
77
80
 
78
81
  def id_property
@@ -87,9 +90,8 @@ module SkullIsland
87
90
  self.class.immutable?
88
91
  end
89
92
 
90
- # rubocop:disable Metrics/CyclomaticComplexity
91
93
  # rubocop:disable Metrics/PerceivedComplexity
92
- def import_update_or_skip(verbose: false, test: false, index:)
94
+ def import_update_or_skip(index:, verbose: false, test: false)
93
95
  if find_by_digest
94
96
  puts "[INFO] Skipping #{self.class} index #{index} (#{id})" if verbose
95
97
  elsif test
@@ -102,12 +104,16 @@ module SkullIsland
102
104
  puts "[ERR] Failed to save #{self.class} index #{index}"
103
105
  end
104
106
  end
105
- # rubocop:enable Metrics/CyclomaticComplexity
107
+
106
108
  # rubocop:enable Metrics/PerceivedComplexity
107
109
 
108
110
  # Looks up IDs (and usually wraps them in a Hash)
109
111
  def lookup(type, value, raw = false)
110
112
  id_value = case type
113
+ when :ca_certificate
114
+ Resources::CACertificate.find(:name, value).id
115
+ when :certificate
116
+ Resources::Certificate.find(:name, value).id
111
117
  when :consumer
112
118
  Resources::Consumer.find(:username, value).id
113
119
  when :route
@@ -57,9 +57,10 @@ module SkullIsland
57
57
  define_method(method_name) do |value|
58
58
  raise Exceptions::ImmutableModification if immutable?
59
59
 
60
- if opts[:validate]
61
- raise Exceptions::InvalidArguments, name unless send("validate_#{name}".to_sym, value)
60
+ if opts[:validate] && !send("validate_#{name}".to_sym, value)
61
+ raise Exceptions::InvalidArguments, name
62
62
  end
63
+
63
64
  @entity[name.to_s] = if opts[:preprocess]
64
65
  send("preprocess_#{name}".to_sym, value)
65
66
  else
@@ -161,9 +161,10 @@ module SkullIsland
161
161
  # use #merge
162
162
  # @return [ResourceCollection]
163
163
  def +(other)
164
- if other.is_a?(self.class)
164
+ case other
165
+ when self.class
165
166
  self.class.new(@list + other.to_a, type: @type, api_client: @api_client)
166
- elsif other.is_a?(@type)
167
+ when @type
167
168
  self.class.new(@list + [other], type: @type, api_client: @api_client)
168
169
  else
169
170
  raise Exceptions::InvalidArguments
@@ -171,7 +172,7 @@ module SkullIsland
171
172
  end
172
173
 
173
174
  def <<(other)
174
- raise Exceptions::InvalidArguments, 'Resource Type Mismatch' unless other.class == @type
175
+ raise Exceptions::InvalidArguments, 'Resource Type Mismatch' unless other.instance_of?(@type)
175
176
 
176
177
  @list << other
177
178
  end
@@ -12,7 +12,10 @@ module SkullIsland
12
12
  property :cert, required: true, validate: true
13
13
  property :created_at, read_only: true, postprocess: true
14
14
  property :tags, validate: true, preprocess: true, postprocess: true
15
+ # property :name
15
16
 
17
+ # rubocop:disable Metrics/CyclomaticComplexity
18
+ # rubocop:disable Metrics/PerceivedComplexity
16
19
  def self.batch_import(data, verbose: false, test: false, project: nil, time: nil)
17
20
  raise(Exceptions::InvalidArguments) unless data.is_a?(Array)
18
21
 
@@ -22,6 +25,7 @@ module SkullIsland
22
25
  resource = new
23
26
  resource.delayed_set(:cert, resource_data)
24
27
  resource.tags = resource_data['tags'] if resource_data['tags']
28
+ resource.name = resource_data['name'] if resource_data['name']
25
29
  resource.project = project if project
26
30
  resource.import_time = (time || Time.now.utc.to_i) if project
27
31
  resource.import_update_or_skip(index: index, verbose: verbose, test: test)
@@ -32,10 +36,13 @@ module SkullIsland
32
36
 
33
37
  known_ids
34
38
  end
39
+ # rubocop:enable Metrics/CyclomaticComplexity
40
+ # rubocop:enable Metrics/PerceivedComplexity
35
41
 
36
42
  def export(options = {})
37
43
  hash = { 'cert' => cert }
38
44
  hash['tags'] = tags unless tags.empty?
45
+ hash['name'] = name if name
39
46
  [*options[:exclude]].each do |exclude|
40
47
  hash.delete(exclude.to_s)
41
48
  end
@@ -48,10 +55,19 @@ module SkullIsland
48
55
  def modified_existing?
49
56
  return false unless new?
50
57
 
51
- # Find CA certs of the same cert
52
- same_cert = self.class.where(:cert, cert)
58
+ # Find CA certs of the same "name"
59
+ if name
60
+ same_name = self.class.where(:name, name)
53
61
 
54
- existing = same_cert.size == 1 ? same_cert.first : nil
62
+ existing = same_name.size == 1 ? same_name.first : nil
63
+ end
64
+
65
+ unless existing
66
+ # Find CA certs of the same cert
67
+ same_cert = self.class.where(:cert, cert)
68
+
69
+ existing = same_cert.size == 1 ? same_cert.first : nil
70
+ end
55
71
 
56
72
  if existing
57
73
  @entity['id'] = existing.id
@@ -61,6 +77,16 @@ module SkullIsland
61
77
  end
62
78
  end
63
79
 
80
+ # Simulates retrieving a #name property via a tag
81
+ def name
82
+ metatags['name']
83
+ end
84
+
85
+ # Simulates setting a #name property via a tag
86
+ def name=(value)
87
+ add_meta('name', value.to_s)
88
+ end
89
+
64
90
  private
65
91
 
66
92
  # Used to validate {#cert} on set
@@ -12,11 +12,12 @@ module SkullIsland
12
12
  property :cert, required: true, validate: true
13
13
  property :key, required: true, validate: true
14
14
  property :snis, validate: true
15
+ # property :name
15
16
  property :created_at, read_only: true, postprocess: true
16
17
  property :tags, validate: true, preprocess: true, postprocess: true
17
18
 
18
- # rubocop:disable Metrics/CyclomaticComplexity
19
19
  # rubocop:disable Metrics/PerceivedComplexity
20
+ # rubocop:disable Metrics/CyclomaticComplexity
20
21
  def self.batch_import(data, verbose: false, test: false, project: nil, time: nil)
21
22
  raise(Exceptions::InvalidArguments) unless data.is_a?(Array)
22
23
 
@@ -28,6 +29,7 @@ module SkullIsland
28
29
  resource.delayed_set(:key, resource_data)
29
30
  resource.snis = resource_data['snis'] if resource_data['snis']
30
31
  resource.tags = resource_data['tags'] if resource_data['tags']
32
+ resource.name = resource_data['name'] if resource_data['name']
31
33
  resource.project = project if project
32
34
  resource.import_time = (time || Time.now.utc.to_i) if project
33
35
  resource.import_update_or_skip(index: index, verbose: verbose, test: test)
@@ -38,13 +40,15 @@ module SkullIsland
38
40
 
39
41
  known_ids
40
42
  end
41
- # rubocop:enable Metrics/CyclomaticComplexity
42
43
  # rubocop:enable Metrics/PerceivedComplexity
44
+ # rubocop:enable Metrics/CyclomaticComplexity
43
45
 
46
+ # rubocop:disable Metrics/AbcSize
44
47
  def export(options = {})
45
48
  hash = { 'cert' => cert, 'key' => key }
46
49
  hash['snis'] = snis if snis && !snis.empty?
47
50
  hash['tags'] = tags unless tags.empty?
51
+ hash['name'] = name if name
48
52
  [*options[:exclude]].each do |exclude|
49
53
  hash.delete(exclude.to_s)
50
54
  end
@@ -53,14 +57,24 @@ module SkullIsland
53
57
  end
54
58
  hash.reject { |_, value| value.nil? }
55
59
  end
60
+ # rubocop:enable Metrics/AbcSize
56
61
 
57
62
  def modified_existing?
58
63
  return false unless new?
59
64
 
60
- # Find certs of the same cert and key
61
- same_key = self.class.where(:key, key)
65
+ # Find certs of the same "name"
66
+ if name
67
+ same_name = self.class.where(:name, name)
68
+
69
+ existing = same_name.size == 1 ? same_name.first : nil
70
+ end
71
+
72
+ unless existing
73
+ # Find certs of the same cert and key
74
+ same_key = self.class.where(:key, key)
62
75
 
63
- existing = same_key.size == 1 ? same_key.first : nil
76
+ existing = same_key.size == 1 ? same_key.first : nil
77
+ end
64
78
 
65
79
  if existing
66
80
  @entity['id'] = existing.id
@@ -70,6 +84,16 @@ module SkullIsland
70
84
  end
71
85
  end
72
86
 
87
+ # Simulates retrieving a #name property via a tag
88
+ def name
89
+ metatags['name']
90
+ end
91
+
92
+ # Simulates setting a #name property via a tag
93
+ def name=(value)
94
+ add_meta('name', value.to_s)
95
+ end
96
+
73
97
  private
74
98
 
75
99
  # Used to validate {#cert} on set
@@ -60,7 +60,7 @@ module SkullIsland
60
60
 
61
61
  known_acls = AccessControlList.batch_import(
62
62
  (
63
- resource_data.dig('acls') || []
63
+ resource_data['acls'] || []
64
64
  ).map { |t| t.merge('consumer' => { 'id' => resource.id }) },
65
65
  verbose: verbose,
66
66
  test: test
@@ -105,9 +105,10 @@ module SkullIsland
105
105
  end
106
106
 
107
107
  def add_acl!(details)
108
- r = if details.is_a?(AccessControlList)
108
+ r = case details
109
+ when AccessControlList
109
110
  details
110
- elsif details.is_a?(String)
111
+ when String
111
112
  resource = AccessControlList.new(api_client: api_client)
112
113
  resource.group = details
113
114
  resource
@@ -164,6 +165,7 @@ module SkullIsland
164
165
  Plugin.where(:consumer, self, api_client: api_client)
165
166
  end
166
167
 
168
+ # rubocop:disable Metrics/AbcSize
167
169
  def export(options = {})
168
170
  hash = { 'username' => username, 'custom_id' => custom_id }
169
171
  creds = credentials_for_export
@@ -178,6 +180,7 @@ module SkullIsland
178
180
  end
179
181
  hash.reject { |_, value| value.nil? }
180
182
  end
183
+ # rubocop:enable Metrics/AbcSize
181
184
 
182
185
  def modified_existing?
183
186
  return false unless new?
@@ -48,6 +48,7 @@ module SkullIsland
48
48
  consumer ? "#{consumer.relative_uri}/jwt" : nil
49
49
  end
50
50
 
51
+ # rubocop:disable Metrics/AbcSize
51
52
  def export(options = {})
52
53
  hash = { 'algorithm' => algorithm }
53
54
  hash['key'] = key if key
@@ -62,6 +63,7 @@ module SkullIsland
62
63
  end
63
64
  hash.reject { |_, value| value.nil? }
64
65
  end
66
+ # rubocop:enable Metrics/AbcSize
65
67
 
66
68
  # Keys can't be updated, only created or deleted
67
69
  def modified_existing?
@@ -21,6 +21,7 @@ module SkullIsland
21
21
 
22
22
  # rubocop:disable Metrics/CyclomaticComplexity
23
23
  # rubocop:disable Metrics/PerceivedComplexity
24
+ # rubocop:disable Metrics/AbcSize
24
25
  def self.batch_import(data, verbose: false, test: false, project: nil, time: nil)
25
26
  raise(Exceptions::InvalidArguments) unless data.is_a?(Array)
26
27
 
@@ -48,6 +49,7 @@ module SkullIsland
48
49
  end
49
50
  # rubocop:enable Metrics/CyclomaticComplexity
50
51
  # rubocop:enable Metrics/PerceivedComplexity
52
+ # rubocop:enable Metrics/AbcSize
51
53
 
52
54
  def self.enabled_names(api_client: APIClient.instance)
53
55
  api_client.get("#{relative_uri}/enabled")['enabled_plugins']
@@ -123,14 +125,15 @@ module SkullIsland
123
125
  end
124
126
 
125
127
  def postprocess_consumer(value)
126
- if value.is_a?(Hash)
128
+ case value
129
+ when Hash
127
130
  Consumer.new(
128
131
  entity: value,
129
132
  lazy: true,
130
133
  tainted: false,
131
134
  api_client: api_client
132
135
  )
133
- elsif value.is_a?(String)
136
+ when String
134
137
  Consumer.new(
135
138
  entity: { 'id' => value },
136
139
  lazy: true,
@@ -143,9 +146,10 @@ module SkullIsland
143
146
  end
144
147
 
145
148
  def preprocess_consumer(input)
146
- if input.is_a?(Hash)
149
+ case input
150
+ when Hash
147
151
  input
148
- elsif input.is_a?(Consumer)
152
+ when Consumer
149
153
  { 'id' => input.id }
150
154
  else
151
155
  input
@@ -153,14 +157,15 @@ module SkullIsland
153
157
  end
154
158
 
155
159
  def postprocess_route(value)
156
- if value.is_a?(Hash)
160
+ case value
161
+ when Hash
157
162
  Route.new(
158
163
  entity: value,
159
164
  lazy: true,
160
165
  tainted: false,
161
166
  api_client: api_client
162
167
  )
163
- elsif value.is_a?(String)
168
+ when String
164
169
  Route.new(
165
170
  entity: { 'id' => value },
166
171
  lazy: true,
@@ -173,9 +178,10 @@ module SkullIsland
173
178
  end
174
179
 
175
180
  def preprocess_route(input)
176
- if input.is_a?(Hash)
181
+ case input
182
+ when Hash
177
183
  input
178
- elsif input.is_a?(Route)
184
+ when Route
179
185
  { 'id' => input.id }
180
186
  else
181
187
  input
@@ -183,14 +189,15 @@ module SkullIsland
183
189
  end
184
190
 
185
191
  def postprocess_service(value)
186
- if value.is_a?(Hash)
192
+ case value
193
+ when Hash
187
194
  Service.new(
188
195
  entity: value,
189
196
  lazy: true,
190
197
  tainted: false,
191
198
  api_client: api_client
192
199
  )
193
- elsif value.is_a?(String)
200
+ when String
194
201
  Service.new(
195
202
  entity: { 'id' => value },
196
203
  lazy: true,
@@ -203,9 +210,10 @@ module SkullIsland
203
210
  end
204
211
 
205
212
  def preprocess_service(input)
206
- if input.is_a?(Hash)
213
+ case input
214
+ when Hash
207
215
  input
208
- elsif input.is_a?(Service)
216
+ when Service
209
217
  { 'id' => input.id }
210
218
  else
211
219
  input
@@ -74,6 +74,8 @@ module SkullIsland
74
74
  Plugin.where(:route, self, api_client: api_client)
75
75
  end
76
76
 
77
+ # rubocop:disable Metrics/CyclomaticComplexity
78
+ # rubocop:disable Metrics/PerceivedComplexity
77
79
  # rubocop:disable Metrics/AbcSize
78
80
  def export(options = {})
79
81
  hash = {
@@ -99,6 +101,8 @@ module SkullIsland
99
101
  end
100
102
  hash.reject { |_, value| value.nil? }
101
103
  end
104
+ # rubocop:enable Metrics/CyclomaticComplexity
105
+ # rubocop:enable Metrics/PerceivedComplexity
102
106
  # rubocop:enable Metrics/AbcSize
103
107
 
104
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,7 +44,9 @@ 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
@@ -94,6 +98,8 @@ module SkullIsland
94
98
  Plugin.where(:service, self, api_client: api_client)
95
99
  end
96
100
 
101
+ # rubocop:disable Metrics/CyclomaticComplexity
102
+ # rubocop:disable Metrics/PerceivedComplexity
97
103
  # rubocop:disable Metrics/AbcSize
98
104
  def export(options = {})
99
105
  hash = {
@@ -109,7 +115,15 @@ module SkullIsland
109
115
  }
110
116
  hash['routes'] = routes.collect { |route| route.export(exclude: 'service') }
111
117
  hash['tags'] = tags unless tags.empty?
112
- 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)
113
127
  [*options[:exclude]].each do |exclude|
114
128
  hash.delete(exclude.to_s)
115
129
  end
@@ -118,6 +132,8 @@ module SkullIsland
118
132
  end
119
133
  hash.reject { |_, value| value.nil? }
120
134
  end
135
+ # rubocop:enable Metrics/CyclomaticComplexity
136
+ # rubocop:enable Metrics/PerceivedComplexity
121
137
  # rubocop:enable Metrics/AbcSize
122
138
 
123
139
  def modified_existing?
@@ -153,6 +169,33 @@ module SkullIsland
153
169
 
154
170
  private
155
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
+
156
199
  def postprocess_client_certificate(value)
157
200
  if value.is_a?(Hash)
158
201
  Certificate.new(
@@ -167,13 +210,31 @@ module SkullIsland
167
210
  end
168
211
 
169
212
  def preprocess_client_certificate(input)
170
- if input.is_a?(Hash)
213
+ case input
214
+ when Hash
171
215
  input
216
+ when String
217
+ { 'id' => input }
172
218
  else
173
219
  { 'id' => input.id }
174
220
  end
175
221
  end
176
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
+
177
238
  # Used to validate {#protocol} on set
178
239
  def validate_protocol(value)
179
240
  # only HTTP and HTTPS are allowed
@@ -192,6 +253,12 @@ module SkullIsland
192
253
  value.is_a?(Integer) && value.positive? && (1...65_535).cover?(value)
193
254
  end
194
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
+
195
262
  # Used to validate {#connect_timeout} on set
196
263
  def validate_connect_timeout(value)
197
264
  # only positive Integers are allowed
@@ -51,7 +51,7 @@ module SkullIsland
51
51
  end
52
52
 
53
53
  def self.get(id, options = {})
54
- if options[:upstream]&.is_a?(Upstream)
54
+ if options[:upstream].is_a?(Upstream)
55
55
  options[:upstream].target(id)
56
56
  elsif options[:upstream]
57
57
  upstream_opts = options.merge(lazy: true)
@@ -108,9 +108,10 @@ module SkullIsland
108
108
  end
109
109
 
110
110
  def preprocess_upstream(input)
111
- if input.is_a?(Hash)
111
+ case input
112
+ when Hash
112
113
  input
113
- elsif input.is_a?(String)
114
+ when String
114
115
  { 'id' => input }
115
116
  else
116
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
- 5 # Patch
6
+ 2, # Minor
7
+ 0 # Patch
8
8
  ].join('.')
9
9
  end
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.5
4
+ version: 2.2.0
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-12-02 00:00:00.000000000 Z
11
+ date: 2020-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deepsort