kong 0.1.2 → 0.2.0

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: 16715f84192ef0b86892c41bd5a64233f14bd1f9
4
- data.tar.gz: 140668cf943e425c3ddc7d68bd8b498eba655805
3
+ metadata.gz: 2eb96feeae50f935d3faf48b18bffde840ad3ca0
4
+ data.tar.gz: bc4e0aa0c3125d227135ff82db8168a154b773cf
5
5
  SHA512:
6
- metadata.gz: 071e6c144db8b6b556e03c49eb5f1e5747d289284164cacafd9802ebcde59f4d66927eb1460877a6fb54d851beb47a0411d3d5f7c68d580da3e693c40a6402b5
7
- data.tar.gz: 0a0bb5ee564595b160910c2d325fe4ae0c67d67bf65dd5c6be60804b2874047060ccc69f23badae923f5e24ac940dc56643335f401607242fd66abcd3d66c97a
6
+ metadata.gz: 20914d65262adc1f8592ed02eb689aeba49b5b9b3aca132bf7cd4b9e5bdd1899e0556b1463fea60d3e7ad8dcab16ea8456876086ab94a54d8cf80952c92ff5c0
7
+ data.tar.gz: 5be4a32b52ec29a31a5fcda2d40784881fc9f0ac009bb68eeaf132e1831062822eb76e6554b1d1317326e800f2e8ff25fe2b90770ef6806d1993808daf87d1d2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.2.0 (2017-04-20)
2
+ - Add Server information support ([#14](https://github.com/kontena/kong-client-ruby/pull/14))
3
+ - Add optional attributes to Api
4
+ ([#13](https://github.com/kontena/kong-client-ruby/pull/13))
5
+ - Fix Plugin#create and #update to save config properly
6
+ ([#12](https://github.com/kontena/kong-client-ruby/pull/12))
7
+
1
8
  # 0.1.2 (2017-01-12)
2
9
  - Add JWT support ([#2](https://github.com/kontena/kong-client-ruby/pull/2))
3
10
  - Allow to properly set a custom api_url ([#4](https://github.com/kontena/kong-client-ruby/pull/4))
data/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  [![Build Status](https://travis-ci.org/kontena/kong-client-ruby.svg?branch=master)](https://travis-ci.org/kontena/kong-client-ruby)
6
6
  [![Gem Version](https://badge.fury.io/rb/kong.svg)](https://badge.fury.io/rb/kong)
7
+
7
8
  ## Installation
8
9
  Add this line to your application's Gemfile:
9
10
 
@@ -27,7 +28,7 @@ require 'kong'
27
28
  Kong::Client.api_url = 'http://your-kong-url:8001'
28
29
  ```
29
30
 
30
- ### Desing
31
+ ### Design
31
32
 
32
33
  Kong client follows a design of resoures as Plain Old Ruby objects(tm). For examples to create a new Consumer resource you can do it like this:
33
34
 
@@ -203,6 +204,25 @@ token.delete
203
204
  token.oauth_app
204
205
  ```
205
206
 
207
+ #### JWT
208
+
209
+ ```ruby
210
+
211
+ jwt = Kong::JWT.new({
212
+ consumer_id: 'a3dX2dh2-1adb-40a5-c042-63b19dbx83hF4',
213
+ key: 'a36c3049b36249a3c9f8891cb127243c',
214
+ secret: 'e71829c351aa4242c2719cbfbe671c09'
215
+ })
216
+
217
+ jwt.create
218
+ jwt.update
219
+ jwt.save # requests create_or_update action
220
+ jwt.delete
221
+
222
+ consumer = Kong::Consumer.find_by_username('testuser')
223
+ consumer.jwts
224
+ ```
225
+
206
226
  #### ACL
207
227
 
208
228
  ```ruby
@@ -221,6 +241,16 @@ consumer = Kong::Consumer.find_by_username('testuser')
221
241
  consumer.acls
222
242
  ```
223
243
 
244
+ #### Server Information
245
+
246
+ ```ruby
247
+ Kong::Server.info
248
+ Kong::Server.version
249
+ Kong::Server.status
250
+ Kong::Server.cluster
251
+ Kong::Server.remove_node(node_name)
252
+ ```
253
+
224
254
  ## Contributing
225
255
 
226
256
  1. Fork it ( https://github.com/kontena/kong-client-ruby/fork )
data/lib/kong.rb CHANGED
@@ -13,3 +13,4 @@ require_relative 'kong/basic_auth'
13
13
  require_relative 'kong/key_auth'
14
14
  require_relative 'kong/jwt'
15
15
  require_relative 'kong/acl'
16
+ require_relative 'kong/server'
data/lib/kong/api.rb CHANGED
@@ -2,7 +2,12 @@ module Kong
2
2
  class Api
3
3
  include Base
4
4
 
5
- ATTRIBUTE_NAMES = %w(id name request_host request_path strip_request_path preserve_host upstream_url).freeze
5
+ ATTRIBUTE_NAMES = %w(
6
+ id name request_host request_path strip_request_path
7
+ hosts uris strip_uri preserve_host upstream_url retries
8
+ upstream_connect_timeout upstream_send_timeout upstream_read_timeout
9
+ https_only http_if_terminated
10
+ ).freeze
6
11
  API_END_POINT = '/apis/'.freeze
7
12
 
8
13
  ##
data/lib/kong/plugin.rb CHANGED
@@ -5,5 +5,27 @@ module Kong
5
5
 
6
6
  ATTRIBUTE_NAMES = %w(id api_id name config enabled consumer_id).freeze
7
7
  API_END_POINT = '/plugins/'.freeze
8
+
9
+ # Create resource
10
+ def create
11
+ if attributes['config']
12
+ attributes['config'].each do |key, value|
13
+ attributes["config.#{key}"] = value
14
+ end
15
+ attributes.delete('config')
16
+ end
17
+ super
18
+ end
19
+
20
+ # update resource
21
+ def update
22
+ if attributes['config']
23
+ attributes['config'].each do |key, value|
24
+ attributes["config.#{key}"] = value
25
+ end
26
+ attributes.delete('config')
27
+ end
28
+ super
29
+ end
8
30
  end
9
31
  end
@@ -0,0 +1,23 @@
1
+ module Kong
2
+ class Server
3
+ def self.version
4
+ self.info['version'] rescue nil
5
+ end
6
+
7
+ def self.info
8
+ Client.instance.get('/')
9
+ end
10
+
11
+ def self.status
12
+ Client.instance.get('/status')
13
+ end
14
+
15
+ def self.cluster
16
+ Client.instance.get('/cluster')
17
+ end
18
+
19
+ def self.remove_node(name)
20
+ Client.instance.delete("/cluster/nodes/#{name}")
21
+ end
22
+ end
23
+ end
data/lib/kong/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kong
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -2,7 +2,12 @@ require_relative "../spec_helper"
2
2
 
3
3
  describe Kong::Api do
4
4
  let(:valid_attribute_names) do
5
- %w(id name request_host request_path strip_request_path preserve_host upstream_url)
5
+ %w(
6
+ id name request_host request_path strip_request_path
7
+ hosts uris strip_uri preserve_host upstream_url retries
8
+ upstream_connect_timeout upstream_send_timeout upstream_read_timeout
9
+ https_only http_if_terminated
10
+ )
6
11
  end
7
12
 
8
13
  describe 'ATTRIBUTE_NAMES' do
@@ -23,4 +23,24 @@ describe Kong::Plugin do
23
23
  expect(subject.api_end_point).to eq('/apis/:api_id/plugins/')
24
24
  end
25
25
  end
26
+
27
+ describe '#create' do
28
+ it 'transforms config keys to config.key format' do
29
+ headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
30
+ attributes = { 'api_id' => ':api_id', 'config.anonymous' => '12345' }
31
+ expect(Kong::Client.instance).to receive(:post).with('/apis/:api_id/plugins/', nil, attributes, headers).and_return(attributes)
32
+ subject = described_class.new({ api_id: ':api_id', config: { 'anonymous' => '12345' } })
33
+ subject.create
34
+ end
35
+ end
36
+
37
+ describe '#update' do
38
+ it 'transforms config keys to config.key format' do
39
+ headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
40
+ attributes = { 'api_id' => ':api_id', 'config.anonymous' => '12345' }
41
+ expect(Kong::Client.instance).to receive(:patch).with('/apis/:api_id/plugins/', nil, attributes, headers).and_return(attributes)
42
+ subject = described_class.new({ api_id: ':api_id', config: { 'anonymous' => '12345' } })
43
+ subject.update
44
+ end
45
+ end
26
46
  end
@@ -0,0 +1,39 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe Kong::Server do
4
+ describe '.info' do
5
+ it 'makes GET / request' do
6
+ expect(Kong::Client.instance).to receive(:get).with('/')
7
+ described_class.info
8
+ end
9
+ end
10
+
11
+ describe '.version' do
12
+ it 'returns version information' do
13
+ allow(Kong::Client.instance).to receive(:get).with('/')
14
+ .and_return({ 'version' => '0.10.0' })
15
+ expect(described_class.version).to eq('0.10.0')
16
+ end
17
+ end
18
+
19
+ describe '.status' do
20
+ it 'makes GET /status request' do
21
+ expect(Kong::Client.instance).to receive(:get).with('/status')
22
+ described_class.status
23
+ end
24
+ end
25
+
26
+ describe '.cluster' do
27
+ it 'makes GET /cluster request' do
28
+ expect(Kong::Client.instance).to receive(:get).with('/cluster')
29
+ described_class.cluster
30
+ end
31
+ end
32
+
33
+ describe '.remove_node' do
34
+ it 'makes DELETE /cluster/nodes/:name request' do
35
+ expect(Kong::Client.instance).to receive(:delete).with('/cluster/nodes/:name')
36
+ described_class.remove_node(':name')
37
+ end
38
+ end
39
+ 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.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lauri Nevala
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-12 00:00:00.000000000 Z
11
+ date: 2017-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,6 +84,7 @@ files:
84
84
  - lib/kong/oauth2_token.rb
85
85
  - lib/kong/oauth_app.rb
86
86
  - lib/kong/plugin.rb
87
+ - lib/kong/server.rb
87
88
  - lib/kong/version.rb
88
89
  - spec/kong/acl_spec.rb
89
90
  - spec/kong/api_spec.rb
@@ -95,6 +96,7 @@ files:
95
96
  - spec/kong/oauth2_token_spec.rb
96
97
  - spec/kong/oauth_app_spec.rb
97
98
  - spec/kong/plugin_spec.rb
99
+ - spec/kong/server_spec.rb
98
100
  - spec/spec_helper.rb
99
101
  - tasks/rspec.rake
100
102
  homepage: https://github.com/kontena/kong-client-ruby
@@ -117,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
119
  version: '0'
118
120
  requirements: []
119
121
  rubyforge_project:
120
- rubygems_version: 2.6.6
122
+ rubygems_version: 2.5.2
121
123
  signing_key:
122
124
  specification_version: 4
123
125
  summary: A Ruby client for the Kong API
@@ -132,4 +134,5 @@ test_files:
132
134
  - spec/kong/oauth2_token_spec.rb
133
135
  - spec/kong/oauth_app_spec.rb
134
136
  - spec/kong/plugin_spec.rb
137
+ - spec/kong/server_spec.rb
135
138
  - spec/spec_helper.rb