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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a77eb790a5c2e9bc9041918244f463890a598b48
4
- data.tar.gz: 76815d46d5c50a3d6cc01aee03d13b6b0f870ee0
3
+ metadata.gz: 48d76ad569bf581b7da42eb3f0d82b2c777bc256
4
+ data.tar.gz: f21ff4a308efbd39ecd22d65a3dd0d20ba5b9b26
5
5
  SHA512:
6
- metadata.gz: 8186d7fb699bf6ae80f6534fc66aeedc735dcef9594f063d498361d02375a152fb0efb9e33080ee025928333c9cb1662d8b91ef76647a378fd341d3b9d440edf
7
- data.tar.gz: 8522830249a8c888dd7ab6dcc5712921e80c8fedc13ffb152f250574e8d405fa94d7da9cea8760348376696e0a3b58fefb3c3a02a91b6c720260a0d7ff421817
6
+ metadata.gz: 7f5281d2c489ebced5f8b9b9353c943b928f128bad0f203b1e30b9e8d726012b92a45b21df7c1833131ae9fdb2a26d2c51290a4d686b749eb2dcd62ad06b31c9
7
+ data.tar.gz: d3d1eeb1f5658d4e8687c0da35f6853c408d6d09a6435d43778e31b524f4ac71c3733693dd2e0b2729863cbd4ec688601bf6c30d13328e0b387b40d0a51c0dde
data/.gitignore CHANGED
@@ -1,4 +1,3 @@
1
1
  /.bundle
2
2
  /coverage
3
- /bin
4
3
  /*.gem
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.3.1
2
+
3
+ - Fixed an issue that was preventing Kong::Plugin objects from being created
4
+ without an api
5
+
1
6
  ## 1.3.0
2
7
 
3
8
  - Added support for Kong::Plugin objects.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kong_schema (1.2.0)
4
+ kong_schema (1.3.1)
5
5
  diffy (~> 3.1)
6
6
  gli (~> 2.16)
7
7
  kong (~> 0.3)
@@ -13,9 +13,17 @@ module KongSchema
13
13
  def identify(record)
14
14
  case record
15
15
  when Kong::Plugin
16
- [ record.name, try(record.api, :name), record.consumer_id ]
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
- [ record['name'], record['api_id'], record['consumer_id'] ]
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('api_id' => record.api.id)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KongSchema
4
- VERSION = "1.3.0".freeze
4
+ VERSION = "1.3.1".freeze
5
5
  end
@@ -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 'adds a plugin if it does not exist' do
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 'does add a plugin' do
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 'updates a plugin' do
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
- with_update = test_utils.generate_config({
53
- apis: [{
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
- plugins: [{
60
- config: plugin_config.merge({ second: 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(with_update)) }.to change {
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kong_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmad Amireh