reedb 0.10.rc1 → 0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -12
- data/Gemfile.lock +17 -11
- data/bin/reedbd +65 -23
- data/lib/reedb/constants.rb +11 -23
- data/lib/reedb/daemon_wrapper.rb +138 -121
- data/lib/reedb/debouncer.rb +129 -0
- data/lib/reedb/errors/daemon_errors.rb +4 -4
- data/lib/reedb/errors/exit_errors.rb +12 -0
- data/lib/reedb/errors/reedb_errors.rb +21 -0
- data/lib/reedb/errors/vault_errors.rb +8 -6
- data/lib/reedb/reevault.rb +84 -72
- data/lib/reedb/security/encryption.rb +1 -5
- data/lib/reedb/security/tokens.rb +21 -0
- data/lib/reedb/utils/logger.rb +5 -5
- data/lib/reedb/utils/uuids.rb +40 -132
- data/lib/reedb.rb +518 -272
- data/reedb.gemspec +32 -24
- data/tests/embeddedc/MyTest/Makefile +238 -0
- data/tests/embeddedc/MyTest/MyTest.c +27 -0
- data/tests/embeddedc/MyTest/MyTest.o +0 -0
- data/tests/embeddedc/MyTest/extconf.rb +11 -0
- data/tests/embeddedc/MyTest/mytest.so +0 -0
- data/tests/embeddedc/mytest.rb +8 -0
- data/tests/http_tester.py +208 -0
- data/tests/play.rb +60 -4
- data/tests/tests.rb +7 -59
- data/tmp/gems/aes-0.5.0.spec +80 -0
- data/tmp/gems/digest-tiger-1.0.2.spec +85 -0
- data/tmp/gems/main.template +118 -0
- data/tmp/gems/twofish-1.0.5.spec +75 -0
- metadata +45 -16
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
data/lib/reedb/daemon_wrapper.rb
CHANGED
@@ -18,7 +18,14 @@ require 'sinatra'
|
|
18
18
|
require 'rack'
|
19
19
|
|
20
20
|
# Reedb requirements
|
21
|
-
|
21
|
+
# This rescue block fixes the issue where reedbd could not be run without system integration
|
22
|
+
begin
|
23
|
+
require 'reedb'
|
24
|
+
rescue LoadError => e
|
25
|
+
require_relative '../reedb'
|
26
|
+
end
|
27
|
+
|
28
|
+
require_relative 'errors/exit_errors'
|
22
29
|
|
23
30
|
# HTTP handler class that registers the functions
|
24
31
|
# for the vault interface
|
@@ -32,15 +39,15 @@ class ReedbHandler < Sinatra::Base
|
|
32
39
|
# PUT /vaults/scope Scope a vault that already exists
|
33
40
|
|
34
41
|
# POST /vaults/*vault-id*/request_token Auth for vault with ID
|
35
|
-
# [AUTH] POST /vaults/*vault-id*/headers Return vault headers
|
36
|
-
# [AUTH] POST /vaults/*vault-id*/close Close vault with ID
|
42
|
+
# [AUTH] POST /vaults/*vault-id*/headers Return vault headers
|
43
|
+
# [AUTH] POST /vaults/*vault-id*/close Close vault with ID
|
37
44
|
|
38
|
-
# [AUTH] POST /vaults/*vault-id*/files/*file-id* Returns body of a file
|
39
|
-
# [AUTH] POST /vaults/*vault-id*/files/*file-id*/history Returns history of a file (???)
|
45
|
+
# [AUTH] POST /vaults/*vault-id*/files/*file-id* Returns body of a file
|
46
|
+
# [AUTH] POST /vaults/*vault-id*/files/*file-id*/history Returns history of a file (???)
|
40
47
|
|
41
|
-
# [AUTH] PUT /vaults/*vault-id*/files Create file
|
42
|
-
# [AUTH] POST /vaults/*vault-id*/files/*file-id* Update file contents
|
43
|
-
# [AUTH] POST /vaults/*vault-id*/files/*file-id*/remove Removes a file
|
48
|
+
# [AUTH] PUT /vaults/*vault-id*/files Create file
|
49
|
+
# [AUTH] POST /vaults/*vault-id*/files/*file-id* Update file contents
|
50
|
+
# [AUTH] POST /vaults/*vault-id*/files/*file-id*/remove Removes a file
|
44
51
|
|
45
52
|
configure :production, :development do
|
46
53
|
enable :logging
|
@@ -50,8 +57,8 @@ class ReedbHandler < Sinatra::Base
|
|
50
57
|
status status_code # Set http status code
|
51
58
|
content_type 'application/json'
|
52
59
|
response = { 'success' => (status_code >= 400 ? false : true),
|
53
|
-
|
54
|
-
|
60
|
+
'message' => message,
|
61
|
+
'payload' => payload }
|
55
62
|
return response.to_json
|
56
63
|
end
|
57
64
|
|
@@ -66,7 +73,7 @@ class ReedbHandler < Sinatra::Base
|
|
66
73
|
|
67
74
|
# If request was garbage
|
68
75
|
unless request.content_type == 'application/json'
|
69
|
-
|
76
|
+
return build_response(400, 'Data was malformed. Expects JSON!')
|
70
77
|
end
|
71
78
|
|
72
79
|
# Check if the JSON data
|
@@ -74,7 +81,7 @@ class ReedbHandler < Sinatra::Base
|
|
74
81
|
begin
|
75
82
|
data = JSON.parse(request.body.read)
|
76
83
|
rescue
|
77
|
-
return build_response(400, 'JSON data was malformed!')
|
84
|
+
return build_response(400, 'JSON data was malformed!')
|
78
85
|
end
|
79
86
|
|
80
87
|
name = data["name"] if data["name"]
|
@@ -83,8 +90,8 @@ class ReedbHandler < Sinatra::Base
|
|
83
90
|
encryption = :auto # TODO: Handle this better!
|
84
91
|
|
85
92
|
# This gets fired if not all neccesary information was provided.
|
86
|
-
if name == nil
|
87
|
-
return build_response(400, 'Required data fields are missing from JSON data body!')
|
93
|
+
if name == nil || path == nil || passphrase == nil
|
94
|
+
return build_response(400, 'Required data fields are missing from JSON data body!')
|
88
95
|
end
|
89
96
|
|
90
97
|
# Now deal with the actual stuff
|
@@ -92,25 +99,26 @@ class ReedbHandler < Sinatra::Base
|
|
92
99
|
|
93
100
|
# Catches ALL possible errors that can occur during this operation!
|
94
101
|
begin
|
95
|
-
token = Reedb::Vault::create_vault(name, path, passphrase
|
102
|
+
token = Reedb::Vault::create_vault(name, path, passphrase)
|
96
103
|
rescue InsecureUserPasswordError => e
|
97
104
|
return build_response(400, e.message)
|
98
105
|
|
99
106
|
rescue VaultExistsAtLocationError => e
|
100
107
|
return build_response(409, e.message)
|
101
108
|
|
109
|
+
# Thank you descriptive exception messages
|
102
110
|
rescue VaultWritePermissionsError,
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
111
|
+
VaultMissingConfigurationError,
|
112
|
+
VaultLoggerError,
|
113
|
+
BadCacheError,
|
114
|
+
EncryptionFailedError,
|
115
|
+
DecryptionFailedError => e
|
108
116
|
|
109
117
|
# Bundled error return
|
110
118
|
return build_response(500, e.message)
|
111
119
|
end
|
112
120
|
|
113
|
-
return build_response(201,
|
121
|
+
return build_response(201, 'Vault was successfully crated at location', token)
|
114
122
|
end
|
115
123
|
|
116
124
|
# Scope a new vault on the system.
|
@@ -125,14 +133,14 @@ class ReedbHandler < Sinatra::Base
|
|
125
133
|
begin
|
126
134
|
data = JSON.parse(request.body.read)
|
127
135
|
rescue
|
128
|
-
return build_response(400, 'JSON data was malformed!')
|
136
|
+
return build_response(400, 'JSON data was malformed!')
|
129
137
|
end
|
130
138
|
|
131
|
-
name = data[
|
132
|
-
path = data[
|
139
|
+
name = data['name'] ? data['name'] : nil
|
140
|
+
path = data['path'] ? data['path'] : nil
|
133
141
|
|
134
|
-
if name == nil
|
135
|
-
return build_response(400, 'Required data fields are missing from JSON data body!')
|
142
|
+
if name == nil || path == nil
|
143
|
+
return build_response(400, 'Required data fields are missing from JSON data body!')
|
136
144
|
end
|
137
145
|
|
138
146
|
begin
|
@@ -142,7 +150,7 @@ class ReedbHandler < Sinatra::Base
|
|
142
150
|
end
|
143
151
|
|
144
152
|
# If everything went well
|
145
|
-
return build_response(200,
|
153
|
+
return build_response(200, 'Vault successfully scoped. It is now available to load.')
|
146
154
|
end
|
147
155
|
|
148
156
|
put '/vaults/unscope' do
|
@@ -156,14 +164,14 @@ class ReedbHandler < Sinatra::Base
|
|
156
164
|
begin
|
157
165
|
data = JSON.parse(request.body.read)
|
158
166
|
rescue
|
159
|
-
return build_response(400, 'JSON data was malformed!')
|
167
|
+
return build_response(400, 'JSON data was malformed!')
|
160
168
|
end
|
161
169
|
|
162
170
|
name = data["name"] if data["name"]
|
163
171
|
path = data["path"] if data["path"]
|
164
172
|
|
165
|
-
if name == nil
|
166
|
-
return build_response(400, 'Required data fields are missing from JSON data body!')
|
173
|
+
if name == nil || path == nil
|
174
|
+
return build_response(400, 'Required data fields are missing from JSON data body!')
|
167
175
|
end
|
168
176
|
|
169
177
|
begin
|
@@ -174,14 +182,12 @@ class ReedbHandler < Sinatra::Base
|
|
174
182
|
|
175
183
|
# If everything went well
|
176
184
|
return build_response(200, "Vault successfully unscoped and will not show up in vault lists anymore.")
|
177
|
-
end
|
185
|
+
end
|
178
186
|
|
179
187
|
# Request a token for a vault
|
180
188
|
post '/vaults/*/request_token' do
|
181
189
|
vault_uuid = params[:splat][0]
|
182
190
|
|
183
|
-
puts vault_uuid
|
184
|
-
|
185
191
|
if vault_uuid == nil
|
186
192
|
return build_response(400, 'Missing vault access id.')
|
187
193
|
end
|
@@ -196,14 +202,14 @@ class ReedbHandler < Sinatra::Base
|
|
196
202
|
begin
|
197
203
|
data = JSON.parse(request.body.read)
|
198
204
|
rescue
|
199
|
-
return build_response(400, 'JSON data was malformed!')
|
205
|
+
return build_response(400, 'JSON data was malformed!')
|
200
206
|
end
|
201
207
|
|
202
|
-
passphrase = data[
|
208
|
+
passphrase = data['passphrase'] if data['passphrase']
|
203
209
|
permanent = false # TODO: Implement this!
|
204
210
|
|
205
|
-
if passphrase == nil
|
206
|
-
return build_response(400, 'Required data fields are missing from JSON data body!')
|
211
|
+
if passphrase == nil || permanent == nil
|
212
|
+
return build_response(400, 'Required data fields are missing from JSON data body!')
|
207
213
|
end
|
208
214
|
|
209
215
|
token = nil
|
@@ -213,7 +219,7 @@ class ReedbHandler < Sinatra::Base
|
|
213
219
|
return build_response(404, e.message)
|
214
220
|
|
215
221
|
rescue WrongUserPasswordError => e
|
216
|
-
return build_response(401, e.message)
|
222
|
+
return build_response(401, e.message)
|
217
223
|
end
|
218
224
|
|
219
225
|
return build_response(200, "Access successfully granted for vault", token)
|
@@ -222,7 +228,7 @@ class ReedbHandler < Sinatra::Base
|
|
222
228
|
post '/vaults/*/free_token' do
|
223
229
|
vault_uuid = params[:splat][0]
|
224
230
|
|
225
|
-
unless vault_uuid
|
231
|
+
unless vault_uuid
|
226
232
|
return build_response(400, 'Missing vault access id.')
|
227
233
|
end
|
228
234
|
|
@@ -236,13 +242,13 @@ class ReedbHandler < Sinatra::Base
|
|
236
242
|
begin
|
237
243
|
data = JSON.parse(request.body.read)
|
238
244
|
rescue
|
239
|
-
return build_response(400, 'JSON data was malformed!')
|
245
|
+
return build_response(400, 'JSON data was malformed!')
|
240
246
|
end
|
241
247
|
|
242
248
|
token = data["token"] if data["token"]
|
243
249
|
|
244
250
|
if token == nil
|
245
|
-
return build_response(400, 'Required data fields are missing from JSON data body!')
|
251
|
+
return build_response(400, 'Required data fields are missing from JSON data body!')
|
246
252
|
end
|
247
253
|
|
248
254
|
begin
|
@@ -258,7 +264,7 @@ class ReedbHandler < Sinatra::Base
|
|
258
264
|
post '/vaults/*/close' do
|
259
265
|
vault_uuid = params[:splat][0]
|
260
266
|
|
261
|
-
unless vault_uuid
|
267
|
+
unless vault_uuid
|
262
268
|
return build_response(400, 'Missing vault access id.')
|
263
269
|
end
|
264
270
|
|
@@ -272,18 +278,18 @@ class ReedbHandler < Sinatra::Base
|
|
272
278
|
begin
|
273
279
|
data = JSON.parse(request.body.read)
|
274
280
|
rescue
|
275
|
-
return build_response(400, 'JSON data was malformed!')
|
281
|
+
return build_response(400, 'JSON data was malformed!')
|
276
282
|
end
|
277
283
|
|
278
|
-
token = data[
|
279
|
-
|
284
|
+
token = data['token'] if data['token']
|
285
|
+
|
280
286
|
unless token
|
281
|
-
return build_response(400, 'Required data fields are missing from JSON data body!')
|
287
|
+
return build_response(400, 'Required data fields are missing from JSON data body!')
|
282
288
|
end
|
283
289
|
|
284
290
|
begin
|
285
291
|
Reedb::Vault::close_vault(vault_uuid, token)
|
286
|
-
|
292
|
+
|
287
293
|
rescue VaultNotAvailableError => e
|
288
294
|
return build_response(404, e.message)
|
289
295
|
|
@@ -298,14 +304,13 @@ class ReedbHandler < Sinatra::Base
|
|
298
304
|
end
|
299
305
|
|
300
306
|
return build_response(200, "Vault #{vault_uuid} successfully closed.")
|
301
|
-
|
302
307
|
end
|
303
308
|
|
304
309
|
# [AUTH] Request headers for a vault with token/ id
|
305
310
|
post '/vaults/*/headers' do
|
306
311
|
vault_uuid = params[:splat][0]
|
307
312
|
|
308
|
-
if vault_uuid == nil
|
313
|
+
if vault_uuid == nil
|
309
314
|
return build_response(400, 'Missing vault access id.')
|
310
315
|
end
|
311
316
|
|
@@ -319,20 +324,20 @@ class ReedbHandler < Sinatra::Base
|
|
319
324
|
begin
|
320
325
|
data = JSON.parse(request.body.read)
|
321
326
|
rescue
|
322
|
-
return build_response(400, 'JSON data was malformed!')
|
327
|
+
return build_response(400, 'JSON data was malformed!')
|
323
328
|
end
|
324
329
|
|
325
330
|
token = data["token"] if data["token"]
|
326
331
|
search = data["search"] if data["search"]
|
327
332
|
|
328
333
|
if token == nil
|
329
|
-
return build_response(400, 'Required data fields are missing from JSON data body!')
|
334
|
+
return build_response(400, 'Required data fields are missing from JSON data body!')
|
330
335
|
end
|
331
336
|
|
332
337
|
headers = nil
|
333
338
|
begin
|
334
339
|
headers = Reedb::Vault::access_headers(vault_uuid, token, search)
|
335
|
-
|
340
|
+
|
336
341
|
rescue VaultNotAvailableError => e
|
337
342
|
return build_response(404, e.message)
|
338
343
|
|
@@ -350,11 +355,11 @@ class ReedbHandler < Sinatra::Base
|
|
350
355
|
end
|
351
356
|
|
352
357
|
# [AUTH] Return body of a file
|
353
|
-
post '/vaults/*/files
|
358
|
+
post '/vaults/*/files/*/body' do
|
354
359
|
vault_uuid = params[:splat][0]
|
355
360
|
file_id = params[:splat][1]
|
356
361
|
|
357
|
-
unless vault_uuid
|
362
|
+
unless vault_uuid
|
358
363
|
return build_response(400, 'Missing vault access id.')
|
359
364
|
end
|
360
365
|
|
@@ -368,21 +373,16 @@ class ReedbHandler < Sinatra::Base
|
|
368
373
|
begin
|
369
374
|
data = JSON.parse(request.body.read)
|
370
375
|
rescue
|
371
|
-
return build_response(400, 'JSON data was malformed!')
|
376
|
+
return build_response(400, 'JSON data was malformed!')
|
372
377
|
end
|
373
378
|
|
374
|
-
token = data[
|
379
|
+
token = data['token'] if data['token']
|
375
380
|
|
376
|
-
|
377
|
-
puts "#{Reedb::Config::Master::dump_config}\n"
|
378
|
-
|
379
|
-
unless token
|
380
|
-
return build_response(400, 'Required data fields are missing from JSON data body!')
|
381
|
-
end
|
381
|
+
return build_response(400, 'Required data fields are missing from JSON data body!') if token == nil
|
382
382
|
|
383
383
|
file = nil
|
384
384
|
begin
|
385
|
-
file = Reedb::Vault::access_file(vault_uuid,
|
385
|
+
file = Reedb::Vault::access_file(vault_uuid, token, file_id, false)
|
386
386
|
rescue FileNotFoundError => e
|
387
387
|
return build_response(404, e.message)
|
388
388
|
|
@@ -396,7 +396,7 @@ class ReedbHandler < Sinatra::Base
|
|
396
396
|
return build_response(403, e.message)
|
397
397
|
|
398
398
|
end
|
399
|
-
return build_response(200,
|
399
|
+
return build_response(200, 'File read without version history', file)
|
400
400
|
end
|
401
401
|
|
402
402
|
# [AUTH] Return history of a file
|
@@ -404,7 +404,7 @@ class ReedbHandler < Sinatra::Base
|
|
404
404
|
vault_uuid = params[:splat][0]
|
405
405
|
file_id = params[:splat][1]
|
406
406
|
|
407
|
-
unless vault_uuid
|
407
|
+
unless vault_uuid
|
408
408
|
return build_response(400, 'Missing vault access id.')
|
409
409
|
end
|
410
410
|
|
@@ -418,21 +418,18 @@ class ReedbHandler < Sinatra::Base
|
|
418
418
|
begin
|
419
419
|
data = JSON.parse(request.body.read)
|
420
420
|
rescue
|
421
|
-
return build_response(400, 'JSON data was malformed!')
|
421
|
+
return build_response(400, 'JSON data was malformed!')
|
422
422
|
end
|
423
423
|
|
424
|
-
token = data[
|
425
|
-
|
426
|
-
puts "#{token}\n"
|
427
|
-
puts "#{Reedb::Config::Master::dump_config}\n"
|
424
|
+
token = data['token'] if data['token']
|
428
425
|
|
429
426
|
unless token
|
430
|
-
return build_response(400, 'Required data fields are missing from JSON data body!')
|
427
|
+
return build_response(400, 'Required data fields are missing from JSON data body!')
|
431
428
|
end
|
432
429
|
|
433
430
|
file = nil
|
434
431
|
begin
|
435
|
-
file = Reedb::Vault::access_file(vault_uuid,
|
432
|
+
file = Reedb::Vault::access_file(vault_uuid, token, file_id, true)
|
436
433
|
rescue FileNotFoundError => e
|
437
434
|
return build_response(404, e.message)
|
438
435
|
|
@@ -453,7 +450,7 @@ class ReedbHandler < Sinatra::Base
|
|
453
450
|
put '/vaults/*/files' do
|
454
451
|
vault_uuid = params[:splat][0]
|
455
452
|
|
456
|
-
unless vault_uuid
|
453
|
+
unless vault_uuid
|
457
454
|
return build_response(400, 'Missing vault access id.')
|
458
455
|
end
|
459
456
|
|
@@ -467,39 +464,39 @@ class ReedbHandler < Sinatra::Base
|
|
467
464
|
begin
|
468
465
|
data = JSON.parse(request.body.read)
|
469
466
|
rescue
|
470
|
-
return build_response(400, 'JSON data was malformed!')
|
467
|
+
return build_response(400, 'JSON data was malformed!')
|
471
468
|
end
|
472
469
|
|
473
|
-
token = data[
|
474
|
-
name = data[
|
475
|
-
file_data = data[
|
470
|
+
token = data['token'] if data['token']
|
471
|
+
name = data['name'] if data['name']
|
472
|
+
file_data = data['data'] if data['data']
|
476
473
|
|
477
|
-
|
478
|
-
return build_response(400, 'Required data fields are missing from JSON data body!')
|
474
|
+
if token == nil || name == nil || file_data == nil
|
475
|
+
return build_response(400, 'Required data fields are missing from JSON data body!')
|
479
476
|
end
|
480
477
|
|
481
478
|
headers = Reedb::Vault::access_headers(vault_uuid, token, nil)
|
482
|
-
|
483
|
-
return build_response(400, "File already exists. Use update POST instead.")
|
484
|
-
end
|
479
|
+
return build_response(400, 'File already exists. Use update POST instead.') if headers.include?(name)
|
485
480
|
|
486
|
-
response = nil
|
487
481
|
begin
|
488
|
-
|
482
|
+
Reedb::Vault::insert(vault_uuid, token, name, file_data)
|
489
483
|
rescue VaultNotAvailableError => e
|
490
484
|
return build_response(404, e.message)
|
491
|
-
|
485
|
+
|
492
486
|
rescue UnknownTokenError => e
|
493
487
|
return build_response(401, e.message)
|
494
|
-
|
488
|
+
|
495
489
|
rescue UnautherisedTokenError => e
|
496
490
|
return build_response(403, e.message)
|
497
|
-
|
491
|
+
|
498
492
|
rescue FileBusyError => e
|
499
493
|
return build_response(418, "Dont take this error code too seriously: #{e.message}")
|
500
494
|
end
|
501
495
|
|
502
|
-
|
496
|
+
headers = Reedb::Vault::access_headers(vault_uuid, token, nil)
|
497
|
+
|
498
|
+
# Adds the file name as a handle to the payload so that it can be referenced in a future request
|
499
|
+
return build_response(200, 'File successfully created!', { 'file_handle' => headers[name]['name'] })
|
503
500
|
end
|
504
501
|
|
505
502
|
# [AUTH] Update file contents
|
@@ -507,7 +504,7 @@ class ReedbHandler < Sinatra::Base
|
|
507
504
|
vault_uuid = params[:splat][0]
|
508
505
|
file_name = params[:splat][1]
|
509
506
|
|
510
|
-
unless vault_uuid
|
507
|
+
unless vault_uuid
|
511
508
|
return build_response(400, 'Missing vault access id.')
|
512
509
|
end
|
513
510
|
|
@@ -521,14 +518,14 @@ class ReedbHandler < Sinatra::Base
|
|
521
518
|
begin
|
522
519
|
data = JSON.parse(request.body.read)
|
523
520
|
rescue
|
524
|
-
return build_response(400, 'JSON data was malformed!')
|
521
|
+
return build_response(400, 'JSON data was malformed!')
|
525
522
|
end
|
526
523
|
|
527
|
-
token = data[
|
528
|
-
file_data = data[
|
524
|
+
token = data['token'] if data['token']
|
525
|
+
file_data = data['data'] if data['data']
|
529
526
|
|
530
|
-
|
531
|
-
return build_response(400, 'Required data fields are missing from JSON data body!')
|
527
|
+
if token == nil || file_data == nil
|
528
|
+
return build_response(400, 'Required data fields are missing from JSON data body!')
|
532
529
|
end
|
533
530
|
|
534
531
|
begin
|
@@ -536,18 +533,18 @@ class ReedbHandler < Sinatra::Base
|
|
536
533
|
|
537
534
|
rescue VaultNotAvailableError => e
|
538
535
|
return build_response(404, e.message)
|
539
|
-
|
536
|
+
|
540
537
|
rescue UnknownTokenError => e
|
541
538
|
return build_response(401, e.message)
|
542
|
-
|
539
|
+
|
543
540
|
rescue UnautherisedTokenError => e
|
544
541
|
return build_response(403, e.message)
|
545
|
-
|
542
|
+
|
546
543
|
rescue FileBusyError => e
|
547
544
|
return build_response(418, "Dont take this error code too seriously: #{e.message}")
|
548
545
|
end
|
549
546
|
|
550
|
-
return build_response(200,
|
547
|
+
return build_response(200, 'File successfully updated!')
|
551
548
|
end
|
552
549
|
|
553
550
|
# [AUTH] Removes a file
|
@@ -555,7 +552,7 @@ class ReedbHandler < Sinatra::Base
|
|
555
552
|
vault_uuid = params[:splat][0]
|
556
553
|
file_name = params[:splat][1]
|
557
554
|
|
558
|
-
unless vault_uuid
|
555
|
+
unless vault_uuid
|
559
556
|
return build_response(400, 'Missing vault access id.')
|
560
557
|
end
|
561
558
|
|
@@ -569,14 +566,14 @@ class ReedbHandler < Sinatra::Base
|
|
569
566
|
begin
|
570
567
|
data = JSON.parse(request.body.read)
|
571
568
|
rescue
|
572
|
-
return build_response(400, 'JSON data was malformed!')
|
569
|
+
return build_response(400, 'JSON data was malformed!')
|
573
570
|
end
|
574
571
|
|
575
|
-
token = data[
|
572
|
+
token = data['token'] if data['token']
|
576
573
|
|
577
574
|
begin
|
578
575
|
Reedb::Vault::remove(vault_uuid, token, file_name)
|
579
|
-
|
576
|
+
|
580
577
|
rescue FileNotFoundError, VaultNotAvailableError => e
|
581
578
|
return build_response(404, e.message)
|
582
579
|
|
@@ -587,31 +584,51 @@ class ReedbHandler < Sinatra::Base
|
|
587
584
|
return build_response(403, e.message)
|
588
585
|
end
|
589
586
|
|
590
|
-
return build_response(200,
|
587
|
+
return build_response(200, 'File successfully deleted.')
|
591
588
|
end
|
592
589
|
end
|
593
590
|
|
594
|
-
options = {}
|
591
|
+
@options = {}
|
595
592
|
|
596
593
|
# Setting default options
|
597
|
-
options[:pw_length] = 12
|
598
|
-
options[:verbose] = false
|
599
|
-
options[:daemon] = true
|
600
|
-
options[:port] = Reedb::NET_PORT
|
601
|
-
options[:os] = Reedb::Utilities::parse_os
|
602
|
-
options[:path] = Reedb::
|
603
|
-
|
604
|
-
|
594
|
+
@options[:pw_length] = 12
|
595
|
+
@options[:verbose] = false
|
596
|
+
@options[:daemon] = true
|
597
|
+
@options[:port] = Reedb::NET_PORT
|
598
|
+
@options[:os] = Reedb::Utilities::parse_os
|
599
|
+
@options[:path] = Reedb::DEFAULT_PATH
|
600
|
+
@options[:dave] = false
|
601
|
+
@options[:force] = false
|
602
|
+
|
603
|
+
# Create argument parsers and handle them
|
605
604
|
opts = OptionParser.new
|
606
|
-
opts.on('-l', '--pw-length INTEGER') { |o| options[:pw_length] = o }
|
607
|
-
opts.on('-p', '--port INTEGER') { |o| options[:port] = o }
|
608
|
-
opts.on('-v', '--verbose') { options[:verbose] = true }
|
609
|
-
opts.on('-
|
610
|
-
opts.on('
|
605
|
+
opts.on('-l', '--pw-length INTEGER') { |o| @options[:pw_length] = o }
|
606
|
+
opts.on('-p', '--port INTEGER') { |o| @options[:port] = o }
|
607
|
+
opts.on('-v', '--verbose') { @options[:verbose] = true }
|
608
|
+
opts.on('-f', '--force') { @options[:force] = true }
|
609
|
+
opts.on('--dave') { @options[:dave] = true }
|
610
|
+
opts.on('-d', '--no-daemon') { @options[:daemon] = false }
|
611
|
+
opts.on('-a', '--app-path STRING') { |o| @options[:path] = o }
|
611
612
|
opts.parse! unless ARGV == []
|
612
613
|
|
613
|
-
#
|
614
|
-
Reedb::Core::
|
615
|
-
|
614
|
+
# Define what to do when that evil SIGTERM comes
|
615
|
+
at_exit { Reedb::Core::terminate('root', true) }
|
616
|
+
|
616
617
|
# Next up we start the HTTP server and that's that. We're up and running :)
|
617
|
-
|
618
|
+
def http_server
|
619
|
+
Rack::Handler::WEBrick.run(ReedbHandler.new, { :Port => @options[:port], :BindAddress => 'localhost' })
|
620
|
+
end
|
621
|
+
|
622
|
+
# This creates the Reedb module and binds it to a variable to be interacted with in the future
|
623
|
+
# Gives more information to the core classes than they need
|
624
|
+
|
625
|
+
begin
|
626
|
+
Reedb::Core::init(@options) { http_server }
|
627
|
+
rescue Interrupt => e
|
628
|
+
puts e.message
|
629
|
+
puts 'User interrupt fired! Abandon ship...abandon ship!\n'
|
630
|
+
puts 'Waiting for background threads to die...'
|
631
|
+
Reedb::Core::terminate('user', true)
|
632
|
+
puts "Exit code #{Reedb::EXIT_PANIC_INTERUPT}"
|
633
|
+
exit(Reedb::EXIT_PANIC_INTERUPT)
|
634
|
+
end
|