skull_island 2.0.0 → 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: 00a7b4f233be82c0837c704cc2db5e07ede909632c2e54e413962f4343908974
4
- data.tar.gz: 28589bf89713ddc2a039b861d7a1290677b6c69b5bdfe2f5a7ea62bce05fa52e
3
+ metadata.gz: 17234eaf013609bf69fd1bb6be226d2da41c5c2d720fcf7c8aab6320bed7be49
4
+ data.tar.gz: bb19cf537906e3fce0b577e75261eb9ca5cba7039086b89b07dbdb69d1b4cd61
5
5
  SHA512:
6
- metadata.gz: b2530b37d2f914b1f6c6c419fa9b0c8dfb39dd9c760c51f0135bc9267eea4aab94ea3e8ae1c6058731356125a63ca1aafe5a6e97ac74ad5feb440849a28bb45b
7
- data.tar.gz: c5231a55b789eb6cd602f34c7643585a8142adb81f722e96a805b0b91509d16f05df7708f811d61cfa6b76ce67dfbb0c898506b014c7395634a40c4f95808968
6
+ metadata.gz: 481f50743c1f3dad36f04426c2bb791484d11503df91744233f6da4789429f7b0c469ad919a25402de17da33ad03c744afb5aa60f04d11f89e96d3410e31982e
7
+ data.tar.gz: c2e8109e0ae1bdb10f0a8fa707ef8a0fac48266a4cb034d8092f86215d583fe164e57cef4b343a09cd6b0fc5a2241bd8a191e809b860f18712b5b03ae04544d2
@@ -1,14 +1,35 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.5
3
+ NewCops: enable
3
4
 
4
5
  Metrics/MethodLength:
5
6
  Max: 50
6
7
 
8
+ Layout/EmptyLinesAroundAttributeAccessor:
9
+ Enabled: true
10
+
7
11
  Layout/LineLength:
8
12
  Max: 100
9
13
 
14
+ Layout/SpaceAroundMethodCallOperator:
15
+ Enabled: true
16
+
17
+ Lint/ConstantDefinitionInBlock:
18
+ Exclude:
19
+ - 'spec/**/*_spec.rb'
20
+ - 'spec/spec_helper.rb'
21
+
22
+ Lint/MissingSuper:
23
+ Enabled: false
24
+
25
+ Lint/RaiseException:
26
+ Enabled: true
27
+
28
+ Lint/StructNewOverride:
29
+ Enabled: true
30
+
10
31
  Metrics/ClassLength:
11
- Max: 190
32
+ Max: 200
12
33
 
13
34
  Metrics/ModuleLength:
14
35
  Max: 175
@@ -16,9 +37,13 @@ Metrics/ModuleLength:
16
37
  - 'lib/skull_island/helpers/resource.rb'
17
38
 
18
39
  Metrics/CyclomaticComplexity:
19
- Max: 7
40
+ Max: 8
41
+
42
+ Metrics/ParameterLists:
43
+ Max: 6
20
44
 
21
45
  Metrics/PerceivedComplexity:
46
+ Max: 8
22
47
  Exclude:
23
48
  - 'lib/skull_island/cli.rb'
24
49
 
@@ -40,6 +65,24 @@ Security/Eval:
40
65
  Exclude:
41
66
  - 'lib/skull_island/cli.rb'
42
67
 
68
+ Style/ExponentialNotation:
69
+ Enabled: true
70
+
71
+ Style/HashEachMethods:
72
+ Enabled: true
73
+
74
+ Style/HashTransformKeys:
75
+ Enabled: true
76
+
77
+ Style/HashTransformValues:
78
+ Enabled: false
79
+
43
80
  Style/NumericLiterals:
44
81
  Exclude:
45
82
  - 'spec/**/*_spec.rb'
83
+
84
+ Style/OptionalBooleanParameter:
85
+ Enabled: false
86
+
87
+ Style/SlicingWithRange:
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.0)
4
+ skull_island (2.2.0)
5
5
  deepsort (~> 0.4)
6
6
  erubi (~> 1.8)
7
7
  json (~> 2.1)
@@ -13,118 +13,134 @@ PATH
13
13
  GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
- addressable (2.4.0)
17
- ast (2.4.0)
18
- backports (3.16.1)
16
+ activesupport (5.2.4.4)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ addressable (2.7.0)
22
+ public_suffix (>= 2.0.2, < 5.0)
23
+ ast (2.4.1)
24
+ concurrent-ruby (1.1.7)
19
25
  coveralls (0.7.1)
20
26
  multi_json (~> 1.3)
21
27
  rest-client
22
28
  simplecov (>= 0.7)
