ruby-kong 0.1.0a
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 +7 -0
- data/.codeclimate.yml +40 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +99 -0
- data/.travis.yml +8 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +71 -0
- data/LICENSE.txt +21 -0
- data/README.md +12 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ruby-kong.rb +12 -0
- data/lib/ruby-kong/api.rb +47 -0
- data/lib/ruby-kong/consumer.rb +43 -0
- data/lib/ruby-kong/kong.rb +7 -0
- data/lib/ruby-kong/node.rb +15 -0
- data/lib/ruby-kong/plugin.rb +70 -0
- data/lib/ruby-kong/request.rb +31 -0
- data/lib/ruby-kong/request/api.rb +150 -0
- data/lib/ruby-kong/request/consumer.rb +142 -0
- data/lib/ruby-kong/request/node.rb +70 -0
- data/lib/ruby-kong/request/plugin.rb +280 -0
- data/lib/ruby-kong/spec.rb +42 -0
- data/lib/ruby-kong/stub.rb +28 -0
- data/lib/ruby-kong/utils.rb +9 -0
- data/lib/ruby-kong/version.rb +3 -0
- data/ruby-kong.gemspec +37 -0
- metadata +156 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'ruby-kong/request/plugin'
|
2
|
+
|
3
|
+
module RubyKong
|
4
|
+
module Plugin
|
5
|
+
class << self
|
6
|
+
# Params: api:,
|
7
|
+
# plugin: {name:, consumer_id: nil, config.{property}}
|
8
|
+
#
|
9
|
+
# Usage: RubyKong::Plugin.create api: 'shipit',
|
10
|
+
# plugin: {name: 'key-auth'}
|
11
|
+
def create(*args)
|
12
|
+
RubyKong::Request::Plugin.create args[0]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Params: id, name, api_id, consumer_id, size, offset
|
16
|
+
#
|
17
|
+
# Usage: RubyKong::Plugin.list
|
18
|
+
def list(*args)
|
19
|
+
RubyKong::Request::Plugin.list args[0]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Params: api: id,
|
23
|
+
# filter: {name, api_id, consumer_id, size, offset}
|
24
|
+
#
|
25
|
+
# Usage: RubyKong::Plugin.list_by_api api: 'shipit',
|
26
|
+
# filter: {name: 'key-auth'}
|
27
|
+
def list_by_api(*args)
|
28
|
+
RubyKong::Request::Plugin.list_by_api args[0]
|
29
|
+
end
|
30
|
+
|
31
|
+
# Params: id
|
32
|
+
#
|
33
|
+
# Usage: RubyKong::Plugin.retrieve id: '90e6e8f4-2d51-444d-ac28-3f1dc1b3b3ed'
|
34
|
+
def retrieve(*args)
|
35
|
+
RubyKong::Request::Plugin.retrieve args[0]
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Usage: RubyKong::Plugin.retrieve_enabled
|
40
|
+
def retrieve_enabled(*args)
|
41
|
+
RubyKong::Request::Plugin.retrieve_enabled args[0]
|
42
|
+
end
|
43
|
+
|
44
|
+
# Params: plugin_name
|
45
|
+
#
|
46
|
+
# Usage: RubyKong::Plugin.retrieve_schema plugin_name: 'basic_auth'
|
47
|
+
def retrieve_schema(*args)
|
48
|
+
RubyKong::Request::Plugin.retrieve_schema args[0]
|
49
|
+
end
|
50
|
+
|
51
|
+
# Params: api:, plugin:,
|
52
|
+
# params: {name:, consumer_id:, config.{property}}
|
53
|
+
#
|
54
|
+
# Usage: RubyKong::Plugin.update api: 'shipit',
|
55
|
+
# plugin: '90e6e8f4-2d51-444d-ac28-3f1dc1b3b3ed'
|
56
|
+
# params: {name: 'basic-auth'}
|
57
|
+
def update(*args)
|
58
|
+
RubyKong::Request::Plugin.update args[0]
|
59
|
+
end
|
60
|
+
|
61
|
+
# Params: id, name
|
62
|
+
#
|
63
|
+
# Usage: RubyKong::Plugin.update name: 'shipit',
|
64
|
+
# upstream_url: 'https://api.shipit.vn/v2/'
|
65
|
+
def delete(*args)
|
66
|
+
RubyKong::Request::Plugin.delete args[0]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'unirest'
|
2
|
+
module RubyKong
|
3
|
+
module Request
|
4
|
+
class << self
|
5
|
+
def get(path, params = nil, headers = {})
|
6
|
+
endpoint = RubyKong::Utils.endpoint_builder(path)
|
7
|
+
Unirest.get(endpoint, :headers => headers, :parameters => params)
|
8
|
+
end
|
9
|
+
|
10
|
+
def post(path, params = nil, headers = {})
|
11
|
+
endpoint = RubyKong::Utils.endpoint_builder(path)
|
12
|
+
Unirest.post(endpoint, :headers => headers, :parameters => params)
|
13
|
+
end
|
14
|
+
|
15
|
+
def put(path, params = nil, headers = {})
|
16
|
+
endpoint = RubyKong::Utils.endpoint_builder(path)
|
17
|
+
Unirest.put(endpoint, :headers => headers, :parameters => params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def patch(path, params = nil, headers = {})
|
21
|
+
endpoint = RubyKong::Utils.endpoint_builder(path)
|
22
|
+
Unirest.patch(endpoint, :headers => headers, :parameters => params)
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete(path, params = nil, headers = {})
|
26
|
+
endpoint = RubyKong::Utils.endpoint_builder(path)
|
27
|
+
Unirest.delete(endpoint, :headers => headers, :parameters => params)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
module RubyKong
|
2
|
+
module Request
|
3
|
+
module Api
|
4
|
+
class << self
|
5
|
+
def create(*args)
|
6
|
+
path = RubyKong.paths[:api][:create]
|
7
|
+
Request.post(path, args[0])
|
8
|
+
end
|
9
|
+
|
10
|
+
def list(*args)
|
11
|
+
path = RubyKong.paths[:api][:list]
|
12
|
+
Request.get(path, args[0])
|
13
|
+
end
|
14
|
+
|
15
|
+
def retrieve(*args)
|
16
|
+
resource = args[0][:name] || args[0][:id]
|
17
|
+
path = RubyKong.paths[:api][:retrieve] + resource
|
18
|
+
Request.get(path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update(*args)
|
22
|
+
resource = args[0][:name] || args[0][:id]
|
23
|
+
path = RubyKong.paths[:api][:update] + resource
|
24
|
+
Request.patch(path, args[0])
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete(*args)
|
28
|
+
resource = args[0][:name] || args[0][:id]
|
29
|
+
path = RubyKong.paths[:api][:update] + resource
|
30
|
+
Request.delete(path, args[0])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Stub
|
35
|
+
def self.delete
|
36
|
+
# Mock with /apis/shipit path
|
37
|
+
path = RubyKong.paths[:api][:delete] + 'shipit'
|
38
|
+
url = RubyKong::Utils.endpoint_builder(path)
|
39
|
+
|
40
|
+
RubyKong::Stub.request(
|
41
|
+
:method => :delete,
|
42
|
+
:url => url,
|
43
|
+
:response => {
|
44
|
+
:status => 204,
|
45
|
+
:body => ""
|
46
|
+
}
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.update
|
51
|
+
# Mock with /apis/shipit path
|
52
|
+
path = RubyKong.paths[:api][:update] + 'shipit'
|
53
|
+
url = RubyKong::Utils.endpoint_builder(path)
|
54
|
+
|
55
|
+
RubyKong::Stub.request(
|
56
|
+
:method => :patch,
|
57
|
+
:url => url,
|
58
|
+
:request => {
|
59
|
+
:body => {
|
60
|
+
:upstream_url => 'https://api.shipit.vn/v2/',
|
61
|
+
:name => 'shipit'
|
62
|
+
}
|
63
|
+
},
|
64
|
+
:response => {
|
65
|
+
:status => 200,
|
66
|
+
:body => {
|
67
|
+
'upstream_url' => 'https://api.shipit.vn/v2/',
|
68
|
+
'id' => '0faeb3a7-3839-4739-916a-6b139c5b491b',
|
69
|
+
'name' => 'shipit',
|
70
|
+
'created_at' => 1458706997000,
|
71
|
+
'request_host' => 'api.shipit.vn'
|
72
|
+
}.to_s
|
73
|
+
}
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.retrieve
|
78
|
+
# Mock with /apis/shipit path
|
79
|
+
path = RubyKong.paths[:api][:retrieve] + 'shipit'
|
80
|
+
url = RubyKong::Utils.endpoint_builder(path)
|
81
|
+
|
82
|
+
RubyKong::Stub.request(
|
83
|
+
:method => :get,
|
84
|
+
:url => url,
|
85
|
+
:response => {
|
86
|
+
:status => 200,
|
87
|
+
:body => {
|
88
|
+
"upstream_url" => "https://api.shipit.vn/v1/",
|
89
|
+
"id" => "0faeb3a7-3839-4739-916a-6b139c5b491b",
|
90
|
+
"name" => "shipit",
|
91
|
+
"created_at" => 1458706997000,
|
92
|
+
"request_host" => "api.shipit.vn"
|
93
|
+
}.to_s
|
94
|
+
}
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.list
|
99
|
+
url = RubyKong::Utils.endpoint_builder(RubyKong.paths[:api][:list])
|
100
|
+
|
101
|
+
RubyKong::Stub.request(
|
102
|
+
:method => :get,
|
103
|
+
:url => url,
|
104
|
+
:response => {
|
105
|
+
:status => 200,
|
106
|
+
:body => {
|
107
|
+
"data" =>
|
108
|
+
[
|
109
|
+
{
|
110
|
+
"upstream_url" => "https://api.shipit.vn/v1/",
|
111
|
+
"id" => "0faeb3a7-3839-4739-916a-6b139c5b491b",
|
112
|
+
"name" => "shipit",
|
113
|
+
"created_at" => 1458706997000,
|
114
|
+
"request_host" => "api.shipit.vn"
|
115
|
+
}
|
116
|
+
],
|
117
|
+
"total" => 1
|
118
|
+
}.to_s
|
119
|
+
}
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.create
|
124
|
+
url = RubyKong::Utils.endpoint_builder(RubyKong.paths[:api][:create])
|
125
|
+
RubyKong::Stub.request(
|
126
|
+
:method => :post,
|
127
|
+
:url => url,
|
128
|
+
:request => {
|
129
|
+
:body => {
|
130
|
+
:upstream_url => 'https://api.shipit.vn/v1/',
|
131
|
+
:request_host => 'api.shipit.vn',
|
132
|
+
:name => 'shipit'
|
133
|
+
}
|
134
|
+
},
|
135
|
+
:response => {
|
136
|
+
:status => 201,
|
137
|
+
:body => {
|
138
|
+
'upstream_url' => 'https://api.shipit.vn/v1/',
|
139
|
+
'id' => '0faeb3a7-3839-4739-916a-6b139c5b491b',
|
140
|
+
'name' => 'shipit',
|
141
|
+
'created_at' => 1458706997000,
|
142
|
+
'request_host' => 'api.shipit.vn'
|
143
|
+
}.to_s
|
144
|
+
}
|
145
|
+
)
|
146
|
+
end # End of Stub.create method
|
147
|
+
end # End of Stub module
|
148
|
+
end # end of Api
|
149
|
+
end # End of Request
|
150
|
+
end # End of RubyKong
|
@@ -0,0 +1,142 @@
|
|
1
|
+
module RubyKong
|
2
|
+
module Request
|
3
|
+
module Consumer
|
4
|
+
class << self
|
5
|
+
def create(*args)
|
6
|
+
path = RubyKong.paths[:consumer][:create]
|
7
|
+
Request.post(path, args[0])
|
8
|
+
end
|
9
|
+
|
10
|
+
def list(*args)
|
11
|
+
path = RubyKong.paths[:consumer][:list]
|
12
|
+
Request.get(path, args[0])
|
13
|
+
end
|
14
|
+
|
15
|
+
def retrieve(*args)
|
16
|
+
resource = args[0][:username] || args[0][:id]
|
17
|
+
path = RubyKong.paths[:consumer][:retrieve] + resource
|
18
|
+
Request.get(path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update(*args)
|
22
|
+
resource = args[0][:username] || args[0][:id]
|
23
|
+
path = RubyKong.paths[:consumer][:update] + resource
|
24
|
+
Request.patch(path, args[0])
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete(*args)
|
28
|
+
resource = args[0][:username] || args[0][:id]
|
29
|
+
path = RubyKong.paths[:consumer][:update] + resource
|
30
|
+
Request.delete(path, args[0])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Stub
|
35
|
+
def self.delete
|
36
|
+
# Mock with /consumers/lamdt path
|
37
|
+
path = RubyKong.paths[:consumer][:delete] + 'lamdt'
|
38
|
+
url = RubyKong::Utils.endpoint_builder(path)
|
39
|
+
|
40
|
+
RubyKong::Stub.request(
|
41
|
+
:method => :delete,
|
42
|
+
:url => url,
|
43
|
+
:response => {
|
44
|
+
:status => 204,
|
45
|
+
:body => ""
|
46
|
+
}
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.update
|
51
|
+
# Mock with /consumers/lamdt path
|
52
|
+
path = RubyKong.paths[:consumer][:update] + 'lamdt'
|
53
|
+
url = RubyKong::Utils.endpoint_builder(path)
|
54
|
+
|
55
|
+
RubyKong::Stub.request(
|
56
|
+
:method => :patch,
|
57
|
+
:url => url,
|
58
|
+
:request => {
|
59
|
+
:body => {
|
60
|
+
:custom_id => '1234',
|
61
|
+
:username => 'lamdt'
|
62
|
+
}
|
63
|
+
},
|
64
|
+
:response => {
|
65
|
+
:status => 200,
|
66
|
+
:body => {
|
67
|
+
'custom_id' => 1234,
|
68
|
+
'username' => 'lamdt',
|
69
|
+
'created_at' => 1458789832000,
|
70
|
+
'id' => 'b880f403-b161-4294-9a13-2462d39991b2'
|
71
|
+
}.to_s
|
72
|
+
}
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.retrieve
|
77
|
+
# Mock with /consumers/lamdt path
|
78
|
+
path = RubyKong.paths[:consumer][:retrieve] + 'lamdt'
|
79
|
+
url = RubyKong::Utils.endpoint_builder(path)
|
80
|
+
|
81
|
+
RubyKong::Stub.request(
|
82
|
+
:method => :get,
|
83
|
+
:url => url,
|
84
|
+
:response => {
|
85
|
+
:status => 200,
|
86
|
+
:body => {
|
87
|
+
'username' => 'lamdt',
|
88
|
+
'created_at' => 1458789832000,
|
89
|
+
'id' => 'b880f403-b161-4294-9a13-2462d39991b2'
|
90
|
+
}.to_s
|
91
|
+
}
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.list
|
96
|
+
url = RubyKong::Utils.endpoint_builder(RubyKong.paths[:consumer][:list])
|
97
|
+
|
98
|
+
RubyKong::Stub.request(
|
99
|
+
:method => :get,
|
100
|
+
:url => url,
|
101
|
+
:response => {
|
102
|
+
:status => 200,
|
103
|
+
:body => {
|
104
|
+
"data" =>
|
105
|
+
[
|
106
|
+
{
|
107
|
+
'username' => 'lamdt',
|
108
|
+
'created_at' => 1458789832000,
|
109
|
+
'id' => 'b880f403-b161-4294-9a13-2462d39991b2'
|
110
|
+
}
|
111
|
+
],
|
112
|
+
"total" => 1
|
113
|
+
}.to_s
|
114
|
+
}
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.create
|
119
|
+
url = RubyKong::Utils.endpoint_builder(RubyKong.paths[:consumer][:create])
|
120
|
+
|
121
|
+
RubyKong::Stub.request(
|
122
|
+
:method => :post,
|
123
|
+
:url => url,
|
124
|
+
:request => {
|
125
|
+
:body => {
|
126
|
+
:username => 'lamdt'
|
127
|
+
}
|
128
|
+
},
|
129
|
+
:response => {
|
130
|
+
:status => 201,
|
131
|
+
:body => {
|
132
|
+
'username' => 'lamdt',
|
133
|
+
'created_at' => 1458789832000,
|
134
|
+
'id' => 'b880f403-b161-4294-9a13-2462d39991b2'
|
135
|
+
}.to_s
|
136
|
+
}
|
137
|
+
)
|
138
|
+
end # End of Stub.create method
|
139
|
+
end # End of Stub module
|
140
|
+
end # end of Consumer
|
141
|
+
end # End of Request
|
142
|
+
end # End of RubyKong
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module RubyKong
|
2
|
+
module Request
|
3
|
+
module Node
|
4
|
+
class << self
|
5
|
+
def get_node_info
|
6
|
+
path = RubyKong.paths[:node][:info]
|
7
|
+
|
8
|
+
Request.get path
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_node_status
|
12
|
+
path = RubyKong.paths[:node][:status]
|
13
|
+
|
14
|
+
Request.get path
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Stub
|
19
|
+
def self.get_node_info
|
20
|
+
url = RubyKong::Utils.endpoint_builder(RubyKong.paths[:node][:info])
|
21
|
+
|
22
|
+
RubyKong::Stub.request(
|
23
|
+
:method => :get,
|
24
|
+
:url => url,
|
25
|
+
:response => {
|
26
|
+
:body => {
|
27
|
+
'version' => '0.7.0',
|
28
|
+
'lua_version' => 'LuaJIT 2.1.0-beta1',
|
29
|
+
'tagline' => 'Welcome to Kong',
|
30
|
+
'hostname' => '8b173da56e6'
|
31
|
+
}.to_s
|
32
|
+
}
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.get_node_status
|
37
|
+
url = RubyKong::Utils.endpoint_builder(RubyKong.paths[:node][:status])
|
38
|
+
|
39
|
+
RubyKong::Stub.request(
|
40
|
+
:method => :get,
|
41
|
+
:url => url,
|
42
|
+
:response => {
|
43
|
+
:body => {
|
44
|
+
"server" => {
|
45
|
+
"connections_handled" => 2757,
|
46
|
+
"connections_reading" => 0,
|
47
|
+
"connections_active" => 1,
|
48
|
+
"connections_waiting" => 0,
|
49
|
+
"connections_writing" => 1,
|
50
|
+
"total_requests" => 2757,
|
51
|
+
"connections_accepted" => 2757
|
52
|
+
},
|
53
|
+
"database" => {
|
54
|
+
"response_ratelimiting_metrics" => 0,
|
55
|
+
"keyauth_credentials" => 0,
|
56
|
+
"apis" => 0,
|
57
|
+
"consumers" => 0,
|
58
|
+
"plugins" => 0,
|
59
|
+
"nodes" => 1,
|
60
|
+
"basicauth_credentials" => 0,
|
61
|
+
"ratelimiting_metrics" => 0
|
62
|
+
}
|
63
|
+
}.to_s
|
64
|
+
}
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|