skull_island 1.4.2 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +30 -0
- data/Gemfile.lock +60 -45
- data/README.md +11 -11
- data/lib/core_extensions/hash/pruning.rb +27 -0
- data/lib/skull_island.rb +6 -3
- data/lib/skull_island/cli.rb +5 -5
- data/lib/skull_island/helpers/cli_erb.rb +2 -2
- data/lib/skull_island/helpers/migration.rb +17 -1
- data/lib/skull_island/helpers/resource.rb +16 -13
- data/lib/skull_island/resource.rb +4 -2
- data/lib/skull_island/resources/ca_certificate.rb +2 -0
- data/lib/skull_island/resources/certificate.rb +2 -0
- data/lib/skull_island/resources/consumer.rb +2 -0
- data/lib/skull_island/resources/jwt_credential.rb +2 -1
- data/lib/skull_island/resources/plugin.rb +4 -2
- data/lib/skull_island/resources/route.rb +13 -2
- data/lib/skull_island/resources/service.rb +10 -3
- data/lib/skull_island/resources/upstream.rb +8 -1
- data/lib/skull_island/resources/upstream_target.rb +2 -0
- data/lib/skull_island/version.rb +3 -3
- 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: ace4a2181bc52769f759dc35b0a3798e46c6d91ac1c1ea47e84e61e8bd4d3b93
|
4
|
+
data.tar.gz: 5c44345918531e4d74301643266014fb9e09cf1c8d3edf34e8cea138de667c22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6567a75f0a9f0348468457f367cbc172d108d94c2f0e19be5006346e6877c6fd75f95b0e3a46830c7756edbc0f309bfc6857e629242f076ae6e1cb42b6f4bf8
|
7
|
+
data.tar.gz: 374cdb852610fc7409554ca6e1fecaf161702f68cbb1eef3076da798cfb9e70ece3e3811525b72a8f990adfc5f079e7ce8875f102f6ee0c293cf355e9f4b0496
|
data/.rubocop.yml
CHANGED
@@ -4,9 +4,21 @@ AllCops:
|
|
4
4
|
Metrics/MethodLength:
|
5
5
|
Max: 50
|
6
6
|
|
7
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
8
|
+
Enabled: true
|
9
|
+
|
7
10
|
Layout/LineLength:
|
8
11
|
Max: 100
|
9
12
|
|
13
|
+
Layout/SpaceAroundMethodCallOperator:
|
14
|
+
Enabled: true
|
15
|
+
|
16
|
+
Lint/RaiseException:
|
17
|
+
Enabled: true
|
18
|
+
|
19
|
+
Lint/StructNewOverride:
|
20
|
+
Enabled: true
|
21
|
+
|
10
22
|
Metrics/ClassLength:
|
11
23
|
Max: 190
|
12
24
|
|
@@ -18,6 +30,9 @@ Metrics/ModuleLength:
|
|
18
30
|
Metrics/CyclomaticComplexity:
|
19
31
|
Max: 7
|
20
32
|
|
33
|
+
Metrics/ParameterLists:
|
34
|
+
Max: 6
|
35
|
+
|
21
36
|
Metrics/PerceivedComplexity:
|
22
37
|
Exclude:
|
23
38
|
- 'lib/skull_island/cli.rb'
|
@@ -40,6 +55,21 @@ Security/Eval:
|
|
40
55
|
Exclude:
|
41
56
|
- 'lib/skull_island/cli.rb'
|
42
57
|
|
58
|
+
Style/ExponentialNotation:
|
59
|
+
Enabled: true
|
60
|
+
|
61
|
+
Style/HashEachMethods:
|
62
|
+
Enabled: true
|
63
|
+
|
64
|
+
Style/HashTransformKeys:
|
65
|
+
Enabled: true
|
66
|
+
|
67
|
+
Style/HashTransformValues:
|
68
|
+
Enabled: false
|
69
|
+
|
43
70
|
Style/NumericLiterals:
|
44
71
|
Exclude:
|
45
72
|
- 'spec/**/*_spec.rb'
|
73
|
+
|
74
|
+
Style/SlicingWithRange:
|
75
|
+
Enabled: true
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
skull_island (
|
4
|
+
skull_island (2.0.5)
|
5
5
|
deepsort (~> 0.4)
|
6
6
|
erubi (~> 1.8)
|
7
7
|
json (~> 2.1)
|
@@ -13,115 +13,130 @@ PATH
|
|
13
13
|
GEM
|
14
14
|
remote: https://rubygems.org/
|
15
15
|
specs:
|
16
|
-
|
16
|
+
activesupport (5.2.4.3)
|
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)
|
17
23
|
ast (2.4.0)
|
18
|
-
|
24
|
+
concurrent-ruby (1.1.6)
|
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.
|
31
|
+
deepsort (0.4.5)
|
26
32
|
diff-lcs (1.3)
|
27
33
|
docile (1.3.2)
|
28
34
|
domain_name (0.5.20190701)
|
29
35
|
unf (>= 0.0.5, < 1.0.0)
|
30
|
-
erubi (1.
|
36
|
+
erubi (1.10.0)
|
31
37
|
ethon (0.12.0)
|
32
38
|
ffi (>= 1.3.0)
|
33
|
-
faraday (0.
|
39
|
+
faraday (1.0.1)
|
34
40
|
multipart-post (>= 1.2, < 3)
|
35
|
-
faraday_middleware (0.
|
36
|
-
faraday (
|
37
|
-
ffi (1.
|
38
|
-
gh (0.
|
39
|
-
|
40
|
-
|
41
|
-
faraday (~> 0
|
41
|
+
faraday_middleware (1.0.0)
|
42
|
+
faraday (~> 1.0)
|
43
|
+
ffi (1.12.2)
|
44
|
+
gh (0.17.0)
|
45
|
+
activesupport (~> 5.0)
|
46
|
+
addressable (~> 2.4)
|
47
|
+
faraday (~> 1.0)
|
48
|
+
faraday_middleware (~> 1.0)
|
42
49
|
multi_json (~> 1.0)
|
43
50
|
net-http-persistent (~> 2.9)
|
44
51
|
net-http-pipeline
|
45
|
-
highline (
|
52
|
+
highline (2.0.3)
|
46
53
|
http-accept (1.7.0)
|
47
54
|
http-cookie (1.0.3)
|
48
55
|
domain_name (~> 0.5)
|
49
|
-
|
56
|
+
i18n (1.8.2)
|
57
|
+
concurrent-ruby (~> 1.0)
|
50
58
|
json (2.3.0)
|
51
59
|
launchy (2.4.3)
|
52
60
|
addressable (~> 2.3)
|
53
61
|
linguistics (2.1.0)
|
54
62
|
loggability (~> 0.11)
|
55
|
-
loggability (0.
|
63
|
+
loggability (0.17.0)
|
56
64
|
mime-types (3.3.1)
|
57
65
|
mime-types-data (~> 3.2015)
|
58
|
-
mime-types-data (3.
|
66
|
+
mime-types-data (3.2020.0512)
|
67
|
+
minitest (5.14.1)
|
59
68
|
multi_json (1.14.1)
|
60
69
|
multipart-post (2.1.1)
|
61
70
|
net-http-persistent (2.9.4)
|
62
71
|
net-http-pipeline (1.0.1)
|
63
72
|
netrc (0.11.0)
|
64
73
|
parallel (1.19.1)
|
65
|
-
parser (2.7.
|
74
|
+
parser (2.7.1.2)
|
66
75
|
ast (~> 2.4.0)
|
76
|
+
public_suffix (4.0.5)
|
67
77
|
pusher-client (0.6.2)
|
68
78
|
json
|
69
79
|
websocket (~> 1.0)
|
70
80
|
rainbow (3.0.0)
|
71
|
-
rake (
|
81
|
+
rake (13.0.1)
|
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)
|
87
|
+
rexml (3.2.4)
|
77
88
|
rspec (3.9.0)
|
78
89
|
rspec-core (~> 3.9.0)
|
79
90
|
rspec-expectations (~> 3.9.0)
|
80
91
|
rspec-mocks (~> 3.9.0)
|
81
|
-
rspec-core (3.9.
|
82
|
-
rspec-support (~> 3.9.
|
83
|
-
rspec-expectations (3.9.
|
92
|
+
rspec-core (3.9.2)
|
93
|
+
rspec-support (~> 3.9.3)
|
94
|
+
rspec-expectations (3.9.2)
|
84
95
|
diff-lcs (>= 1.2.0, < 2.0)
|
85
96
|
rspec-support (~> 3.9.0)
|
86
|
-
rspec-mocks (3.9.
|
97
|
+
rspec-mocks (3.9.1)
|
87
98
|
diff-lcs (>= 1.2.0, < 2.0)
|
88
99
|
rspec-support (~> 3.9.0)
|
89
|
-
rspec-support (3.9.
|
90
|
-
rubocop (0.
|
91
|
-
jaro_winkler (~> 1.5.1)
|
100
|
+
rspec-support (3.9.3)
|
101
|
+
rubocop (0.83.0)
|
92
102
|
parallel (~> 1.10)
|
93
|
-
parser (>= 2.
|
103
|
+
parser (>= 2.7.0.1)
|
94
104
|
rainbow (>= 2.2.2, < 4.0)
|
105
|
+
rexml
|
95
106
|
ruby-progressbar (~> 1.7)
|
96
|
-
unicode-display_width (>= 1.4.0, <
|
107
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
97
108
|
ruby-progressbar (1.10.1)
|
98
|
-
simplecov (0.
|
109
|
+
simplecov (0.18.5)
|
99
110
|
docile (~> 1.1)
|
100
|
-
|
101
|
-
|
102
|
-
|
111
|
+
simplecov-html (~> 0.11)
|
112
|
+
simplecov-html (0.12.2)
|
113
|
+
sync (0.5.0)
|
103
114
|
term-ansicolor (1.7.1)
|
104
115
|
tins (~> 1.0)
|
105
116
|
thor (0.20.3)
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
117
|
+
thread_safe (0.3.6)
|
118
|
+
tins (1.25.0)
|
119
|
+
sync
|
120
|
+
travis (1.9.1)
|
121
|
+
faraday (~> 1.0)
|
122
|
+
faraday_middleware (~> 1.0)
|
111
123
|
gh (~> 0.13)
|
112
|
-
highline (~>
|
113
|
-
|
124
|
+
highline (~> 2.0)
|
125
|
+
json (~> 2.3)
|
126
|
+
launchy (~> 2.1, < 2.5.0)
|
114
127
|
pusher-client (~> 0.4)
|
115
128
|
typhoeus (~> 0.6, >= 0.6.8)
|
116
129
|
typhoeus (0.8.0)
|
117
130
|
ethon (>= 0.8.0)
|
131
|
+
tzinfo (1.2.7)
|
132
|
+
thread_safe (~> 0.1)
|
118
133
|
unf (0.1.4)
|
119
134
|
unf_ext
|
120
|
-
unf_ext (0.0.7.
|
121
|
-
unicode-display_width (1.
|
135
|
+
unf_ext (0.0.7.7)
|
136
|
+
unicode-display_width (1.7.0)
|
122
137
|
websocket (1.2.8)
|
123
|
-
will_paginate (3.
|
124
|
-
yard (0.9.
|
138
|
+
will_paginate (3.3.0)
|
139
|
+
yard (0.9.25)
|
125
140
|
|
126
141
|
PLATFORMS
|
127
142
|
ruby
|
@@ -129,7 +144,7 @@ PLATFORMS
|
|
129
144
|
DEPENDENCIES
|
130
145
|
bundler (~> 2.0)
|
131
146
|
coveralls (~> 0.7)
|
132
|
-
rake (~>
|
147
|
+
rake (~> 13.0)
|
133
148
|
rspec (~> 3.0)
|
134
149
|
rubocop (~> 0.50)
|
135
150
|
simplecov (~> 0.17)
|
@@ -138,4 +153,4 @@ DEPENDENCIES
|
|
138
153
|
yard (~> 0.9.20)
|
139
154
|
|
140
155
|
BUNDLED WITH
|
141
|
-
2.
|
156
|
+
2.1.4
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Skull Island
|
2
2
|
|
3
|
-
A full-featured SDK for [Kong](https://konghq.com/kong/)
|
3
|
+
A full-featured SDK for [Kong](https://konghq.com/kong/) 2.0.x (with support for migrating from 0.14.x, 1.1.x, 1.2.x, 1.4.x, and 1.5.x). Note that this is unofficial (meaning this project is in no way officially endorsed, recommended, or related to Kong [as a company](https://konghq.com/) or an [open-source project](https://github.com/Kong/kong)). It is also in no way related to the [pet toy company](https://www.kongcompany.com/) by the same name (but hopefully that was obvious).
|
4
4
|
|
5
5
|
![Gem](https://img.shields.io/gem/v/skull_island)
|
6
6
|
![Travis (.org)](https://img.shields.io/travis/jgnagy/skull_island)
|
@@ -30,7 +30,7 @@ gem install skull_island
|
|
30
30
|
Or add this to your Gemfile:
|
31
31
|
|
32
32
|
```ruby
|
33
|
-
gem 'skull_island', '~>
|
33
|
+
gem 'skull_island', '~> 2.0'
|
34
34
|
```
|
35
35
|
|
36
36
|
Or add this to your .gemspec:
|
@@ -38,7 +38,7 @@ Or add this to your .gemspec:
|
|
38
38
|
```ruby
|
39
39
|
Gem::Specification.new do |spec|
|
40
40
|
# ...
|
41
|
-
spec.add_runtime_dependency 'skull_island', '~>
|
41
|
+
spec.add_runtime_dependency 'skull_island', '~> 2.0'
|
42
42
|
# ...
|
43
43
|
end
|
44
44
|
```
|
@@ -149,17 +149,17 @@ When using the `project` feature of Skull Island, the CLI tool will automaticall
|
|
149
149
|
|
150
150
|
### Migrating
|
151
151
|
|
152
|
-
With Skull Island, it is possible to migrate a configuration from a 0.14.x, 1.1.x, or 1.
|
152
|
+
With Skull Island, it is possible to migrate a configuration from a 0.14.x, 1.1.x, 1.2.x, 1.4.x, or 1.5.x gateway to the most recent compatible gateway. If you have a previous export, you can just run `skull_island migrate /path/to/export.yml` and you'll receive a 2.0 compatible config on standard out. If you'd prefer, you can have that config written to a file as well (just like the export command) like so:
|
153
153
|
|
154
154
|
```sh
|
155
155
|
skull_island migrate /path/to/export.yml /output/location/migrated.yml
|
156
156
|
```
|
157
157
|
|
158
|
-
While this hasn't been heavily tested for all possible use-cases, any configuration generated or usable by the `'~> 0.14'
|
158
|
+
While this hasn't been heavily tested for all possible use-cases, any configuration generated or usable by the `'~> 0.14'`, `'~> 1.2'`, or `~> 1.4` version of this gem should safely convert using the migration command. This tool also makes no guarantees about plugin functionality, configuration compatibility across versions, or that the same plugins are installed and available in your newer gateway. It should go without saying that you should **test and confirm** that all of your functionality was successfully migrated.
|
159
159
|
|
160
160
|
If you don't have a previous export, you'll need to install an older version of this gem using something like `gem install --version '~> 0.14' skull_island`, then perform an `export`, then you can switch back to the latest version of the gem for migrating and importing.
|
161
161
|
|
162
|
-
While it would be possible to make migration _automatic_ for the `import` command, `skull_island` intentionally doesn't do this to avoid the appearance that the config is losslessly compatible across versions. In reality, the newer config version has additional features (like tagging) that are used heavily by skull_island. It makes sense to this author to maintain the migration component and the normal functionality as distinct features to encourage the use of the newer capabilities in 1.1 and beyond. That said, Skull Island does allow 1.1 and 1.
|
162
|
+
While it would be possible to make migration _automatic_ for the `import` command, `skull_island` intentionally doesn't do this to avoid the appearance that the config is losslessly compatible across versions. In reality, the newer config version has additional features (like tagging) that are used heavily by skull_island. It makes sense to this author to maintain the migration component and the normal functionality as distinct features to encourage the use of the newer capabilities in 1.1 and beyond. That said, Skull Island does allow 1.1, 1.2, and 1.4 version configurations to be applied to 2.0 gateways, but not the opposite.
|
163
163
|
|
164
164
|
### Reset A Gateway
|
165
165
|
|
@@ -188,7 +188,7 @@ If you're wondering what version of `skull_island` is installed, use:
|
|
188
188
|
```sh
|
189
189
|
$ skull_island version
|
190
190
|
|
191
|
-
SkullIsland Version:
|
191
|
+
SkullIsland Version: 2.0.0
|
192
192
|
```
|
193
193
|
|
194
194
|
### File Format
|
@@ -197,7 +197,7 @@ The import/export/migrate CLI functions produce YAML with support for embedded R
|
|
197
197
|
|
198
198
|
```yaml
|
199
199
|
---
|
200
|
-
version: '
|
200
|
+
version: '2.0'
|
201
201
|
project: FooV2
|
202
202
|
certificates: []
|
203
203
|
ca_certificates:
|
@@ -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
|
|
@@ -398,7 +398,7 @@ service.routes.size
|
|
398
398
|
# => 4
|
399
399
|
```
|
400
400
|
|
401
|
-
From here, the SDK mostly wraps the attributes described in the [Kong API Docs](https://docs.konghq.com/
|
401
|
+
From here, the SDK mostly wraps the attributes described in the [Kong API Docs](https://docs.konghq.com/2.0.x/admin-api/). For simplicity, I'll go over the resource types and attributes this SDK supports manipulating. Rely on the API documentation to determine which attributes are required and under which conditions.
|
402
402
|
|
403
403
|
#### CA Certificates
|
404
404
|
|
@@ -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
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Core Extensions
|
4
|
+
require 'core_extensions/string/transformations'
|
5
|
+
require 'core_extensions/hash/pruning'
|
6
|
+
String.include CoreExtensions::String::Transformations
|
7
|
+
Hash.include CoreExtensions::Hash::Pruning
|
8
|
+
|
3
9
|
# Standard Library Requirements
|
4
10
|
require 'date'
|
5
11
|
require 'digest'
|
@@ -18,9 +24,6 @@ require 'will_paginate'
|
|
18
24
|
require 'will_paginate/array'
|
19
25
|
|
20
26
|
# Internal Requirements
|
21
|
-
require 'core_extensions/string/transformations'
|
22
|
-
String.include CoreExtensions::String::Transformations
|
23
|
-
|
24
27
|
require 'skull_island/version'
|
25
28
|
require 'skull_island/api_exception'
|
26
29
|
require 'skull_island/exceptions/ambiguous_find'
|
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' => '
|
33
|
+
output = { 'version' => '2.0' }
|
34
34
|
output['project'] = options['project'] if options['project']
|
35
35
|
|
36
36
|
[
|
@@ -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'].include?(version)
|
194
|
+
if version && ['1.1', '1.2', '1.4', '1.5', '2.0'].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`.'
|
@@ -203,17 +203,17 @@ module SkullIsland
|
|
203
203
|
end
|
204
204
|
|
205
205
|
def validate_migrate_version(version)
|
206
|
-
if version && ['0.14', '1.0', '1.1', '1.2'].include?(version)
|
206
|
+
if version && ['0.14', '1.0', '1.1', '1.2', '1.4', '1.5'].include?(version)
|
207
207
|
true
|
208
208
|
else
|
209
|
-
warn '[CRITICAL] Config version must be 0.14 or 1.0-1.
|
209
|
+
warn '[CRITICAL] Config version must be 0.14 or 1.0-1.5 for migration.'
|
210
210
|
exit 4
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
214
214
|
def validate_server_version
|
215
215
|
server_version = SkullIsland::APIClient.about_service['version']
|
216
|
-
if server_version.match?(/^
|
216
|
+
if server_version.match?(/^2.0/)
|
217
217
|
true
|
218
218
|
else
|
219
219
|
warn '[CRITICAL] Server version mismatch!'
|
@@ -8,7 +8,11 @@ module SkullIsland
|
|
8
8
|
if config['version'] == '0.14'
|
9
9
|
migrate_config migrate_0_14_to_1_1(config)
|
10
10
|
elsif ['1.0', '1.1', '1.2', '1.3'].include?(config['version'])
|
11
|
-
migrate_1_1_to_1_4(config)
|
11
|
+
migrate_config migrate_1_1_to_1_4(config)
|
12
|
+
elsif config['version'] == '1.4'
|
13
|
+
migrate_config migrate_1_4_to_1_5(config)
|
14
|
+
elsif config['version'] == '1.5'
|
15
|
+
migrate_1_5_to_2_0(config)
|
12
16
|
else
|
13
17
|
false # Just return false if it can't be migrated
|
14
18
|
end
|
@@ -37,6 +41,18 @@ module SkullIsland
|
|
37
41
|
new_config['version'] = '1.4'
|
38
42
|
new_config
|
39
43
|
end
|
44
|
+
|
45
|
+
def migrate_1_4_to_1_5(config)
|
46
|
+
new_config = config.dup
|
47
|
+
new_config['version'] = '1.5'
|
48
|
+
new_config
|
49
|
+
end
|
50
|
+
|
51
|
+
def migrate_1_5_to_2_0(config)
|
52
|
+
new_config = config.dup
|
53
|
+
new_config['version'] = '2.0'
|
54
|
+
new_config
|
55
|
+
end
|
40
56
|
end
|
41
57
|
end
|
42
58
|
end
|
@@ -105,19 +105,22 @@ module SkullIsland
|
|
105
105
|
# rubocop:enable Metrics/CyclomaticComplexity
|
106
106
|
# rubocop:enable Metrics/PerceivedComplexity
|
107
107
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
108
|
+
# Looks up IDs (and usually wraps them in a Hash)
|
109
|
+
def lookup(type, value, raw = false)
|
110
|
+
id_value = case type
|
111
|
+
when :consumer
|
112
|
+
Resources::Consumer.find(:username, value).id
|
113
|
+
when :route
|
114
|
+
Resources::Route.find(:name, value).id
|
115
|
+
when :service
|
116
|
+
Resources::Service.find(:name, value).id
|
117
|
+
when :upstream
|
118
|
+
Resources::Upstream.find(:name, value).id
|
119
|
+
else
|
120
|
+
raise Exceptions::InvalidArguments, "#{type} is not a valid lookup type"
|
121
|
+
end
|
122
|
+
|
123
|
+
raw ? id_value : { 'id' => id_value }
|
121
124
|
end
|
122
125
|
|
123
126
|
# ActiveRecord ActiveModel::Name compatibility method
|
@@ -179,8 +179,10 @@ module SkullIsland
|
|
179
179
|
)
|
180
180
|
end
|
181
181
|
|
182
|
-
def self.cleanup_except(project, keep_these)
|
183
|
-
where(:project, project)
|
182
|
+
def self.cleanup_except(project, keep_these, from_these = nil)
|
183
|
+
old_resources = from_these || where(:project, project)
|
184
|
+
|
185
|
+
old_resources.reject { |res| keep_these.include?(res.id) }.map do |res|
|
184
186
|
puts "[WARN] ! Removing #{name} (#{res.id})"
|
185
187
|
res.destroy
|
186
188
|
end
|
@@ -102,9 +102,10 @@ module SkullIsland
|
|
102
102
|
end
|
103
103
|
|
104
104
|
# Used to validate {#algorithm} on set
|
105
|
+
# @see https://github.com/Kong/kong/blob/master/kong/plugins/jwt/daos.lua#L29
|
105
106
|
def validate_algorithm(value)
|
106
107
|
# allow a String
|
107
|
-
%w[HS256 HS384 HS512 RS256 ES256].include? value
|
108
|
+
%w[HS256 HS384 HS512 RS256 RS512 ES256].include? value
|
108
109
|
end
|
109
110
|
|
110
111
|
# Used to validate {#key} on set
|
@@ -43,6 +43,8 @@ module SkullIsland
|
|
43
43
|
end
|
44
44
|
|
45
45
|
cleanup_except(project, known_ids) if project
|
46
|
+
|
47
|
+
known_ids
|
46
48
|
end
|
47
49
|
# rubocop:enable Metrics/CyclomaticComplexity
|
48
50
|
# rubocop:enable Metrics/PerceivedComplexity
|
@@ -52,7 +54,7 @@ module SkullIsland
|
|
52
54
|
end
|
53
55
|
|
54
56
|
def self.schema(name, api_client: APIClient.instance)
|
55
|
-
api_client.get("
|
57
|
+
api_client.get("/schemas/plugins/#{name}")
|
56
58
|
end
|
57
59
|
|
58
60
|
def digest_properties
|
@@ -117,7 +119,7 @@ module SkullIsland
|
|
117
119
|
end
|
118
120
|
|
119
121
|
def postprocess_config(value)
|
120
|
-
value.deep_sort.compact
|
122
|
+
value.deep_sort.prune.compact
|
121
123
|
end
|
122
124
|
|
123
125
|
def postprocess_consumer(value)
|
@@ -20,6 +20,7 @@ module SkullIsland
|
|
20
20
|
property :strip_path, type: :boolean
|
21
21
|
property :preserve_host, type: :boolean
|
22
22
|
property :snis, validate: true
|
23
|
+
property :path_handling, validate: true
|
23
24
|
property :sources
|
24
25
|
property :destinations
|
25
26
|
property :service, validate: true, preprocess: true, postprocess: true
|
@@ -30,7 +31,8 @@ module SkullIsland
|
|
30
31
|
# rubocop:disable Metrics/CyclomaticComplexity
|
31
32
|
# rubocop:disable Metrics/PerceivedComplexity
|
32
33
|
# rubocop:disable Metrics/AbcSize
|
33
|
-
|
34
|
+
# rubocop:disable Layout/LineLength
|
35
|
+
def self.batch_import(data, verbose: false, test: false, project: nil, time: nil, cleanup: true)
|
34
36
|
raise(Exceptions::InvalidArguments) unless data.is_a?(Array)
|
35
37
|
|
36
38
|
known_ids = []
|
@@ -58,11 +60,14 @@ module SkullIsland
|
|
58
60
|
known_ids << resource.id
|
59
61
|
end
|
60
62
|
|
61
|
-
cleanup_except(project, known_ids) if project
|
63
|
+
cleanup_except(project, known_ids) if project && cleanup
|
64
|
+
|
65
|
+
known_ids
|
62
66
|
end
|
63
67
|
# rubocop:enable Metrics/CyclomaticComplexity
|
64
68
|
# rubocop:enable Metrics/PerceivedComplexity
|
65
69
|
# rubocop:enable Metrics/AbcSize
|
70
|
+
# rubocop:enable Layout/LineLength
|
66
71
|
|
67
72
|
# Provides a collection of related {Plugin} instances
|
68
73
|
def plugins
|
@@ -135,6 +140,12 @@ module SkullIsland
|
|
135
140
|
end
|
136
141
|
end
|
137
142
|
|
143
|
+
# Used to validate {#path_handling} on set
|
144
|
+
def validate_path_handling(value)
|
145
|
+
valid_values = %w[v0 v1]
|
146
|
+
valid_values.include?(value)
|
147
|
+
end
|
148
|
+
|
138
149
|
# Used to validate {#protocols} on set
|
139
150
|
def validate_protocols(value)
|
140
151
|
valid_protos = %w[http https tls tcp grpc grpcs]
|
@@ -49,16 +49,23 @@ module SkullIsland
|
|
49
49
|
resource.import_update_or_skip(index: index, verbose: verbose, test: test)
|
50
50
|
known_ids << resource.id
|
51
51
|
|
52
|
-
|
52
|
+
previous_routes = resource.routes.dup
|
53
|
+
|
54
|
+
added_routes = Route.batch_import(
|
53
55
|
(rdata['routes'] || []).map { |r| r.merge('service' => { 'id' => resource.id }) },
|
54
56
|
verbose: verbose,
|
55
57
|
test: test,
|
56
58
|
project: project,
|
57
|
-
time: time
|
59
|
+
time: time,
|
60
|
+
cleanup: false
|
58
61
|
)
|
62
|
+
|
63
|
+
Route.cleanup_except(project, added_routes, previous_routes)
|
59
64
|
end
|
60
65
|
|
61
66
|
cleanup_except(project, known_ids) if project
|
67
|
+
|
68
|
+
known_ids
|
62
69
|
end
|
63
70
|
# rubocop:enable Metrics/CyclomaticComplexity
|
64
71
|
# rubocop:enable Metrics/PerceivedComplexity
|
@@ -116,7 +123,7 @@ module SkullIsland
|
|
116
123
|
def modified_existing?
|
117
124
|
return false unless new?
|
118
125
|
|
119
|
-
# Find
|
126
|
+
# Find services of the same name
|
120
127
|
same_name = self.class.where(:name, name)
|
121
128
|
|
122
129
|
existing = same_name.size == 1 ? same_name.first : nil
|
@@ -18,7 +18,7 @@ module SkullIsland
|
|
18
18
|
property :hash_fallback_header, validate: true
|
19
19
|
property :hash_on_cookie, validate: true
|
20
20
|
property :hash_on_cookie_path, validate: true
|
21
|
-
property :healthchecks, validate: true
|
21
|
+
property :healthchecks, validate: true, postprocess: true
|
22
22
|
property :host_header, validate: true
|
23
23
|
property :created_at, read_only: true, postprocess: true
|
24
24
|
property :tags, validate: true, preprocess: true, postprocess: true
|
@@ -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
|
@@ -160,6 +162,11 @@ module SkullIsland
|
|
160
162
|
|
161
163
|
private
|
162
164
|
|
165
|
+
# Prunes empty values from the healthchecks Hash
|
166
|
+
def postprocess_healthchecks(value)
|
167
|
+
value.is_a?(Hash) ? value.prune : value
|
168
|
+
end
|
169
|
+
|
163
170
|
# Validates the upstream balancing {#algorithm}
|
164
171
|
def validate_algorithm(value)
|
165
172
|
%w[round-robin consistent-hashing least-connections].include?(value)
|
data/lib/skull_island/version.rb
CHANGED
data/skull_island.gemspec
CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
|
|
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', '~>
|
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:
|
4
|
+
version: 2.0.5
|
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-
|
11
|
+
date: 2020-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deepsort
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
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: '
|
152
|
+
version: '13.0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: rspec
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -241,6 +241,7 @@ files:
|
|
241
241
|
- bin/console
|
242
242
|
- bin/setup
|
243
243
|
- exe/skull_island
|
244
|
+
- lib/core_extensions/hash/pruning.rb
|
244
245
|
- lib/core_extensions/string/transformations.rb
|
245
246
|
- lib/skull_island.rb
|
246
247
|
- lib/skull_island/api_client.rb
|
@@ -305,8 +306,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
305
306
|
- !ruby/object:Gem::Version
|
306
307
|
version: '0'
|
307
308
|
requirements: []
|
308
|
-
|
309
|
-
rubygems_version: 2.7.7
|
309
|
+
rubygems_version: 3.0.8
|
310
310
|
signing_key:
|
311
311
|
specification_version: 4
|
312
312
|
summary: Ruby SDK for Kong
|