23
29
  term-ansicolor
24
30
  thor
25
- deepsort (0.4.3)
26
- diff-lcs (1.3)
27
- docile (1.3.2)
31
+ deepsort (0.4.5)
32
+ diff-lcs (1.4.4)
33
+ docile (1.3.3)
28
34
  domain_name (0.5.20190701)
29
35
  unf (>= 0.0.5, < 1.0.0)
30
- erubi (1.9.0)
31
- ethon (0.12.0)
32
- ffi (>= 1.3.0)
33
- faraday (0.17.3)
36
+ erubi (1.10.0)
37
+ faraday (1.1.0)
34
38
  multipart-post (>= 1.2, < 3)
35
- faraday_middleware (0.14.0)
36
- faraday (>= 0.7.4, < 1.0)
37
- ffi (1.12.2)
38
- gh (0.15.1)
39
- addressable (~> 2.4.0)
40
- backports
41
- faraday (~> 0.8)
39
+ ruby2_keywords
40
+ faraday_middleware (1.0.0)
41
+ faraday (~> 1.0)
42
+ gh (0.18.0)
43
+ activesupport (~> 5.0)
44
+ addressable (~> 2.4)
45
+ faraday (~> 1.0)
46
+ faraday_middleware (~> 1.0)
42
47
  multi_json (~> 1.0)
43
48
  net-http-persistent (~> 2.9)
44
49
  net-http-pipeline
45
- highline (1.7.10)
50
+ highline (2.0.3)
46
51
  http-accept (1.7.0)
47
52
  http-cookie (1.0.3)
48
53
  domain_name (~> 0.5)
49
- jaro_winkler (1.5.4)
50
- json (2.3.0)
54
+ i18n (1.8.5)
55
+ concurrent-ruby (~> 1.0)
56
+ json (2.4.1)
57
+ json_pure (2.4.1)
51
58
  launchy (2.4.3)
52
59
  addressable (~> 2.3)
53
60
  linguistics (2.1.0)
54
61
  loggability (~> 0.11)
55
- loggability (0.15.1)
62
+ loggability (0.17.0)
56
63
  mime-types (3.3.1)
57
64
  mime-types-data (~> 3.2015)
58
- mime-types-data (3.2019.1009)
59
- multi_json (1.14.1)
65
+ mime-types-data (3.2020.1104)
66
+ minitest (5.14.2)
67
+ multi_json (1.15.0)
60
68
  multipart-post (2.1.1)
61
69
  net-http-persistent (2.9.4)
62
70
  net-http-pipeline (1.0.1)
63
71
  netrc (0.11.0)
64
- parallel (1.19.1)
65
- parser (2.7.0.2)
66
- ast (~> 2.4.0)
72
+ parallel (1.20.1)
73
+ parser (2.7.2.0)
74
+ ast (~> 2.4.1)
75
+ public_suffix (4.0.6)
67
76
  pusher-client (0.6.2)
68
77
  json
69
78
  websocket (~> 1.0)
70
79
  rainbow (3.0.0)
71
- rake (12.3.3)
80
+ rake (13.0.1)
81
+ regexp_parser (2.0.0)
72
82
  rest-client (2.1.0)
73
83
  http-accept (>= 1.7.0, < 2.0)
74
84
  http-cookie (>= 1.0.2, < 2.0)
75
85
  mime-types (>= 1.16, < 4.0)
76
86
  netrc (~> 0.8)
77
87
  rexml (3.2.4)
78
- rspec (3.9.0)
79
- rspec-core (~> 3.9.0)
80
- rspec-expectations (~> 3.9.0)
81
- rspec-mocks (~> 3.9.0)
82
- rspec-core (3.9.1)
83
- rspec-support (~> 3.9.1)
84
- rspec-expectations (3.9.0)
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)
85
95
  diff-lcs (>= 1.2.0, < 2.0)
86
- rspec-support (~> 3.9.0)
87
- rspec-mocks (3.9.1)
96
+ rspec-support (~> 3.10.0)
97
+ rspec-mocks (3.10.0)
88
98
  diff-lcs (>= 1.2.0, < 2.0)
89
- rspec-support (~> 3.9.0)
90
- rspec-support (3.9.2)
91
- rubocop (0.80.0)
92
- jaro_winkler (~> 1.5.1)
99
+ rspec-support (~> 3.10.0)
100
+ rspec-support (3.10.0)
101
+ rubocop (0.93.1)
93
102
  parallel (~> 1.10)
94
- parser (>= 2.7.0.1)
103
+ parser (>= 2.7.1.5)
95
104
  rainbow (>= 2.2.2, < 4.0)
