kong 0.3.2 → 0.3.3
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 +4 -4
- data/.rubocop.yml +27 -31
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -2
- data/README.md +2 -2
- data/lib/kong/base.rb +9 -6
- data/lib/kong/client.rb +1 -3
- data/lib/kong/plugin.rb +11 -11
- data/lib/kong/util.rb +16 -0
- data/lib/kong/version.rb +1 -1
- data/lib/kong.rb +3 -0
- data/spec/kong/base_spec.rb +8 -8
- data/spec/kong/plugin_spec.rb +20 -4
- data/spec/kong/util_spec.rb +29 -0
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 128c39dcd5396b44c6ea3489766feb2f330ffd61
|
|
4
|
+
data.tar.gz: 06ea2dfe3e8a7f768274d72dad955fd255dd47b8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e6e526da140002b3b139eccd3fba81a9477432d584c15b9b67ab8390948aa73f9d800a452d886f4fa34c6fe6bc65dd59ff847a523aa1ef10fca3c6d2a7561857
|
|
7
|
+
data.tar.gz: 15d3f6f50314fdd9b240b656369c68706b252ea35c68ebc32c250e8a9cd706af5bc077d4f27efd5f984f4dcb11e83fc311e01b55bb8b08578b3d5d731184a757
|
data/.rubocop.yml
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
AllCops:
|
|
2
2
|
DisabledByDefault: true
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Layout/IndentationConsistency:
|
|
5
5
|
Enabled: true
|
|
6
6
|
AutoCorrect: true
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Layout/CommentIndentation:
|
|
9
9
|
Enabled: true
|
|
10
10
|
AutoCorrect: true
|
|
11
11
|
|
|
12
12
|
Style/NestedModifier:
|
|
13
13
|
Enabled: true
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Layout/IndentArray:
|
|
16
16
|
Enabled: true
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Layout/AlignArray:
|
|
19
19
|
Enabled: true
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Layout/AlignHash:
|
|
22
22
|
Enabled: true
|
|
23
23
|
|
|
24
24
|
#Lint/EmptyInterpolation:
|
|
@@ -141,7 +141,7 @@ Metrics/MethodLength:
|
|
|
141
141
|
Max: 40
|
|
142
142
|
Severity: refactor
|
|
143
143
|
|
|
144
|
-
|
|
144
|
+
Layout/Tab:
|
|
145
145
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#tabs
|
|
146
146
|
Enabled: true
|
|
147
147
|
|
|
@@ -152,7 +152,7 @@ Metrics/ParameterLists:
|
|
|
152
152
|
Max: 5
|
|
153
153
|
CountKeywordArgs: true
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
Layout/IndentationWidth:
|
|
156
156
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#tabs
|
|
157
157
|
Enabled: true
|
|
158
158
|
|
|
@@ -161,41 +161,41 @@ Metrics/LineLength:
|
|
|
161
161
|
Max: 120
|
|
162
162
|
Enabled: false
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
Layout/TrailingWhitespace:
|
|
165
165
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#no-trailing-whitespace
|
|
166
166
|
Enabled: true
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
Layout/TrailingBlankLines:
|
|
169
169
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#end-file-newline
|
|
170
170
|
EnforcedStyle: final_newline
|
|
171
171
|
|
|
172
|
-
|
|
172
|
+
Layout/SpaceAroundOperators:
|
|
173
173
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#spaces-around-operators
|
|
174
174
|
Enabled: true
|
|
175
175
|
AllowForAlignment: true
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
|
178
178
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#spaces-around-operators
|
|
179
179
|
EnforcedStyle: space
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
Layout/SpaceAfterComma:
|
|
182
182
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#spaces-around-operators
|
|
183
183
|
Enabled: true
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
Layout/SpaceAfterColon:
|
|
186
186
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#spaces-around-operators
|
|
187
187
|
Enabled: true
|
|
188
188
|
|
|
189
|
-
|
|
189
|
+
Layout/SpaceAfterSemicolon:
|
|
190
190
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#spaces-around-operators
|
|
191
191
|
Enabled: true
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
Layout/SpaceBeforeBlockBraces:
|
|
194
194
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#spaces-around-operators
|
|
195
195
|
Enabled: true
|
|
196
196
|
EnforcedStyle: space
|
|
197
197
|
|
|
198
|
-
|
|
198
|
+
Layout/SpaceInsideBlockBraces:
|
|
199
199
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#spaces-around-operators
|
|
200
200
|
Enabled: true
|
|
201
201
|
EnforcedStyle: space
|
|
@@ -204,34 +204,34 @@ Style/SpaceInsideBlockBraces:
|
|
|
204
204
|
# Space between { and |. Overrides EnforcedStyle if there is a conflict.
|
|
205
205
|
SpaceBeforeBlockParameters: true
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
Layout/SpaceInsideHashLiteralBraces:
|
|
208
208
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#spaces-around-operators
|
|
209
209
|
Enabled: true
|
|
210
210
|
EnforcedStyle: space
|
|
211
211
|
EnforcedStyleForEmptyBraces: no_space
|
|
212
212
|
|
|
213
|
-
|
|
213
|
+
Layout/SpaceInsideStringInterpolation:
|
|
214
214
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#spaces-around-operators
|
|
215
215
|
Enabled: true
|
|
216
216
|
EnforcedStyle: no_space
|
|
217
217
|
|
|
218
|
-
|
|
218
|
+
Layout/SpaceInsideParens:
|
|
219
219
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#no-spaces-around-delimiters
|
|
220
220
|
Enabled: true
|
|
221
221
|
|
|
222
|
-
|
|
222
|
+
Layout/SpaceInsideBrackets:
|
|
223
223
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#no-spaces-around-delimiters
|
|
224
224
|
Enabled: true
|
|
225
225
|
|
|
226
|
-
|
|
226
|
+
Layout/CaseIndentation:
|
|
227
227
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#case-indentation
|
|
228
228
|
Enabled: true
|
|
229
229
|
|
|
230
|
-
|
|
230
|
+
Layout/ElseAlignment:
|
|
231
231
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#case-indentation
|
|
232
232
|
Enabled: true
|
|
233
233
|
|
|
234
|
-
|
|
234
|
+
Layout/RescueEnsureAlignment:
|
|
235
235
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#case-indentation
|
|
236
236
|
Enabled: true
|
|
237
237
|
|
|
@@ -240,11 +240,11 @@ Lint/EndAlignment:
|
|
|
240
240
|
Enabled: true
|
|
241
241
|
AutoCorrect: true
|
|
242
242
|
|
|
243
|
-
|
|
243
|
+
Layout/SpaceAfterNot:
|
|
244
244
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#no-space-after-not
|
|
245
245
|
Enabled: true
|
|
246
246
|
|
|
247
|
-
|
|
247
|
+
Layout/EmptyLineBetweenDefs:
|
|
248
248
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#lines-between-defs
|
|
249
249
|
Enabled: true
|
|
250
250
|
AllowAdjacentOneLineDefs: false
|
|
@@ -295,10 +295,6 @@ Style/RedundantReturn:
|
|
|
295
295
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#avoid-return
|
|
296
296
|
Enabled: true
|
|
297
297
|
|
|
298
|
-
Style/SpaceAroundEqualsInParameterDefault:
|
|
299
|
-
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#space-around-param-default
|
|
300
|
-
Enabled: true
|
|
301
|
-
|
|
302
298
|
Style/PerlBackrefs:
|
|
303
299
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#no-perlisms
|
|
304
300
|
Enabled: true
|
|
@@ -307,7 +303,7 @@ Style/SpecialGlobalVars:
|
|
|
307
303
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#no-perlisms
|
|
308
304
|
Enabled: true
|
|
309
305
|
|
|
310
|
-
|
|
306
|
+
Layout/SpaceAfterMethodName:
|
|
311
307
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#no-space-after-method-name
|
|
312
308
|
Enabled: true
|
|
313
309
|
|
|
@@ -325,7 +321,7 @@ Style/ClassVars:
|
|
|
325
321
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#class-vars
|
|
326
322
|
Enabled: true
|
|
327
323
|
|
|
328
|
-
|
|
324
|
+
Layout/AccessModifierIndentation:
|
|
329
325
|
StyleGuide: https://github.com/backupify/backupify_styleguides/blob/master/RubyStyleguide.md#access-modifier-indent
|
|
330
326
|
Enabled: true
|
|
331
327
|
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# 0.3.3 (2018-09-07)
|
|
2
|
+
- Switch to application json content type ([#28](https://github.com/kontena/kong-client-ruby/pull/28))
|
|
3
|
+
- Flatten nested plugin config items ([#27](https://github.com/kontena/kong-client-ruby/pull/27))
|
|
4
|
+
|
|
5
|
+
# 0.3.2 (2018-02-05)
|
|
6
|
+
- Remove Excon version dependency ([#25](https://github.com/kontena/kong-client-ruby/pull/25))
|
|
7
|
+
|
|
1
8
|
# 0.3.1 (2017-10-02)
|
|
2
9
|
- Use consumer id to retrieve auth keys and tokens ([#19](https://github.com/kontena/kong-client-ruby/pull/19))
|
|
3
10
|
- Add methods to kong api base attributes ([#21](https://github.com/kontena/kong-client-ruby/pull/21))
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -89,9 +89,9 @@ Kong::Api.create(attributes)
|
|
|
89
89
|
|
|
90
90
|
api = Kong::Api.new({
|
|
91
91
|
name: 'Mockbin',
|
|
92
|
-
hosts: ['
|
|
92
|
+
hosts: ['example.com'],
|
|
93
93
|
uris: ['/someservice'],
|
|
94
|
-
methods: ['GET']
|
|
94
|
+
methods: ['GET'],
|
|
95
95
|
strip_uri: false,
|
|
96
96
|
preserve_host: false,
|
|
97
97
|
upstream_url: 'https://mockbin.com'
|
data/lib/kong/base.rb
CHANGED
|
@@ -83,7 +83,6 @@ module Kong
|
|
|
83
83
|
Client.instance
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
-
|
|
87
86
|
# Get resource
|
|
88
87
|
# @param [String] key
|
|
89
88
|
def get(key = nil)
|
|
@@ -104,6 +103,10 @@ module Kong
|
|
|
104
103
|
self.id.nil?
|
|
105
104
|
end
|
|
106
105
|
|
|
106
|
+
def primary_key
|
|
107
|
+
self.new? ? self.name : self.id
|
|
108
|
+
end
|
|
109
|
+
|
|
107
110
|
# Save resource to Kong
|
|
108
111
|
def save
|
|
109
112
|
create_or_update
|
|
@@ -111,8 +114,8 @@ module Kong
|
|
|
111
114
|
|
|
112
115
|
# Create resource
|
|
113
116
|
def create
|
|
114
|
-
headers = { 'Content-Type' => 'application/
|
|
115
|
-
response = client.post(@api_end_point,
|
|
117
|
+
headers = { 'Content-Type' => 'application/json' }
|
|
118
|
+
response = client.post(@api_end_point, attributes, nil, headers)
|
|
116
119
|
init_attributes(response)
|
|
117
120
|
self
|
|
118
121
|
end
|
|
@@ -121,15 +124,15 @@ module Kong
|
|
|
121
124
|
# Data is sent to Kong in JSON format and HTTP PUT request is used
|
|
122
125
|
def create_or_update
|
|
123
126
|
headers = { 'Content-Type' => 'application/json' }
|
|
124
|
-
response = client.put(
|
|
127
|
+
response = client.put(@api_end_point+self.primary_key, attributes, nil, headers)
|
|
125
128
|
init_attributes(response)
|
|
126
129
|
self
|
|
127
130
|
end
|
|
128
131
|
|
|
129
132
|
# Update resource
|
|
130
133
|
def update
|
|
131
|
-
headers = { 'Content-Type' => 'application/
|
|
132
|
-
response = client.patch("#{@api_end_point}#{self.id}",
|
|
134
|
+
headers = { 'Content-Type' => 'application/json' }
|
|
135
|
+
response = client.patch("#{@api_end_point}#{self.id}", attributes, nil, headers)
|
|
133
136
|
init_attributes(response)
|
|
134
137
|
self
|
|
135
138
|
end
|
data/lib/kong/client.rb
CHANGED
|
@@ -46,7 +46,6 @@ module Kong
|
|
|
46
46
|
@api_url = url
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
|
|
50
49
|
# Get request
|
|
51
50
|
#
|
|
52
51
|
# @param [String] path
|
|
@@ -89,7 +88,7 @@ module Kong
|
|
|
89
88
|
end
|
|
90
89
|
end
|
|
91
90
|
|
|
92
|
-
#
|
|
91
|
+
# Patch request
|
|
93
92
|
#
|
|
94
93
|
# @param [String] path
|
|
95
94
|
# @param [Object] obj
|
|
@@ -113,7 +112,6 @@ module Kong
|
|
|
113
112
|
end
|
|
114
113
|
end
|
|
115
114
|
|
|
116
|
-
|
|
117
115
|
# Put request
|
|
118
116
|
#
|
|
119
117
|
# @param [String] path
|
data/lib/kong/plugin.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require_relative './util'
|
|
2
|
+
|
|
1
3
|
module Kong
|
|
2
4
|
class Plugin
|
|
3
5
|
include Base
|
|
@@ -8,24 +10,22 @@ module Kong
|
|
|
8
10
|
|
|
9
11
|
# Create resource
|
|
10
12
|
def create
|
|
11
|
-
|
|
12
|
-
attributes['config'].each do |key, value|
|
|
13
|
-
attributes["config.#{key}"] = value
|
|
14
|
-
end
|
|
15
|
-
attributes.delete('config')
|
|
16
|
-
end
|
|
13
|
+
flatten_config
|
|
17
14
|
super
|
|
18
15
|
end
|
|
19
16
|
|
|
20
17
|
# update resource
|
|
21
18
|
def update
|
|
19
|
+
flatten_config
|
|
20
|
+
super
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def flatten_config
|
|
22
26
|
if attributes['config']
|
|
23
|
-
attributes
|
|
24
|
-
attributes["config.#{key}"] = value
|
|
25
|
-
end
|
|
26
|
-
attributes.delete('config')
|
|
27
|
+
attributes.merge!(Util.flatten(attributes.delete('config'), 'config'))
|
|
27
28
|
end
|
|
28
|
-
super
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
end
|
data/lib/kong/util.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Kong
|
|
2
|
+
module Util
|
|
3
|
+
def self.flatten(cursor, parent_key = nil, memo = {})
|
|
4
|
+
memo.tap do
|
|
5
|
+
case cursor
|
|
6
|
+
when Hash
|
|
7
|
+
cursor.keys.each do |key|
|
|
8
|
+
flatten(cursor[key], [parent_key, key].compact.join('.'), memo)
|
|
9
|
+
end
|
|
10
|
+
else
|
|
11
|
+
memo["#{parent_key}"] = cursor
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/kong/version.rb
CHANGED
data/lib/kong.rb
CHANGED
|
@@ -2,6 +2,8 @@ require 'kong/version'
|
|
|
2
2
|
require_relative 'kong/base'
|
|
3
3
|
require_relative 'kong/api'
|
|
4
4
|
require_relative 'kong/belongs_to_api'
|
|
5
|
+
require_relative 'kong/service'
|
|
6
|
+
require_relative 'kong/route'
|
|
5
7
|
require_relative 'kong/client'
|
|
6
8
|
require_relative 'kong/consumer'
|
|
7
9
|
require_relative 'kong/belongs_to_consumer'
|
|
@@ -16,3 +18,4 @@ require_relative 'kong/acl'
|
|
|
16
18
|
require_relative 'kong/target'
|
|
17
19
|
require_relative 'kong/upstream'
|
|
18
20
|
require_relative 'kong/server'
|
|
21
|
+
require_relative 'kong/util'
|
data/spec/kong/base_spec.rb
CHANGED
|
@@ -94,18 +94,18 @@ describe Kong::Base do
|
|
|
94
94
|
|
|
95
95
|
describe '#create' do
|
|
96
96
|
it 'creates POST /:resource_end_point/ request with resource attributes' do
|
|
97
|
-
headers = { 'Content-Type' => 'application/
|
|
97
|
+
headers = { 'Content-Type' => 'application/json' }
|
|
98
98
|
attributes = { 'name' => 'test object' }
|
|
99
|
-
expect(Kong::Client.instance).to receive(:post).with('/resources/',
|
|
99
|
+
expect(Kong::Client.instance).to receive(:post).with('/resources/', attributes, nil, headers)
|
|
100
100
|
.and_return(attributes)
|
|
101
101
|
subject.name = 'test object'
|
|
102
102
|
subject.create
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
it 'returns resource instance' do
|
|
106
|
-
headers = { 'Content-Type' => 'application/
|
|
106
|
+
headers = { 'Content-Type' => 'application/json' }
|
|
107
107
|
attributes = { 'name' => 'test object' }
|
|
108
|
-
allow(Kong::Client.instance).to receive(:post).with('/resources/',
|
|
108
|
+
allow(Kong::Client.instance).to receive(:post).with('/resources/', attributes, nil, headers)
|
|
109
109
|
.and_return(attributes.merge({ 'id' => '12345' }))
|
|
110
110
|
subject.name = 'test object'
|
|
111
111
|
expect(subject.create).to eq(subject)
|
|
@@ -134,19 +134,19 @@ describe Kong::Base do
|
|
|
134
134
|
|
|
135
135
|
describe '#update' do
|
|
136
136
|
it 'creates PATCH /:resource_end_point/:resource_id request with resource attributes' do
|
|
137
|
-
headers = { 'Content-Type' => 'application/
|
|
137
|
+
headers = { 'Content-Type' => 'application/json' }
|
|
138
138
|
subject.id = '12345'
|
|
139
139
|
subject.name = 'test object'
|
|
140
|
-
expect(Kong::Client.instance).to receive(:patch).with('/resources/12345',
|
|
140
|
+
expect(Kong::Client.instance).to receive(:patch).with('/resources/12345', subject.attributes, nil, headers)
|
|
141
141
|
.and_return(subject.attributes)
|
|
142
142
|
subject.update
|
|
143
143
|
end
|
|
144
144
|
|
|
145
145
|
it 'returns resource instance' do
|
|
146
|
-
headers = { 'Content-Type' => 'application/
|
|
146
|
+
headers = { 'Content-Type' => 'application/json' }
|
|
147
147
|
subject.id = '12345'
|
|
148
148
|
subject.name = 'test object'
|
|
149
|
-
allow(Kong::Client.instance).to receive(:patch).with('/resources/12345',
|
|
149
|
+
allow(Kong::Client.instance).to receive(:patch).with('/resources/12345', subject.attributes, nil, headers)
|
|
150
150
|
.and_return(subject.attributes)
|
|
151
151
|
expect(subject.update).to eq(subject)
|
|
152
152
|
end
|
data/spec/kong/plugin_spec.rb
CHANGED
|
@@ -26,21 +26,37 @@ describe Kong::Plugin do
|
|
|
26
26
|
|
|
27
27
|
describe '#create' do
|
|
28
28
|
it 'transforms config keys to config.key format' do
|
|
29
|
-
headers = { 'Content-Type' => 'application/
|
|
29
|
+
headers = { 'Content-Type' => 'application/json' }
|
|
30
30
|
attributes = { 'api_id' => ':api_id', 'config.anonymous' => '12345' }
|
|
31
|
-
expect(Kong::Client.instance).to receive(:post).with('/apis/:api_id/plugins/',
|
|
31
|
+
expect(Kong::Client.instance).to receive(:post).with('/apis/:api_id/plugins/', attributes, nil, headers).and_return(attributes)
|
|
32
32
|
subject = described_class.new({ api_id: ':api_id', config: { 'anonymous' => '12345' } })
|
|
33
33
|
subject.create
|
|
34
34
|
end
|
|
35
|
+
|
|
36
|
+
it 'transforms nested config keys to config.key format' do
|
|
37
|
+
headers = { 'Content-Type' => 'application/json' }
|
|
38
|
+
attributes = { 'api_id' => ':api_id', 'config.anonymous' => '12345', 'config.first.second' => '1' }
|
|
39
|
+
expect(Kong::Client.instance).to receive(:post).with('/apis/:api_id/plugins/', attributes, nil, headers).and_return(attributes)
|
|
40
|
+
subject = described_class.new({ api_id: ':api_id', config: { 'anonymous' => '12345', 'first' => { 'second' => '1' } } })
|
|
41
|
+
subject.create
|
|
42
|
+
end
|
|
35
43
|
end
|
|
36
44
|
|
|
37
45
|
describe '#update' do
|
|
38
46
|
it 'transforms config keys to config.key format' do
|
|
39
|
-
headers = { 'Content-Type' => 'application/
|
|
47
|
+
headers = { 'Content-Type' => 'application/json' }
|
|
40
48
|
attributes = { 'api_id' => ':api_id', 'config.anonymous' => '12345' }
|
|
41
|
-
expect(Kong::Client.instance).to receive(:patch).with('/apis/:api_id/plugins/',
|
|
49
|
+
expect(Kong::Client.instance).to receive(:patch).with('/apis/:api_id/plugins/', attributes, nil, headers).and_return(attributes)
|
|
42
50
|
subject = described_class.new({ api_id: ':api_id', config: { 'anonymous' => '12345' } })
|
|
43
51
|
subject.update
|
|
44
52
|
end
|
|
53
|
+
|
|
54
|
+
it 'transforms nested config keys to config.key format' do
|
|
55
|
+
headers = { 'Content-Type' => 'application/json' }
|
|
56
|
+
attributes = { 'api_id' => ':api_id', 'config.anonymous' => '12345', 'config.first.second' => '1' }
|
|
57
|
+
expect(Kong::Client.instance).to receive(:patch).with('/apis/:api_id/plugins/', attributes, nil, headers).and_return(attributes)
|
|
58
|
+
subject = described_class.new({ api_id: ':api_id', config: { 'anonymous' => '12345', 'first' => { 'second' => '1' } } })
|
|
59
|
+
subject.update
|
|
60
|
+
end
|
|
45
61
|
end
|
|
46
62
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative "../spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Kong::Util do
|
|
4
|
+
describe '.flatten' do
|
|
5
|
+
subject { described_class.method(:flatten) }
|
|
6
|
+
|
|
7
|
+
it 'works' do
|
|
8
|
+
expect(subject[{
|
|
9
|
+
a: {
|
|
10
|
+
b: 1,
|
|
11
|
+
c: {
|
|
12
|
+
d: 3
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
b: 2
|
|
16
|
+
}]).to include({
|
|
17
|
+
"a.b" => 1,
|
|
18
|
+
"a.c.d" => 3,
|
|
19
|
+
"b" => 2,
|
|
20
|
+
})
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'accepts a scope' do
|
|
24
|
+
expect(subject[{ a: "1" }, 'config']).to eq({
|
|
25
|
+
"config.a" => "1"
|
|
26
|
+
})
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kong
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lauri Nevala
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-09-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -87,6 +87,7 @@ files:
|
|
|
87
87
|
- lib/kong/server.rb
|
|
88
88
|
- lib/kong/target.rb
|
|
89
89
|
- lib/kong/upstream.rb
|
|
90
|
+
- lib/kong/util.rb
|
|
90
91
|
- lib/kong/version.rb
|
|
91
92
|
- spec/kong/acl_spec.rb
|
|
92
93
|
- spec/kong/api_spec.rb
|
|
@@ -101,6 +102,7 @@ files:
|
|
|
101
102
|
- spec/kong/server_spec.rb
|
|
102
103
|
- spec/kong/target_spec.rb
|
|
103
104
|
- spec/kong/upstream_spec.rb
|
|
105
|
+
- spec/kong/util_spec.rb
|
|
104
106
|
- spec/spec_helper.rb
|
|
105
107
|
- tasks/rspec.rake
|
|
106
108
|
homepage: https://github.com/kontena/kong-client-ruby
|
|
@@ -123,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
123
125
|
version: '0'
|
|
124
126
|
requirements: []
|
|
125
127
|
rubyforge_project:
|
|
126
|
-
rubygems_version: 2.6.
|
|
128
|
+
rubygems_version: 2.6.11
|
|
127
129
|
signing_key:
|
|
128
130
|
specification_version: 4
|
|
129
131
|
summary: A Ruby client for the Kong API
|
|
@@ -141,4 +143,5 @@ test_files:
|
|
|
141
143
|
- spec/kong/server_spec.rb
|
|
142
144
|
- spec/kong/target_spec.rb
|
|
143
145
|
- spec/kong/upstream_spec.rb
|
|
146
|
+
- spec/kong/util_spec.rb
|
|
144
147
|
- spec/spec_helper.rb
|