skull_island 2.0.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +45 -2
- data/.travis.yml +1 -0
- data/Gemfile.lock +78 -62
- data/README.md +2 -2
- data/lib/core_extensions/hash/pruning.rb +27 -0
- data/lib/skull_island.rb +2 -0
- data/lib/skull_island/cli.rb +10 -6
- data/lib/skull_island/helpers/cli_erb.rb +2 -2
- data/lib/skull_island/helpers/meta.rb +1 -1
- data/lib/skull_island/helpers/resource.rb +29 -20
- data/lib/skull_island/resource.rb +7 -4
- data/lib/skull_island/resource_collection.rb +4 -3
- data/lib/skull_island/resources/ca_certificate.rb +31 -3
- data/lib/skull_island/resources/certificate.rb +31 -5
- data/lib/skull_island/resources/consumer.rb +8 -3
- data/lib/skull_island/resources/jwt_credential.rb +4 -1
- data/lib/skull_island/resources/plugin.rb +23 -13
- data/lib/skull_island/resources/route.rb +17 -2
- data/lib/skull_island/resources/service.rb +80 -6
- data/lib/skull_island/resources/upstream.rb +8 -1
- data/lib/skull_island/resources/upstream_target.rb +6 -3
- data/lib/skull_island/validations/api_client.rb +1 -1
- data/lib/skull_island/validations/resource.rb +1 -1
- data/lib/skull_island/version.rb +1 -1
- data/skull_island.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17234eaf013609bf69fd1bb6be226d2da41c5c2d720fcf7c8aab6320bed7be49
|
4
|
+
data.tar.gz: bb19cf537906e3fce0b577e75261eb9ca5cba7039086b89b07dbdb69d1b4cd61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 481f50743c1f3dad36f04426c2bb791484d11503df91744233f6da4789429f7b0c469ad919a25402de17da33ad03c744afb5aa60f04d11f89e96d3410e31982e
|
7
|
+
data.tar.gz: c2e8109e0ae1bdb10f0a8fa707ef8a0fac48266a4cb034d8092f86215d583fe164e57cef4b343a09cd6b0fc5a2241bd8a191e809b860f18712b5b03ae04544d2
|
data/.rubocop.yml
CHANGED
@@ -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:
|
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:
|
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
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
skull_island (2.
|
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
|
-
|
17
|
-
|
18
|
-
|
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.
|
26
|
-
diff-lcs (1.
|
27
|
-
docile (1.3.
|
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.
|
31
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
gh (0.
|
39
|
-
|
40
|
-
|
41
|
-
faraday (~> 0
|
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 (
|
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
|
-
|
50
|
-
|
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.
|
62
|
+
loggability (0.17.0)
|
56
63
|
mime-types (3.3.1)
|
57
64
|
mime-types-data (~> 3.2015)
|
58
|
-
mime-types-data (3.
|
59
|
-
|
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.
|
65
|
-
parser (2.7.0
|
66
|
-
ast (~> 2.4.
|
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 (
|
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.
|
79
|
-
rspec-core (~> 3.
|
80
|
-
rspec-expectations (~> 3.
|
81
|
-
rspec-mocks (~> 3.
|
82
|
-
rspec-core (3.
|
83
|
-
rspec-support (~> 3.
|
84
|
-
rspec-expectations (3.
|
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.
|
87
|
-
rspec-mocks (3.
|
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.
|
90
|
-
rspec-support (3.
|
91
|
-
rubocop (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.
|
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, <
|
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
|
-
|
113
|
+
ruby2_keywords (0.0.2)
|
114
|
+
simplecov (0.20.0)
|
101
115
|
docile (~> 1.1)
|
102
116
|
simplecov-html (~> 0.11)
|
103
|
-
|
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
|
-
|
124
|
+
thread_safe (0.3.6)
|
125
|
+
tins (1.26.0)
|
109
126
|
sync
|
110
|
-
travis (1.
|
111
|
-
|
112
|
-
|
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 (~>
|
116
|
-
|
131
|
+
highline (~> 2.0)
|
132
|
+
json_pure (~> 2.3)
|
133
|
+
launchy (~> 2.1, < 2.5.0)
|
117
134
|
pusher-client (~> 0.4)
|
118
|
-
|
119
|
-
|
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.
|
124
|
-
unicode-display_width (1.
|
125
|
-
websocket (1.2.
|
126
|
-
will_paginate (3.
|
127
|
-
yard (0.9.
|
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 (~>
|
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.
|
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
|
data/lib/skull_island.rb
CHANGED
@@ -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'
|
data/lib/skull_island/cli.rb
CHANGED
@@ -30,7 +30,7 @@ module SkullIsland
|
|
30
30
|
|
31
31
|
validate_server_version
|
32
32
|
|
33
|
-
output = { 'version' => '2.
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
32
|
+
case data
|
33
|
+
when String
|
31
34
|
eval(Erubi::Engine.new(data).src)
|
32
|
-
|
35
|
+
when Array
|
33
36
|
data.map { |item| recursive_erubi(item) }
|
34
|
-
|
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
|
-
/^((
|
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
|
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
|
-
|
107
|
+
|
106
108
|
# rubocop:enable Metrics/PerceivedComplexity
|
107
109
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
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
|