105
+ regexp_parser (>= 1.8)
96
106
  rexml
107
+ rubocop-ast (>= 0.6.0)
97
108
  ruby-progressbar (~> 1.7)
98
- unicode-display_width (>= 1.4.0, < 1.7)
109
+ unicode-display_width (>= 1.4.0, < 2.0)
110
+ rubocop-ast (1.3.0)
111
+ parser (>= 2.7.1.5)
99
112
  ruby-progressbar (1.10.1)
100
- simplecov (0.18.4)
113
+ ruby2_keywords (0.0.2)
114
+ simplecov (0.20.0)
101
115
  docile (~> 1.1)
102
116
  simplecov-html (~> 0.11)
103
- simplecov-html (0.12.1)
117
+ simplecov_json_formatter (~> 0.1)
118
+ simplecov-html (0.12.3)
119
+ simplecov_json_formatter (0.1.2)
104
120
  sync (0.5.0)
105
121
  term-ansicolor (1.7.1)
106
122
  tins (~> 1.0)
107
123
  thor (0.20.3)
108
- tins (1.24.1)
124
+ thread_safe (0.3.6)
125
+ tins (1.26.0)
109
126
  sync
110
- travis (1.8.10)
111
- backports
112
- faraday (~> 0.9)
113
- faraday_middleware (~> 0.9, >= 0.9.1)
127
+ travis (1.10.0)
128
+ faraday (~> 1.0)
129
+ faraday_middleware (~> 1.0)
114
130
  gh (~> 0.13)
115
- highline (~> 1.6)
116
- launchy (~> 2.1)
131
+ highline (~> 2.0)
132
+ json_pure (~> 2.3)
133
+ launchy (~> 2.1, < 2.5.0)
117
134
  pusher-client (~> 0.4)
118
- typhoeus (~> 0.6, >= 0.6.8)
119
- typhoeus (0.8.0)
120
- ethon (>= 0.8.0)
135
+ tzinfo (1.2.9)
136
+ thread_safe (~> 0.1)
121
137
  unf (0.1.4)
122
138
  unf_ext
123
- unf_ext (0.0.7.6)
124
- unicode-display_width (1.6.1)
125
- websocket (1.2.8)
126
- will_paginate (3.2.1)
127
- yard (0.9.24)
139
+ unf_ext (0.0.7.7)
140
+ unicode-display_width (1.7.0)
141
+ websocket (1.2.9)
142
+ will_paginate (3.3.0)
143
+ yard (0.9.25)
128
144
 
129
145
  PLATFORMS
130
146
  ruby
@@ -132,7 +148,7 @@ PLATFORMS
132
148
  DEPENDENCIES
133
149
  bundler (~> 2.0)
134
150
  coveralls (~> 0.7)
135
- rake (~> 12.0)
151
+ rake (~> 13.0)
136
152
  rspec (~> 3.0)
137
153
  rubocop (~> 0.50)
138
154
  simplecov (~> 0.17)
@@ -141,4 +157,4 @@ DEPENDENCIES
141
157
  yard (~> 0.9.20)
142
158
 
143
159
  BUNDLED WITH
144
- 2.0.1
160
+ 2.1.4
data/README.md CHANGED
@@ -270,7 +270,7 @@ plugins:
270
270
  service: "<%= lookup :service, 'search_api' %>"
