leofs_manager_client 0.2.12 → 0.2.13
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.
- data/lib/leofs_manager_client.rb +33 -33
- data/spec/dummy_tcp_server.rb +14 -14
- data/spec/leofs_manager_client_spec.rb +15 -15
- metadata +2 -2
data/lib/leofs_manager_client.rb
CHANGED
@@ -26,7 +26,7 @@ require "time"
|
|
26
26
|
require_relative "leofs_manager_client/leofs_manager_models"
|
27
27
|
|
28
28
|
module LeoFSManager
|
29
|
-
VERSION = "0.2.
|
29
|
+
VERSION = "0.2.13"
|
30
30
|
|
31
31
|
class Client
|
32
32
|
CMD_VERSION = "version"
|
@@ -41,16 +41,16 @@ module LeoFSManager
|
|
41
41
|
CMD_DU = "du %s"
|
42
42
|
CMD_COMPACT = "compact %s"
|
43
43
|
CMD_PURGE = "purge %s"
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
44
|
+
CMD_CRE_USER = "create-user %s %s"
|
45
|
+
CMD_UPD_USER_ROLE = "update-user-role %s %s"
|
46
|
+
CMD_UPD_USER_PASS = "update-user-password %s %s"
|
47
|
+
CMD_DEL_USER = "delete-user %s"
|
48
|
+
CMD_GET_USERS = "get-users"
|
49
|
+
CMD_SET_ENDPOINT = "set-endpoint %s"
|
50
|
+
CMD_DEL_ENDPOINT = "delete-endpoint %s"
|
51
|
+
CMD_GET_ENDPOINTS = "get-endpoints"
|
52
|
+
CMD_ADD_BUCKET = "add-bucket %s %s"
|
53
|
+
CMD_GET_BUCKETS = "get-buckets"
|
54
54
|
|
55
55
|
USER_ROLES = RoleDef.invert
|
56
56
|
|
@@ -167,79 +167,79 @@ module LeoFSManager
|
|
167
167
|
# Generate credential for LeoFS
|
168
168
|
# Return::
|
169
169
|
# Credential
|
170
|
-
def
|
171
|
-
Credential.new(sender(
|
170
|
+
def create_user(user_id, password=nil)
|
171
|
+
Credential.new(sender(CMD_CRE_USER % [user_id, password]))
|
172
172
|
end
|
173
173
|
|
174
174
|
# Update user role
|
175
175
|
# Return ::
|
176
176
|
# _nil_
|
177
|
-
def
|
177
|
+
def update_user_role(user_id, role)
|
178
178
|
role = role.to_sym if role.is_a? String
|
179
179
|
role = USER_ROLES[role] if role.is_a? Symbol
|
180
|
-
sender(
|
180
|
+
sender(CMD_UPD_USER_ROLE % [user_id, role])
|
181
181
|
nil
|
182
182
|
end
|
183
183
|
|
184
184
|
# Update user password
|
185
185
|
# Return::
|
186
186
|
# _nil_
|
187
|
-
def
|
188
|
-
sender(
|
187
|
+
def update_user_password(user_id, new_password)
|
188
|
+
sender(CMD_UPD_USER_PASS % [user_id, new_password])
|
189
189
|
nil
|
190
190
|
end
|
191
191
|
|
192
192
|
# Delete user
|
193
193
|
# Return::
|
194
194
|
# _nil_
|
195
|
-
def
|
196
|
-
sender(
|
195
|
+
def delete_user(user_id)
|
196
|
+
sender(CMD_DEL_USER % user_id)
|
197
197
|
nil
|
198
198
|
end
|
199
199
|
|
200
|
-
def
|
201
|
-
users = sender(
|
200
|
+
def get_users
|
201
|
+
users = sender(CMD_GET_USERS)[:users]
|
202
202
|
users.map {|account| User.new(account) }
|
203
203
|
end
|
204
204
|
|
205
205
|
# Insert an endpoint in the system
|
206
206
|
# Return::
|
207
207
|
# _nil_
|
208
|
-
def
|
209
|
-
sender(
|
208
|
+
def set_endpoint(endpoint)
|
209
|
+
sender(CMD_SET_ENDPOINT % endpoint)
|
210
210
|
nil
|
211
211
|
end
|
212
212
|
|
213
213
|
# Remove an endpoint from the system
|
214
214
|
# Return::
|
215
215
|
# _nil_
|
216
|
-
def
|
217
|
-
sender(
|
216
|
+
def delete_endpoint(endpoint)
|
217
|
+
sender(CMD_DEL_ENDPOINT % endpoint)
|
218
218
|
nil
|
219
219
|
end
|
220
|
-
alias :
|
220
|
+
alias :del_endpoint :delete_endpoint
|
221
221
|
|
222
222
|
# Retrieve an endpoint in the system
|
223
223
|
# Return::
|
224
224
|
# Array of Endpoint
|
225
|
-
def
|
226
|
-
endpoints = sender(
|
225
|
+
def get_endpoints
|
226
|
+
endpoints = sender(CMD_GET_ENDPOINTS)[:endpoints]
|
227
227
|
endpoints.map {|endpoint| Endpoint.new(endpoint) }
|
228
228
|
end
|
229
229
|
|
230
230
|
# Add an Bucket in the system
|
231
231
|
# Return::
|
232
232
|
# _nil_
|
233
|
-
def
|
234
|
-
sender(
|
233
|
+
def add_bucket(bucket_name, access_key_id)
|
234
|
+
sender(CMD_ADD_BUCKET % [bucket_name, access_key_id])
|
235
235
|
nil
|
236
236
|
end
|
237
237
|
|
238
238
|
# Retrieve all buckets from the system
|
239
239
|
# Return::
|
240
240
|
# Array of Bucket
|
241
|
-
def
|
242
|
-
buckets = sender(
|
241
|
+
def get_buckets
|
242
|
+
buckets = sender(CMD_GET_BUCKETS)[:buckets]
|
243
243
|
buckets.map {|bucket| Bucket.new(bucket) }
|
244
244
|
end
|
245
245
|
|
@@ -339,6 +339,6 @@ if __FILE__ == $PROGRAM_NAME
|
|
339
339
|
p m.version
|
340
340
|
p m.status
|
341
341
|
p m.status("storage_0@127.0.0.1")
|
342
|
-
p m.
|
342
|
+
p m.get_buckets()
|
343
343
|
p m.whereis("photo/hawaii-0.jpg")
|
344
344
|
end
|
data/spec/dummy_tcp_server.rb
CHANGED
@@ -78,7 +78,7 @@ module Dummy
|
|
78
78
|
]
|
79
79
|
}.to_json
|
80
80
|
|
81
|
-
|
81
|
+
GetEndpoints = {
|
82
82
|
:endpoints => [
|
83
83
|
{:endpoint => "s3.amazonaws.com", :created_at=>"2012-09-21 15:08:11 +0900"},
|
84
84
|
{:endpoint => "localhost", :created_at=>"2012-09-21 15:08:11 +0900"},
|
@@ -87,7 +87,7 @@ module Dummy
|
|
87
87
|
]
|
88
88
|
}.to_json
|
89
89
|
|
90
|
-
|
90
|
+
GetBuckets = {
|
91
91
|
:buckets => [
|
92
92
|
{
|
93
93
|
:bucket => "test",
|
@@ -97,13 +97,13 @@ module Dummy
|
|
97
97
|
]
|
98
98
|
}.to_json
|
99
99
|
|
100
|
-
|
100
|
+
GetUsers = {
|
101
101
|
:users => [
|
102
102
|
{ :access_key_id => "05236", :user_id => "_test_leofs_", :role_id => 1, :created_at => "2012-11-20 15:13:20 +0900" }
|
103
103
|
]
|
104
104
|
}.to_json
|
105
105
|
|
106
|
-
|
106
|
+
CreateUser = {
|
107
107
|
:access_key_id => "xxxxxxxxxxxxxxxxxxxx",
|
108
108
|
:secret_access_key => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
109
109
|
}.to_json
|
@@ -139,18 +139,18 @@ module Dummy
|
|
139
139
|
Response::Login
|
140
140
|
when "status"
|
141
141
|
Response::Status
|
142
|
-
when "
|
143
|
-
Response::
|
142
|
+
when "get-buckets"
|
143
|
+
Response::GetBuckets
|
144
144
|
when "whereis"
|
145
145
|
Response::Whereis
|
146
|
-
when "
|
147
|
-
Response::
|
148
|
-
when "
|
149
|
-
Response::
|
150
|
-
when "
|
151
|
-
Response::
|
152
|
-
when "
|
153
|
-
Response::
|
146
|
+
when "get-endpoints"
|
147
|
+
Response::GetEndpoints
|
148
|
+
when "get-buckets"
|
149
|
+
Response::GetBuckets
|
150
|
+
when "get-users"
|
151
|
+
Response::GetUsers
|
152
|
+
when "create-user"
|
153
|
+
Response::CreateUser
|
154
154
|
else
|
155
155
|
{ :result => line }.to_json
|
156
156
|
end
|
@@ -36,9 +36,9 @@ NoResultAPIs = {
|
|
36
36
|
:rebalance => 0,
|
37
37
|
:compact => 1,
|
38
38
|
:purge => 1,
|
39
|
-
:
|
40
|
-
:
|
41
|
-
:
|
39
|
+
:set_endpoint => 1,
|
40
|
+
:del_endpoint => 1,
|
41
|
+
:add_bucket => 2
|
42
42
|
}
|
43
43
|
|
44
44
|
include LeoFSManager
|
@@ -90,49 +90,49 @@ describe LeoFSManager do
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
describe "#
|
93
|
+
describe "#create_user" do
|
94
94
|
it "returns Credential" do
|
95
|
-
subject.
|
95
|
+
subject.create_user("user_id", "password").should be_a Credential
|
96
96
|
end
|
97
97
|
|
98
98
|
it "goes with only user_id" do
|
99
|
-
subject.
|
99
|
+
subject.create_user("user_id").should be_a Credential
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
describe "#
|
103
|
+
describe "#update_user_role" do
|
104
104
|
it "returns nil" do
|
105
|
-
subject.
|
105
|
+
subject.update_user_role("user_id", "admin").should be_nil
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
describe "#
|
109
|
+
describe "#update_user_password" do
|
110
110
|
it "returns nil" do
|
111
|
-
subject.
|
111
|
+
subject.update_user_password("user_id", "new_password").should be_nil
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
describe "#
|
115
|
+
describe "#delete_user" do
|
116
116
|
it "returns nil" do
|
117
|
-
subject.
|
117
|
+
subject.delete_user("user_id").should be_nil
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
-
its(:
|
121
|
+
its(:get_users) do
|
122
122
|
should be_a Array
|
123
123
|
subject.each do |account|
|
124
124
|
account.should be_a User
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
its(:
|
128
|
+
its(:get_endpoints) do
|
129
129
|
should be_a Array
|
130
130
|
subject.each do |endpoint|
|
131
131
|
endpoint.should be_a Endpoint
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
-
its(:
|
135
|
+
its(:get_buckets) do
|
136
136
|
should be_a Array
|
137
137
|
subject.each do |buckets|
|
138
138
|
buckets.should be_a Bucket
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leofs_manager_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-12-
|
13
|
+
date: 2012-12-13 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Client for LeoFS Manager
|
16
16
|
email:
|