kong 0.1.1 → 0.1.2
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/.hound.yml +2 -0
- data/CHANGELOG.md +10 -0
- data/README.md +18 -0
- data/lib/kong/acl.rb +8 -0
- data/lib/kong/base.rb +1 -1
- data/lib/kong/client.rb +14 -6
- data/lib/kong/consumer.rb +33 -1
- data/lib/kong/jwt.rb +8 -0
- data/lib/kong/version.rb +1 -1
- data/lib/kong.rb +14 -12
- data/spec/kong/acl_spec.rb +19 -0
- data/spec/kong/client_spec.rb +30 -0
- data/spec/kong/consumer_spec.rb +32 -4
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16715f84192ef0b86892c41bd5a64233f14bd1f9
|
4
|
+
data.tar.gz: 140668cf943e425c3ddc7d68bd8b498eba655805
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 071e6c144db8b6b556e03c49eb5f1e5747d289284164cacafd9802ebcde59f4d66927eb1460877a6fb54d851beb47a0411d3d5f7c68d580da3e693c40a6402b5
|
7
|
+
data.tar.gz: 0a0bb5ee564595b160910c2d325fe4ae0c67d67bf65dd5c6be60804b2874047060ccc69f23badae923f5e24ac940dc56643335f401607242fd66abcd3d66c97a
|
data/.hound.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# 0.1.2 (2017-01-12)
|
2
|
+
- Add JWT support ([#2](https://github.com/kontena/kong-client-ruby/pull/2))
|
3
|
+
- Allow to properly set a custom api_url ([#4](https://github.com/kontena/kong-client-ruby/pull/4))
|
4
|
+
- Allow to redefine api_url
|
5
|
+
([#6](https://github.com/kontena/kong-client-ruby/pull/6))
|
6
|
+
- Add ACL support
|
7
|
+
([#9](https://github.com/kontena/kong-client-ruby/pull/9))
|
8
|
+
|
9
|
+
# 0.1.1 (2016-10-10)
|
10
|
+
- Fix Kong::Base.respond_to? to return true for find_by_* methods
|
data/README.md
CHANGED
@@ -203,6 +203,24 @@ token.delete
|
|
203
203
|
token.oauth_app
|
204
204
|
```
|
205
205
|
|
206
|
+
#### ACL
|
207
|
+
|
208
|
+
```ruby
|
209
|
+
|
210
|
+
acl = Kong::Acl.new({
|
211
|
+
consumer_id: 'a3dX2dh2-1adb-40a5-c042-63b19dbx83hF4',
|
212
|
+
group: 'group1'
|
213
|
+
})
|
214
|
+
|
215
|
+
acl.create
|
216
|
+
acl.update
|
217
|
+
acl.save # requests create_or_update action
|
218
|
+
acl.delete
|
219
|
+
|
220
|
+
consumer = Kong::Consumer.find_by_username('testuser')
|
221
|
+
consumer.acls
|
222
|
+
```
|
223
|
+
|
206
224
|
## Contributing
|
207
225
|
|
208
226
|
1. Fork it ( https://github.com/kontena/kong-client-ruby/fork )
|
data/lib/kong/acl.rb
ADDED
data/lib/kong/base.rb
CHANGED
data/lib/kong/client.rb
CHANGED
@@ -5,33 +5,41 @@ require_relative './error'
|
|
5
5
|
|
6
6
|
module Kong
|
7
7
|
class Client
|
8
|
+
class << self
|
9
|
+
attr_accessor :http_client
|
10
|
+
end
|
11
|
+
|
8
12
|
include Singleton
|
9
13
|
|
10
14
|
attr_accessor :default_headers
|
11
|
-
attr_reader :http_client
|
12
15
|
|
13
16
|
# Initialize api client
|
14
17
|
#
|
15
18
|
def initialize
|
16
19
|
Excon.defaults[:ssl_verify_peer] = false if ignore_ssl_errors?
|
17
20
|
@api_url = api_url
|
18
|
-
|
21
|
+
self.class.http_client = Excon.new(@api_url, omit_default_port: true)
|
19
22
|
@default_headers = { 'Accept' => 'application/json' }
|
20
23
|
end
|
21
24
|
|
22
25
|
def self.api_url
|
23
|
-
|
26
|
+
@api_url || ENV['KONG_URI'] || 'http://localhost:8001'
|
24
27
|
end
|
25
28
|
|
26
29
|
def self.api_url=(url)
|
27
|
-
|
30
|
+
@api_url = url
|
31
|
+
@http_client = Excon.new(self.api_url, omit_default_port: true)
|
32
|
+
end
|
33
|
+
|
34
|
+
def http_client
|
35
|
+
self.class.http_client
|
28
36
|
end
|
29
37
|
|
30
38
|
# Kong Admin API URL
|
31
39
|
#
|
32
40
|
# @return [String]
|
33
|
-
def api_url
|
34
|
-
|
41
|
+
def api_url
|
42
|
+
self.class.api_url
|
35
43
|
end
|
36
44
|
|
37
45
|
def api_url=(url)
|
data/lib/kong/consumer.rb
CHANGED
@@ -65,7 +65,39 @@ module Kong
|
|
65
65
|
#
|
66
66
|
# @return [Array<Kong::OAuth2Token>]
|
67
67
|
def oauth2_tokens
|
68
|
-
|
68
|
+
if self.custom_id
|
69
|
+
OAuth2Token.list({ authenticated_userid: self.custom_id })
|
70
|
+
else
|
71
|
+
[]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# List Acls
|
76
|
+
#
|
77
|
+
# @return [Array<Kong::Acl>]
|
78
|
+
def acls
|
79
|
+
acls = []
|
80
|
+
response = client.get("#{@api_end_point}#{self.username}/acls") rescue nil
|
81
|
+
if response
|
82
|
+
response['data'].each do |attributes|
|
83
|
+
acls << Kong::Acl.new(attributes)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
acls
|
87
|
+
end
|
88
|
+
|
89
|
+
# List JWTs
|
90
|
+
#
|
91
|
+
# @return [Array<Kong::JWT>]
|
92
|
+
def jwts
|
93
|
+
apps = []
|
94
|
+
response = client.get("#{@api_end_point}#{self.username}/jwt") rescue nil
|
95
|
+
if response
|
96
|
+
response['data'].each do |attributes|
|
97
|
+
apps << Kong::JWT.new(attributes)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
apps
|
69
101
|
end
|
70
102
|
end
|
71
103
|
end
|
data/lib/kong/jwt.rb
ADDED
data/lib/kong/version.rb
CHANGED
data/lib/kong.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
require 'kong/version'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
2
|
+
require_relative 'kong/base'
|
3
|
+
require_relative 'kong/api'
|
4
|
+
require_relative 'kong/belongs_to_api'
|
5
|
+
require_relative 'kong/client'
|
6
|
+
require_relative 'kong/consumer'
|
7
|
+
require_relative 'kong/belongs_to_consumer'
|
8
|
+
require_relative 'kong/plugin'
|
9
|
+
require_relative 'kong/error'
|
10
|
+
require_relative 'kong/oauth_app'
|
11
|
+
require_relative 'kong/oauth2_token'
|
12
|
+
require_relative 'kong/basic_auth'
|
13
|
+
require_relative 'kong/key_auth'
|
14
|
+
require_relative 'kong/jwt'
|
15
|
+
require_relative 'kong/acl'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "../spec_helper"
|
2
|
+
|
3
|
+
describe Kong::Acl do
|
4
|
+
let(:valid_attribute_names) do
|
5
|
+
%w(id group consumer_id)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '::ATTRIBUTE_NAMES' do
|
9
|
+
it 'contains valid names' do
|
10
|
+
expect(subject.class::ATTRIBUTE_NAMES).to eq(valid_attribute_names)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '::API_END_POINT' do
|
15
|
+
it 'contains valid end point' do
|
16
|
+
expect(subject.class::API_END_POINT).to eq('/acls/')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/kong/client_spec.rb
CHANGED
@@ -12,6 +12,7 @@ describe Kong::Client do
|
|
12
12
|
|
13
13
|
describe '#initialize' do
|
14
14
|
it 'initializes Excon with Kong URI' do
|
15
|
+
described_class.api_url = nil
|
15
16
|
expect(Excon).to receive(:new).with('http://localhost:8001', { omit_default_port: true })
|
16
17
|
described_class.send(:new)
|
17
18
|
end
|
@@ -23,7 +24,22 @@ describe Kong::Client do
|
|
23
24
|
end
|
24
25
|
|
25
26
|
describe '#api_url' do
|
27
|
+
|
28
|
+
def client_params
|
29
|
+
uri = URI.parse described_class.api_url
|
30
|
+
params = {
|
31
|
+
host: uri.host,
|
32
|
+
hostname: uri.hostname,
|
33
|
+
path: uri.path,
|
34
|
+
port: uri.port,
|
35
|
+
query: uri.query,
|
36
|
+
scheme: uri.scheme
|
37
|
+
}
|
38
|
+
described_class.instance.http_client.params.merge(params)
|
39
|
+
end
|
40
|
+
|
26
41
|
it 'returns localhost as default' do
|
42
|
+
described_class.api_url = nil
|
27
43
|
expect(subject.api_url).to eq('http://localhost:8001')
|
28
44
|
end
|
29
45
|
|
@@ -32,9 +48,23 @@ describe Kong::Client do
|
|
32
48
|
allow(ENV).to receive(:[]).with('no_proxy')
|
33
49
|
allow(ENV).to receive(:[]).with('SSL_IGNORE_ERRORS')
|
34
50
|
allow(ENV).to receive(:[]).with('KONG_URI').and_return('http://kong-api:8001')
|
51
|
+
described_class.api_url = nil
|
35
52
|
subject = described_class.send(:new)
|
36
53
|
expect(subject.api_url).to eq('http://kong-api:8001')
|
37
54
|
end
|
55
|
+
|
56
|
+
it 'returns custom api_url if set' do
|
57
|
+
url = 'http://foo.bar:1337'
|
58
|
+
described_class.api_url = url
|
59
|
+
expect(described_class.send(:new).api_url).to eq(url)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'can edit api_url' do
|
63
|
+
described_class.api_url = nil
|
64
|
+
expect(described_class.instance.http_client.params).to eq(client_params)
|
65
|
+
described_class.api_url = 'http://foo.bar:1337'
|
66
|
+
expect(described_class.instance.http_client.params).to eq(client_params)
|
67
|
+
end
|
38
68
|
end
|
39
69
|
|
40
70
|
describe '#get' do
|
data/spec/kong/consumer_spec.rb
CHANGED
@@ -35,10 +35,38 @@ describe Kong::Consumer do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
describe '#oauth2_tokens' do
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
context 'when custom_id is set' do
|
39
|
+
it 'requests oauth2_tokens assigned to consumer' do
|
40
|
+
subject.custom_id = 'custom_id'
|
41
|
+
expect(Kong::OAuth2Token).to receive(:list).with({ authenticated_userid: subject.custom_id })
|
42
|
+
subject.oauth2_tokens
|
43
|
+
end
|
44
|
+
end
|
45
|
+
context 'when custom_id is not set' do
|
46
|
+
it 'requests oauth2_tokens assigned to consumer' do
|
47
|
+
expect(Kong::OAuth2Token).not_to receive(:list)
|
48
|
+
subject.oauth2_tokens
|
49
|
+
end
|
50
|
+
it 'returns empty array' do
|
51
|
+
expect(subject.oauth2_tokens).to eq([])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#acls' do
|
57
|
+
it 'requests consumer\'s acls' do
|
58
|
+
subject.username = ':username'
|
59
|
+
expect(Kong::Client.instance).to receive(:get).with("/consumers/:username/acls")
|
60
|
+
.and_return({ 'data' => [{ 'id' => '123456', 'group' => 'group1' }] })
|
61
|
+
subject.acls
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns list of Acls' do
|
65
|
+
subject.username = ':username'
|
66
|
+
allow(Kong::Client.instance).to receive(:get).with("/consumers/:username/acls")
|
67
|
+
.and_return({ 'data' => [{ 'id' => '123456', 'group' => 'group1' }] })
|
68
|
+
result = subject.acls
|
69
|
+
expect(result.first.is_a?(Kong::Acl)).to be_truthy
|
42
70
|
end
|
43
71
|
end
|
44
72
|
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.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lauri Nevala
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,14 +60,17 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
|
+
- ".hound.yml"
|
63
64
|
- ".rubocop.yml"
|
64
65
|
- ".travis.yml"
|
66
|
+
- CHANGELOG.md
|
65
67
|
- Gemfile
|
66
68
|
- LICENSE
|
67
69
|
- README.md
|
68
70
|
- Rakefile
|
69
71
|
- kong.gemspec
|
70
72
|
- lib/kong.rb
|
73
|
+
- lib/kong/acl.rb
|
71
74
|
- lib/kong/api.rb
|
72
75
|
- lib/kong/base.rb
|
73
76
|
- lib/kong/basic_auth.rb
|
@@ -76,11 +79,13 @@ files:
|
|
76
79
|
- lib/kong/client.rb
|
77
80
|
- lib/kong/consumer.rb
|
78
81
|
- lib/kong/error.rb
|
82
|
+
- lib/kong/jwt.rb
|
79
83
|
- lib/kong/key_auth.rb
|
80
84
|
- lib/kong/oauth2_token.rb
|
81
85
|
- lib/kong/oauth_app.rb
|
82
86
|
- lib/kong/plugin.rb
|
83
87
|
- lib/kong/version.rb
|
88
|
+
- spec/kong/acl_spec.rb
|
84
89
|
- spec/kong/api_spec.rb
|
85
90
|
- spec/kong/base_spec.rb
|
86
91
|
- spec/kong/basic_auth_spec.rb
|
@@ -112,11 +117,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
117
|
version: '0'
|
113
118
|
requirements: []
|
114
119
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
120
|
+
rubygems_version: 2.6.6
|
116
121
|
signing_key:
|
117
122
|
specification_version: 4
|
118
123
|
summary: A Ruby client for the Kong API
|
119
124
|
test_files:
|
125
|
+
- spec/kong/acl_spec.rb
|
120
126
|
- spec/kong/api_spec.rb
|
121
127
|
- spec/kong/base_spec.rb
|
122
128
|
- spec/kong/basic_auth_spec.rb
|