271
271
  ```
272
272
 
273
- All top-level keys (other than `version` and `project`) require an Array as a parameter, either by providing a list of entries or an empty Array (`[]`), or they can be omitted entirely which is the same as providing an empty Array. The above shows how to use the `lookup()` function to refer to another resource. This "looks up" the resource type (`service` in this case) by `name` (`search_api` in this case) and resolves its `id`. This function can also be used to lookup a `route` or `upstream` by its `name`, or a `consumer` by its `username`. Note that Kong itself doesn't _require_ `route` resources to have unique names, so you'll need to enforce that practice yourself for `lookup` to be useful for Routes.
273
+ All top-level keys (other than `version` and `project`) require an Array as a parameter, either by providing a list of entries or an empty Array (`[]`), or they can be omitted entirely which is the same as providing an empty Array. The above shows how to use the `lookup()` function to refer to another resource. This "looks up" the resource type (`service` in this case) by `name` (`search_api` in this case) and resolves its `id`. This function can also be used to lookup a `route` or `upstream` by its `name`, or a `consumer` by its `username`. Note that Kong itself doesn't _require_ `route` resources to have unique names, so you'll need to enforce that practice yourself for `lookup` to be useful for Routes. The `lookup` function also supports a third parameter to provide just the `id` value, rather than wrapping it in a key/value pair of `id: 9992...`. Simple call `lookup` like `lookup :service, 'search_api', true` to turn on this "raw id mode".
274
274
 
275
275
  Note that while this configuration looks a lot like the [DB-less](https://docs.konghq.com/1.4.x/db-less-and-declarative-config/) configuration (and even may, at times, be interchangeable), this is merely a coincidence. **Skull Island doesn't support the DB-less mode for Kong.** This may potentially change in the future, but for now it is not a goal of this project.
276
276
 
@@ -282,7 +282,7 @@ While technically _any_ Ruby is valid, the following are pretty helpful for temp
282
282
 
283
283
  * `ENV.fetch('VARIABLE_NAME', 'default value')` - This allows looking up the environment variable `VARIABLE_NAME` and using its value, or, if it isn't defined, it uses `default value` as the value. With this we could change `host: api.example.com` to `host: <%= ENV.fetch('API_HOST', 'api.example.com') %>`. With this, if `API_HOST` is provided, it'll use that, otherwise it will default to `api.example.com`. This is especially helpful for sensitive information; you can version control the configuration but pass in things like credentials via environment variables at runtime.
284
284
 
285
- Note also that 1.4.x and beyond of Skull Island support two phases of embedded ruby: first, a simple phase that treats the **entire file** as just text, allowing you to use the full power of ruby for things like loops, conditional logic, and more; the second phase is applied for individual attributes within the rendered YAML document. This is where the `lookup()` function above is used.
285
+ Note also that 1.4.x and beyond of Skull Island support two phases of embedded ruby: first, a simple phase that treats the **entire file** as just text, allowing you to use the full power of ruby for things like loops, conditional logic, and more; the second phase is applied for individual attributes within the rendered YAML document. This is where the `lookup()` function above is used.
286
286
 
287
287
  ## SDK Usage
288
288
 
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CoreExtensions
4
+ module Hash
5
+ # Monkey-patches for Hash to add some recursive pruning options
6
+ module Pruning
7
+ # Recursively strips empty and nil elements from a Hash
8
+ # @return [Hash]
9
+ def prune
10
+ newhash = {}
11
+
12
+ each do |k, v|
13
+ if v.is_a?(Hash)
14
+ newvalue = v.prune
15
+ newhash[k] = newvalue unless newvalue.empty?
16
+ elsif v.respond_to?(:empty?)
17
+ newhash[k] = v unless v.empty?
18
+ else
19
+ newhash[k] = v unless v.nil?
20
+ end
21
+ end
22
+
23
+ newhash
24
+ end
25
+ end
26
+ end
27
+ end
@@ -2,7 +2,9 @@
2
2
 
3
3
  # Core Extensions
4
4
  require 'core_extensions/string/transformations'
5
+ require 'core_extensions/hash/pruning'
5
6
  String.include CoreExtensions::String::Transformations
7
+ Hash.include CoreExtensions::Hash::Pruning
6
8
 
7
9
  # Standard Library Requirements
8
10
  require 'date'
@@ -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
@@ -12,8 +12,8 @@ module SkullIsland
12
12
  end
13
13
 
14
14
  # At this phase, we want to leave this alone...
15
- def lookup(type, value)
16
- "<%= lookup :#{type}, '#{value}' %>"
15
+ def lookup(type, value, raw = false)
16
+ "<%= lookup :#{type}, '#{value}', #{raw} %>"
17
17
  end
18
18
  end
19
19
  end
@@ -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,22 +104,29 @@ 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
- def lookup(type, value)
109
- case type
110
- when :consumer
111
- { 'id' => Resources::Consumer.find(:username, value).id }
112
- when :route
113
- { 'id' => Resources::Route.find(:name, value).id }
114
- when :service
115
- { 'id' => Resources::Service.find(:name, value).id }
116
- when :upstream
117
- { 'id' => Resources::Upstream.find(:name, value).id }
118
- else
119
- raise Exceptions::InvalidArguments, "#{type} is not a valid lookup type"
120
- end
110
+ # Looks up IDs (and usually wraps them in a Hash)
111
+ def lookup(type, value, raw = false)
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
117
+ when :consumer
118
+ Resources::Consumer.find(:username, value).id
119
+ when :route
120
+ Resources::Route.find(:name, value).id
121
+ when :service
122
+ Resources::Service.find(:name, value).id
123
+ when :upstream
124
+ Resources::Upstream.find(:name, value).id
125
+ else
126
+ raise Exceptions::InvalidArguments, "#{type} is not a valid lookup type"
127
+ end
128
+
129
+ raw ? id_value : { 'id' => id_value }
121
130
  end
122
131
 
123
132
  # ActiveRecord ActiveModel::Name compatibility method