kong_schema 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/lib/kong_schema/resource/plugin.rb +23 -3
- data/lib/kong_schema/version.rb +1 -1
- data/spec/kong_schema/resource/plugin_spec.rb +42 -33
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48d76ad569bf581b7da42eb3f0d82b2c777bc256
|
4
|
+
data.tar.gz: f21ff4a308efbd39ecd22d65a3dd0d20ba5b9b26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f5281d2c489ebced5f8b9b9353c943b928f128bad0f203b1e30b9e8d726012b92a45b21df7c1833131ae9fdb2a26d2c51290a4d686b749eb2dcd62ad06b31c9
|
7
|
+
data.tar.gz: d3d1eeb1f5658d4e8687c0da35f6853c408d6d09a6435d43778e31b524f4ac71c3733693dd2e0b2729863cbd4ec688601bf6c30d13328e0b387b40d0a51c0dde
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -13,9 +13,17 @@ module KongSchema
|
|
13
13
|
def identify(record)
|
14
14
|
case record
|
15
15
|
when Kong::Plugin
|
16
|
-
[
|
16
|
+
[
|
17
|
+
record.name,
|
18
|
+
api_bound?(record) ? record.api.name : nil,
|
19
|
+
consumer_bound?(record) ? record.consumer_id : nil
|
20
|
+
]
|
17
21
|
when Hash
|
18
|
-
[
|
22
|
+
[
|
23
|
+
record['name'],
|
24
|
+
record['api_id'] || nil,
|
25
|
+
record['consumer_id'] || nil
|
26
|
+
]
|
19
27
|
end
|
20
28
|
end
|
21
29
|
|
@@ -52,7 +60,9 @@ module KongSchema
|
|
52
60
|
else
|
53
61
|
Adapter.for(Kong::Plugin).update(
|
54
62
|
record,
|
55
|
-
partial_attributes.merge(
|
63
|
+
partial_attributes.merge(
|
64
|
+
'api_id' => api_bound?(record) ? record.api.id : nil
|
65
|
+
)
|
56
66
|
)
|
57
67
|
end
|
58
68
|
end
|
@@ -60,6 +70,16 @@ module KongSchema
|
|
60
70
|
def delete(record)
|
61
71
|
Adapter.for(Kong::Plugin).delete(record)
|
62
72
|
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def api_bound?(record)
|
77
|
+
!blank?(record.api_id)
|
78
|
+
end
|
79
|
+
|
80
|
+
def consumer_bound?(record)
|
81
|
+
!blank?(record.consumer_id)
|
82
|
+
end
|
63
83
|
end
|
64
84
|
end
|
65
85
|
end
|
data/lib/kong_schema/version.rb
CHANGED
@@ -9,6 +9,26 @@ describe KongSchema::Resource::Plugin do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
let :config do
|
12
|
+
test_utils.generate_config({
|
13
|
+
plugins: [{
|
14
|
+
name: 'rate-limiting',
|
15
|
+
enabled: true,
|
16
|
+
config: plugin_config
|
17
|
+
}]
|
18
|
+
})
|
19
|
+
end
|
20
|
+
|
21
|
+
let :config_with_custom_options do
|
22
|
+
test_utils.generate_config({
|
23
|
+
plugins: [{
|
24
|
+
name: 'rate-limiting',
|
25
|
+
enabled: true,
|
26
|
+
config: plugin_config.merge({ second: 60 }),
|
27
|
+
}]
|
28
|
+
})
|
29
|
+
end
|
30
|
+
|
31
|
+
let :config_with_api do
|
12
32
|
test_utils.generate_config({
|
13
33
|
apis: [{
|
14
34
|
name: 'my-api',
|
@@ -25,16 +45,13 @@ describe KongSchema::Resource::Plugin do
|
|
25
45
|
})
|
26
46
|
end
|
27
47
|
|
28
|
-
it '
|
48
|
+
it 'identifies plugins to be added' do
|
29
49
|
directives = schema.scan(config)
|
30
50
|
|
31
|
-
expect(directives.map(&:class)).to eq([
|
32
|
-
KongSchema::Actions::Create,
|
33
|
-
KongSchema::Actions::Create
|
34
|
-
])
|
51
|
+
expect(directives.map(&:class)).to eq([ KongSchema::Actions::Create ])
|
35
52
|
end
|
36
53
|
|
37
|
-
it '
|
54
|
+
it 'adds a plugin' do
|
38
55
|
directives = schema.scan(config)
|
39
56
|
|
40
57
|
expect {
|
@@ -46,24 +63,29 @@ describe KongSchema::Resource::Plugin do
|
|
46
63
|
}.by(1)
|
47
64
|
end
|
48
65
|
|
49
|
-
it '
|
66
|
+
it 'adds a plugin with an api' do
|
67
|
+
directives = schema.scan(config_with_api)
|
68
|
+
|
69
|
+
expect {
|
70
|
+
schema.commit(config_with_api, directives)
|
71
|
+
}.to change {
|
72
|
+
KongSchema::Client.connect(config_with_api) {
|
73
|
+
Kong::Plugin.all.count
|
74
|
+
}
|
75
|
+
}.by(1)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'identifies plugins to be updated' do
|
50
79
|
schema.commit(config, schema.scan(config))
|
80
|
+
changes = schema.scan(config_with_custom_options)
|
51
81
|
|
52
|
-
|
53
|
-
|
54
|
-
name: 'my-api',
|
55
|
-
upstream_url: 'http://example.com',
|
56
|
-
hosts: [ 'example.com' ]
|
57
|
-
}],
|
82
|
+
expect(changes.map(&:class)).to eq([ KongSchema::Actions::Update ])
|
83
|
+
end
|
58
84
|
|
59
|
-
|
60
|
-
|
61
|
-
name: 'rate-limiting',
|
62
|
-
api_id: 'my-api',
|
63
|
-
}]
|
64
|
-
})
|
85
|
+
it 'updates a plugin' do
|
86
|
+
schema.commit(config, schema.scan(config))
|
65
87
|
|
66
|
-
expect { schema.commit(config, schema.scan(
|
88
|
+
expect { schema.commit(config, schema.scan(config_with_custom_options)) }.to change {
|
67
89
|
KongSchema::Client.connect(config) {
|
68
90
|
Kong::Plugin.find_by_name('rate-limiting').config['second']
|
69
91
|
}
|
@@ -74,15 +96,8 @@ describe KongSchema::Resource::Plugin do
|
|
74
96
|
schema.commit(config, schema.scan(config))
|
75
97
|
|
76
98
|
with_update = test_utils.generate_config({
|
77
|
-
apis: [{
|
78
|
-
name: 'my-api',
|
79
|
-
upstream_url: 'http://example.com',
|
80
|
-
hosts: [ 'example.com' ]
|
81
|
-
}],
|
82
|
-
|
83
99
|
plugins: [{
|
84
100
|
name: 'rate-limiting',
|
85
|
-
api_id: 'my-api',
|
86
101
|
config: plugin_config,
|
87
102
|
enabled: false
|
88
103
|
}]
|
@@ -99,12 +114,6 @@ describe KongSchema::Resource::Plugin do
|
|
99
114
|
schema.commit(config, schema.scan(config))
|
100
115
|
|
101
116
|
with_removal = test_utils.generate_config({
|
102
|
-
apis: [{
|
103
|
-
name: 'my-api',
|
104
|
-
upstream_url: 'http://example.com',
|
105
|
-
hosts: [ 'example.com' ]
|
106
|
-
}],
|
107
|
-
|
108
117
|
plugins: []
|
109
118
|
})
|
110
119
|
|