apitool-client 0.0.8 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/apitool/client.rb +0 -2
- data/lib/apitool/client/backup.rb +10 -8
- data/lib/apitool/client/version.rb +1 -1
- data/lib/apitool/client/vpn.rb +10 -8
- data/spec/apitool/client/apitool_client_spec.rb +1 -1
- data/spec/apitool/client/backup_spec.rb +18 -18
- data/spec/spec_helper.rb +1 -1
- metadata +2 -8
- data/lib/apitool/client/api_key.rb +0 -95
- data/lib/apitool/client/role.rb +0 -63
- data/spec/apitool/client/api_key_spec.rb +0 -37
- data/spec/apitool/client/role_spec.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f295ba4e37a44866405725fdf28508338dca881d
|
4
|
+
data.tar.gz: 615de65e3f436df81e96b8bd2bc0bf48a36ed6a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55b64353ca58714019a15df016921648023483d972140b5f855ec70666886753fcc77c1c1612b71bf3d21d069a1aca41a5f3bb38059fcfb60dcdc753ef41b545
|
7
|
+
data.tar.gz: 58a1cdc8ab8b9093c1186804935cc98379620c0e7ce01d5cdd9d3b43a8f371b0cc085b1450f8a78def4dbadeed70f7d3c2f1031a081cd8f4e8c31245c24a9ae0
|
data/lib/apitool/client.rb
CHANGED
@@ -14,8 +14,8 @@ class Apitool::Client::Backup < Apitool::Client::ApitoolClient
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def show(
|
18
|
-
get("/backups/#{
|
17
|
+
def show(uuid)
|
18
|
+
get("/backups/#{uuid}") do |response|
|
19
19
|
if response.code == 200
|
20
20
|
parse(response)
|
21
21
|
else
|
@@ -24,11 +24,13 @@ class Apitool::Client::Backup < Apitool::Client::ApitoolClient
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
# {
|
28
|
+
# uuid: "some unique identifier",
|
29
|
+
# b64_path: "some_path_encrypted_in_b64"
|
30
|
+
# }
|
31
|
+
def create(options = {})
|
28
32
|
parameters = {
|
29
|
-
backup:
|
30
|
-
b64_path: path_to_b64_path(path)
|
31
|
-
}
|
33
|
+
backup: options
|
32
34
|
}
|
33
35
|
post("/backups", parameters) do |response|
|
34
36
|
if response.code == 200
|
@@ -39,8 +41,8 @@ class Apitool::Client::Backup < Apitool::Client::ApitoolClient
|
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
|
-
def destroy(
|
43
|
-
delete("/backups/#{
|
44
|
+
def destroy(uuid)
|
45
|
+
delete("/backups/#{uuid}") do |response|
|
44
46
|
if response.code == 200
|
45
47
|
parse(response)
|
46
48
|
else
|
data/lib/apitool/client/vpn.rb
CHANGED
@@ -10,8 +10,8 @@ class Apitool::Client::Vpn < Apitool::Client::ApitoolClient
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def show(
|
14
|
-
get("/vpns/#{
|
13
|
+
def show(uuid)
|
14
|
+
get("/vpns/#{uuid}") do |response|
|
15
15
|
if response.code == 200
|
16
16
|
parse(response)
|
17
17
|
else
|
@@ -20,11 +20,13 @@ class Apitool::Client::Vpn < Apitool::Client::ApitoolClient
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
# {
|
24
|
+
# uuid: "some unique identifier",
|
25
|
+
# identifier: "email@domain.com"
|
26
|
+
# }
|
27
|
+
def create(options = {})
|
24
28
|
parameters = {
|
25
|
-
vpn:
|
26
|
-
username: username
|
27
|
-
}
|
29
|
+
vpn: options
|
28
30
|
}
|
29
31
|
post("/vpns", parameters) do |response|
|
30
32
|
if response.code == 200
|
@@ -35,8 +37,8 @@ class Apitool::Client::Vpn < Apitool::Client::ApitoolClient
|
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
|
-
def destroy(
|
39
|
-
delete("/vpns/#{
|
40
|
+
def destroy(uuid)
|
41
|
+
delete("/vpns/#{uuid}") do |response|
|
40
42
|
if response.code == 200
|
41
43
|
parse(response)
|
42
44
|
else
|
@@ -7,26 +7,26 @@ describe Apitool::Client::Backup, order: :defined do
|
|
7
7
|
port: 3001,
|
8
8
|
ssl: false,
|
9
9
|
token: API_KEY,
|
10
|
-
version: "
|
10
|
+
version: "v2"
|
11
11
|
})
|
12
12
|
end
|
13
13
|
|
14
|
-
it "should be possible to crud backups" do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
14
|
+
#it "should be possible to crud backups" do
|
15
|
+
# expect(@client.index.class).to be Array
|
16
|
+
# uuid = SecureRandom.uuid
|
17
|
+
# backup = "david"
|
18
|
+
# path = [uuid, backup].join('/')
|
19
|
+
#
|
20
|
+
# backup = @client.create(path)
|
21
|
+
# expect(@client.result).to be 200
|
22
|
+
# expect(backup[:backup][:path]).to eq path
|
23
|
+
#
|
24
|
+
# loaded_backup = @client.show(path)
|
25
|
+
# expect(@client.result).to be 200
|
26
|
+
# expect(loaded_backup[:backup][:path]).to eq path
|
27
|
+
#
|
28
|
+
# @client.destroy(path)
|
29
|
+
# expect(@client.result).to be 200
|
30
|
+
#end
|
31
31
|
|
32
32
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apitool-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Terranova David
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,18 +108,14 @@ files:
|
|
108
108
|
- Rakefile
|
109
109
|
- apitool-client.gemspec
|
110
110
|
- lib/apitool/client.rb
|
111
|
-
- lib/apitool/client/api_key.rb
|
112
111
|
- lib/apitool/client/apitool_client.rb
|
113
112
|
- lib/apitool/client/backup.rb
|
114
113
|
- lib/apitool/client/logger.rb
|
115
|
-
- lib/apitool/client/role.rb
|
116
114
|
- lib/apitool/client/version.rb
|
117
115
|
- lib/apitool/client/vpn.rb
|
118
116
|
- log/.gitignore
|
119
|
-
- spec/apitool/client/api_key_spec.rb
|
120
117
|
- spec/apitool/client/apitool_client_spec.rb
|
121
118
|
- spec/apitool/client/backup_spec.rb
|
122
|
-
- spec/apitool/client/role_spec.rb
|
123
119
|
- spec/apitool/client_spec.rb
|
124
120
|
- spec/spec_helper.rb
|
125
121
|
homepage: ''
|
@@ -147,9 +143,7 @@ signing_key:
|
|
147
143
|
specification_version: 4
|
148
144
|
summary: APITool client.
|
149
145
|
test_files:
|
150
|
-
- spec/apitool/client/api_key_spec.rb
|
151
146
|
- spec/apitool/client/apitool_client_spec.rb
|
152
147
|
- spec/apitool/client/backup_spec.rb
|
153
|
-
- spec/apitool/client/role_spec.rb
|
154
148
|
- spec/apitool/client_spec.rb
|
155
149
|
- spec/spec_helper.rb
|
@@ -1,95 +0,0 @@
|
|
1
|
-
class Apitool::Client::ApiKey < Apitool::Client::ApitoolClient
|
2
|
-
|
3
|
-
# ApiKey
|
4
|
-
#
|
5
|
-
# {
|
6
|
-
# :api_key => {
|
7
|
-
# :id => NUMERIC,
|
8
|
-
# :token => "TOKEN",
|
9
|
-
# :roles=>[
|
10
|
-
# {
|
11
|
-
# :role => {
|
12
|
-
# :id => 1,
|
13
|
-
# :name=>"master"
|
14
|
-
# }
|
15
|
-
# },
|
16
|
-
# {
|
17
|
-
# :role => {
|
18
|
-
# :id => 2,
|
19
|
-
# :name=>"admin"
|
20
|
-
# }
|
21
|
-
# },
|
22
|
-
# {
|
23
|
-
# :role => {
|
24
|
-
# :id => 3,
|
25
|
-
# :name=>"user"
|
26
|
-
# }
|
27
|
-
# }
|
28
|
-
# ]
|
29
|
-
# }
|
30
|
-
# }
|
31
|
-
|
32
|
-
def index
|
33
|
-
get('/api_keys') do |response, request, result|
|
34
|
-
if response.code == 200
|
35
|
-
parse(response)
|
36
|
-
else
|
37
|
-
nil
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def show(token)
|
43
|
-
get("/api_keys/#{token}") do |response|
|
44
|
-
if response.code == 200
|
45
|
-
parse(response)
|
46
|
-
else
|
47
|
-
nil
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# roles = 3
|
53
|
-
# roles = [3]
|
54
|
-
# roles = [1, 2, 3]
|
55
|
-
def create(roles = 3)
|
56
|
-
parameters = {
|
57
|
-
api_key: {
|
58
|
-
role_ids: [roles].flatten
|
59
|
-
}
|
60
|
-
}
|
61
|
-
post("/api_keys", parameters) do |response|
|
62
|
-
if response.code == 200
|
63
|
-
parse(response)
|
64
|
-
else
|
65
|
-
nil
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def update(token, roles = 3)
|
71
|
-
parameters = {
|
72
|
-
api_key: {
|
73
|
-
role_ids: [roles].flatten
|
74
|
-
}
|
75
|
-
}
|
76
|
-
put("/api_keys/#{token}", parameters) do |response|
|
77
|
-
if response.code == 200
|
78
|
-
parse(response)
|
79
|
-
else
|
80
|
-
nil
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def destroy(token)
|
86
|
-
delete("/api_keys/#{token}") do |response|
|
87
|
-
if response.code == 200
|
88
|
-
parse(response)
|
89
|
-
else
|
90
|
-
nil
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
data/lib/apitool/client/role.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
class Apitool::Client::Role < Apitool::Client::ApitoolClient
|
2
|
-
|
3
|
-
def index
|
4
|
-
get('/roles') do |response, request, result|
|
5
|
-
if response.code == 200
|
6
|
-
parse(response)
|
7
|
-
else
|
8
|
-
nil
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def show(name)
|
14
|
-
get("/roles/#{name}") do |response|
|
15
|
-
if response.code == 200
|
16
|
-
parse(response)
|
17
|
-
else
|
18
|
-
nil
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def create(name = nil)
|
24
|
-
parameters = {
|
25
|
-
role: {
|
26
|
-
name: name
|
27
|
-
}
|
28
|
-
}
|
29
|
-
post("/roles", parameters) do |response|
|
30
|
-
if response.code == 200
|
31
|
-
parse(response)
|
32
|
-
else
|
33
|
-
nil
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def update(name, new_name)
|
39
|
-
parameters = {
|
40
|
-
role: {
|
41
|
-
name: new_name
|
42
|
-
}
|
43
|
-
}
|
44
|
-
put("/roles/#{name}", parameters) do |response|
|
45
|
-
if response.code == 200
|
46
|
-
parse(response)
|
47
|
-
else
|
48
|
-
nil
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def destroy(name)
|
54
|
-
delete("/roles/#{name}") do |response|
|
55
|
-
if response.code == 200
|
56
|
-
parse(response)
|
57
|
-
else
|
58
|
-
nil
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Apitool::Client::ApiKey, order: :defined do
|
4
|
-
before(:context) do
|
5
|
-
@client = Apitool::Client::ApiKey.new({
|
6
|
-
host: "127.0.0.1",
|
7
|
-
port: 3001,
|
8
|
-
ssl: false,
|
9
|
-
token: API_KEY,
|
10
|
-
version: "v1"
|
11
|
-
})
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should be possible to crud api keys" do
|
15
|
-
expect(@client.index.class).to be Array
|
16
|
-
|
17
|
-
api_key_count = @client.index.count
|
18
|
-
api_key = @client.create(3)
|
19
|
-
expect(@client.result).to be 200
|
20
|
-
expect(api_key[:api_key][:roles][0][:role][:name]).to eq 'user'
|
21
|
-
@new_key = api_key[:api_key][:token]
|
22
|
-
expect(@client.index.count).to be (api_key_count + 1)
|
23
|
-
|
24
|
-
api_key = @client.show(@new_key)
|
25
|
-
expect(@client.result).to be 200
|
26
|
-
|
27
|
-
api_key = @client.update(@new_key, 2)
|
28
|
-
expect(@client.result).to be 200
|
29
|
-
expect(api_key[:api_key][:roles][0][:role][:name]).to eq 'admin'
|
30
|
-
|
31
|
-
api_key_count = @client.index.count
|
32
|
-
@client.destroy(@new_key)
|
33
|
-
expect(@client.result).to be 200
|
34
|
-
expect(@client.index.count).to be (api_key_count - 1)
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Apitool::Client::Role, order: :defined do
|
4
|
-
before(:context) do
|
5
|
-
@client = Apitool::Client::Role.new({
|
6
|
-
host: "127.0.0.1",
|
7
|
-
port: 3001,
|
8
|
-
ssl: false,
|
9
|
-
token: API_KEY,
|
10
|
-
version: "v1"
|
11
|
-
})
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should be possible to list roles" do
|
15
|
-
expect(@client.index.class).to be Array
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should be possible to create a role" do
|
19
|
-
role_count = @client.index.count
|
20
|
-
role = @client.create('role')
|
21
|
-
expect(@client.result).to be 200
|
22
|
-
expect(role[:role][:name]).to eq 'role'
|
23
|
-
expect(@client.index.count).to be (role_count + 1)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should be possible to fetch a role" do
|
27
|
-
role = @client.show('role')
|
28
|
-
expect(@client.result).to be 200
|
29
|
-
expect(role[:role][:name]).to eq 'role'
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should be possible to update a role" do
|
33
|
-
role = @client.update('role', 'new_role')
|
34
|
-
expect(@client.result).to be 200
|
35
|
-
expect(role[:role][:name]).to eq 'new_role'
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should be possible to destroy a role" do
|
39
|
-
role_count = @client.index.count
|
40
|
-
@client.destroy('new_role')
|
41
|
-
expect(@client.result).to be 200
|
42
|
-
expect(@client.index.count).to be (role_count - 1)
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|