ruby-libstorj 1.0.2 → 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/.gitignore +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +17 -121
- data/Rakefile +7 -5
- data/dockerfiles/example.dockerfile +3 -3
- data/dockerfiles/setup-user/activate_user.js +34 -0
- data/dockerfiles/setup-user/create_user.sh +31 -0
- data/dockerfiles/setup-user/import_keys.sh +31 -0
- data/dockerfiles/setup-user/package.json +14 -0
- data/dockerfiles/setup-user/setup_user.sh +26 -0
- data/dockerfiles/test.rb +9 -0
- data/lib/ruby-libstorj/env.rb +11 -2
- data/lib/ruby-libstorj/libstorj.rb +3 -1
- data/lib/ruby-libstorj/mixins/storj.rb +58 -0
- data/{spec/helpers/options.example.yml → options.example.yml} +0 -0
- data/ruby-libstorj.gemspec +1 -1
- data/spec/helpers/storj_options.rb +0 -46
- data/spec/ruby-libstorj/env_spec.rb +3 -2
- 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: d6fe0bf8d40e520d210d6dce512a1c767b4eb3df
|
4
|
+
data.tar.gz: 7409289788a7ccb6915364c29a2593901597a76c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e69068e9392da1589dc68a710b7a6841bc07aea6b7d13006a7da4c015cedd7c665fbafbde2a27ac39ed3c1a274e50f1028038d6a8fafa746f76b36753d5dbdfa
|
7
|
+
data.tar.gz: 13fec483fc292a4aa73c28aa4e20d6982dcfcaa06bb4e35ac8febc70f26646be9beb11c6692eb546ba411b6833c86402b014141bd00ca90da7890bcbe0c50bb4
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -28,7 +28,7 @@ Ruby library for encrypted file transfer on the Storj network via bindings to [l
|
|
28
28
|
cd ruby-libstorj && \
|
29
29
|
rake install
|
30
30
|
```
|
31
|
-
(see [installing for development](#
|
31
|
+
(see [installing for development](#install-gem-1) if you have issues with `rake install`)
|
32
32
|
|
33
33
|
### Usage:
|
34
34
|
Until more thorough documentation is available, please see the tests:
|
@@ -39,6 +39,7 @@ Until more thorough documentation is available, please see the tests:
|
|
39
39
|
- `.mnemonic_check`
|
40
40
|
- `.mnemonic_generate`
|
41
41
|
+ [`LibStorj::Env`](./spec/ruby-libstorj/env_spec.rb) _[(source)](./lib/ruby-libstorj/env.rb)_
|
42
|
+
- `.new`
|
42
43
|
- `#get_info`
|
43
44
|
- `#get_buckets`
|
44
45
|
- `#create_bucket`
|
@@ -79,17 +80,15 @@ rake compile
|
|
79
80
|
```
|
80
81
|
(see [`rake-compiler`](https://github.com/rake-compiler/rake-compiler))
|
81
82
|
|
82
|
-
### Build gem:
|
83
|
-
```bash
|
84
|
-
rake
|
85
|
-
|
86
|
-
# OR
|
87
|
-
# rake build
|
88
|
-
# rake build[no-test] # build without requiring tests to pass
|
89
|
-
```
|
90
|
-
|
91
|
-
### Install gem:
|
83
|
+
### Build and install gem:
|
92
84
|
+ with `rake`:
|
85
|
+
```bash
|
86
|
+
rake
|
87
|
+
|
88
|
+
# OR
|
89
|
+
# rake build
|
90
|
+
# rake build[no-test] # build without requiring tests to pass
|
91
|
+
```
|
93
92
|
```bash
|
94
93
|
rake install
|
95
94
|
|
@@ -99,22 +98,25 @@ rake
|
|
99
98
|
|
100
99
|
+ with `gem`:
|
101
100
|
|
102
|
-
Maybe you need/want to pass args to `gem`, or maybe `rake install` doesn't work
|
101
|
+
Maybe you need/want to pass args to `gem`, or maybe `rake install` doesn't work in your environment:
|
103
102
|
|
104
103
|
```bash
|
105
|
-
gem
|
104
|
+
gem build ./ruby-libstorj.gemspec
|
105
|
+
```
|
106
|
+
```bash
|
107
|
+
gem install --local ./ruby-libstorj-<version>.gem --no-ri --no-rdoc
|
106
108
|
```
|
107
109
|
|
108
110
|
### Testing:
|
109
111
|
#### First create spec/helpers/options.yml !
|
110
112
|
For the moment, the test suite doesn't start it's own mock backend but it does parse whatever's in the `spec/helpsers/options.yml` file to initialize `LibStorj::Ext::Storj::Env` to connect via http/https.
|
111
113
|
|
112
|
-
You can copy [`spec/helpers/options.yml.example`](
|
114
|
+
You can copy [`spec/helpers/options.yml.example`](options.example.yml) and modify it for your use:
|
113
115
|
```bash
|
114
116
|
cp spec/helpers/options.yml.example spec/helpers/options.yml && \
|
115
117
|
vim spec/helpers/options.yml # or whatever
|
116
118
|
```
|
117
|
-
`spec/helpers/options.yml`
|
119
|
+
Ensure that `spec/helpers/options.yml` is in the [`.gitignore`](./.gitignore) so you don't have to worry about accidentally committing it.
|
118
120
|
|
119
121
|
#### A quick note on rspec formatters:
|
120
122
|
The "progress" formatter is the default.
|
@@ -187,109 +189,3 @@ For example usages see "with `rake`" below.
|
|
187
189
|
# rspec spec/ruby-libstorj/env_spec.rb:15 # run test(s) containing line 15
|
188
190
|
```
|
189
191
|
(see `rspec --help | less`)
|
190
|
-
|
191
|
-
### Gotchas:
|
192
|
-
+ `libuv` (see http://docs.libuv.org/en/v1.x/)
|
193
|
-
|
194
|
-
#### The problem
|
195
|
-
The C library [`libuv`](http://docs.libuv.org/en/v1.x/) is used by [`libstorj`](https://github.com/storj/libstorj) for concurrency;
|
196
|
-
however, ruby's C API is not thread-safe so this is currently resolved by using the ruby gem [`libuv`](https://rubygems.org/gems/libuv) in tandem with the C-`libuv` calls in `libstorj`
|
197
|
-
|
198
|
-
Specifically, `libstorj` makes calls to the C-`libuv` function [`uv_queue_work`](http://docs.libuv.org/en/v1.x/threadpool.html), which queues work to be run in another thread.
|
199
|
-
In standard C-`libuv` usage, you would call [`uv_run(...)`](http://docs.libuv.org/en/v1.x/loop.html#c.uv_run):
|
200
|
-
|
201
|
-
```c
|
202
|
-
#include <uv.h>
|
203
|
-
...
|
204
|
-
// Queue work to be run in another thread
|
205
|
-
uv_queue_work(...);
|
206
|
-
...
|
207
|
-
// Run the event loop
|
208
|
-
uv_run(...);
|
209
|
-
```
|
210
|
-
|
211
|
-
After calling a function which queues work using the C `uv_queue_work` function, simply calling `uv_run` from ruby does **not work**:
|
212
|
-
```c
|
213
|
-
/* example.c */
|
214
|
-
#include <uv.h>
|
215
|
-
...
|
216
|
-
// implemented elsewhere
|
217
|
-
uv_work_t* my_work_factory(void* handle);
|
218
|
-
...
|
219
|
-
handle_wrapper
|
220
|
-
...
|
221
|
-
extern "C"
|
222
|
-
int example_queue_work(void* handle, uv_after_work_cb cb)
|
223
|
-
{
|
224
|
-
uv_loop_t* loop = uv_default_loop();
|
225
|
-
uv_work_t *work = my_work_factory(handle);
|
226
|
-
|
227
|
-
return uv_queue_work(loop, work, my_worker, cb);
|
228
|
-
}
|
229
|
-
```
|
230
|
-
|
231
|
-
```ruby
|
232
|
-
# example.rb
|
233
|
-
# NOTE: THIS IS AN EXAMPLE OF WHAT DOES NOT WORK
|
234
|
-
####################################### === ####
|
235
|
-
require 'ffi'
|
236
|
-
|
237
|
-
module Example
|
238
|
-
extend FFI::Library
|
239
|
-
# load built shared object from C/C++ using ruby ffi
|
240
|
-
ffi_lib '/path/to/libexample.so'
|
241
|
-
|
242
|
-
# NB: if `libexample` is installed in the usual system location*
|
243
|
-
# ffi_lib 'example'
|
244
|
-
|
245
|
-
# expose C functions as members of the `Example` module
|
246
|
-
attach_function('queue_work', 'example_queue_work', [:pointer, :int], :int)
|
247
|
-
attach_function('run', 'uv_run', [:pointer, :int], :int)
|
248
|
-
end
|
249
|
-
|
250
|
-
handle = FFI::Function.new(...) {...}
|
251
|
-
cb = FFI::Function.new(...) {...}
|
252
|
-
|
253
|
-
Example.queue_work handle, cb
|
254
|
-
Example.run #=> segmentation fault
|
255
|
-
```
|
256
|
-
_*`ffi_lib` automatically adds the conventional "lib" prefix to args which are not absolute paths_
|
257
|
-
|
258
|
-
|
259
|
-
It seems to be the case that calls to `uv_default_loop()` made from within C-libstorj point to a different location than the default loop from ruby-livub.
|
260
|
-
It may be the case that C-libuv is being loaded twice, one linked through C-libstorj and the other through ruby-libuv bindings or something; more digging required.
|
261
|
-
|
262
|
-
#### The solution
|
263
|
-
Instead of calling `uv_run` directly, if we let the ruby `libuv` gem do it for us, we can call `uv_queue_work` in C as much as we want.
|
264
|
-
|
265
|
-
Using ruby-`libuv`'s `reactor` block to wrap calls to C functions that call `uv_queue_work`, we let ruby-`libuv` do the heavy concurrency lifting and C-`libuv` integration:
|
266
|
-
|
267
|
-
```ruby
|
268
|
-
# example.rb
|
269
|
-
require 'libuv'
|
270
|
-
require 'ffi'
|
271
|
-
|
272
|
-
module Example
|
273
|
-
extend FFI::Library
|
274
|
-
# load built shared object from C/C++ using ruby ffi
|
275
|
-
ffi_lib '/path/to/libexample.so'
|
276
|
-
|
277
|
-
# NB: if `libexample` is installed in the usual system location*
|
278
|
-
# ffi_lib 'example'
|
279
|
-
|
280
|
-
# expose C functions as members of the `Example` module
|
281
|
-
attach_function('queue_work', 'example_queue_work', [:pointer, :int], :int)
|
282
|
-
end
|
283
|
-
|
284
|
-
handle = FFI::Function.new(...) {...}
|
285
|
-
cb = FFI::Function.new(...) {...}
|
286
|
-
|
287
|
-
reactor do |reactor|
|
288
|
-
reactor.work do
|
289
|
-
Example.queue_work handle, cb
|
290
|
-
end
|
291
|
-
end
|
292
|
-
```
|
293
|
-
(see https://github.com/cotag/libuv)
|
294
|
-
|
295
|
-
_NB: the understanding presented here comes from reading the docs and source of the various C and ruby libraries involved_
|
data/Rakefile
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
# i.e. `require 'ruby-libstorj/...'`
|
3
3
|
require_relative './lib/ruby-libstorj/arg_forwarding_task'
|
4
4
|
|
5
|
+
TEMP_PATH = File.join(%W(#{__dir__} tmp))
|
6
|
+
|
5
7
|
# NB: using begin/rescue so that you can use your
|
6
8
|
# Rakefile in an environment where RSpec is
|
7
9
|
# unavailable (e.g. production)
|
@@ -52,14 +54,12 @@ Rake::ExtensionTask.new 'ruby-libstorj'
|
|
52
54
|
|
53
55
|
# TODO: everything that follows... but better
|
54
56
|
LibStorj::ArgForwardingTask.new(:build, args_deps_hash: {
|
55
|
-
%i[no-test] => []
|
57
|
+
%i[no-test] => [TEMP_PATH.to_sym]
|
56
58
|
}) do |t, args, deps|
|
57
59
|
Rake::Task[:spec].invoke if args.to_hash[:'no-test'].nil?
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
-
sh 'gem build ./ruby-libstorj.gemspec'
|
62
|
-
sh 'mv ./ruby-libstorj-*.gem ./tmp/'
|
61
|
+
sh 'gem build ruby-libstorj.gemspec'
|
62
|
+
sh "mv ruby-libstorj-*.gem #{TEMP_PATH}#{File::SEPARATOR}"
|
63
63
|
end
|
64
64
|
|
65
65
|
LibStorj::ArgForwardingTask.new(:install, args_deps_hash: {
|
@@ -72,5 +72,7 @@ LibStorj::ArgForwardingTask.new(:install, args_deps_hash: {
|
|
72
72
|
--no-rdoc'
|
73
73
|
end
|
74
74
|
|
75
|
+
directory TEMP_PATH
|
76
|
+
|
75
77
|
# Build (and test) when you run `rake`
|
76
78
|
task default: %i[build]
|
@@ -21,6 +21,6 @@ RUN make install
|
|
21
21
|
RUN gem install ruby-libstorj
|
22
22
|
|
23
23
|
WORKDIR /storj
|
24
|
-
COPY ./
|
25
|
-
COPY ./
|
26
|
-
CMD /bin/bash
|
24
|
+
COPY ./dockerfiles/test.rb ./test.rb
|
25
|
+
COPY ./options.example.yml ./options.yml
|
26
|
+
CMD bash -c 'echo "### Edit ./options.yml & edit/run ruby ./test.rb ###" && /bin/bash'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
const MongoClient = require('mongodb').MongoClient;
|
4
|
+
const assert = require('assert');
|
5
|
+
|
6
|
+
// Connection URL
|
7
|
+
const url = 'mongodb://localhost:27017';
|
8
|
+
|
9
|
+
// Database Name
|
10
|
+
const dbName = 'storj-sandbox';
|
11
|
+
|
12
|
+
// Use connect method to connect to the server
|
13
|
+
MongoClient.connect(url, function(err, client) {
|
14
|
+
assert.equal(null, err);
|
15
|
+
console.log("Successfully connected to mongo...");
|
16
|
+
|
17
|
+
const db = client.db(dbName);
|
18
|
+
|
19
|
+
// find and update all users to be activated
|
20
|
+
db.collection('users').updateMany({activated: false}, {$set:
|
21
|
+
{
|
22
|
+
activated: true,
|
23
|
+
activator: null
|
24
|
+
}
|
25
|
+
}, function(err, result) {
|
26
|
+
if (err) {
|
27
|
+
return console.error(err);
|
28
|
+
}
|
29
|
+
|
30
|
+
console.log("...done!");
|
31
|
+
// console.log(result);
|
32
|
+
client.close();
|
33
|
+
});
|
34
|
+
});
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/expect
|
2
|
+
|
3
|
+
set email "$env(STORJ_EMAIL)\n"
|
4
|
+
set pass "$env(STORJ_PASS)\n"
|
5
|
+
set keypass "$env(STORJ_KEYPASS)\n"
|
6
|
+
set strength "128\n"
|
7
|
+
set timeout 3
|
8
|
+
|
9
|
+
spawn storj register
|
10
|
+
|
11
|
+
expect "Bridge username"
|
12
|
+
send $email
|
13
|
+
|
14
|
+
expect "Bridge password:"
|
15
|
+
send $pass
|
16
|
+
|
17
|
+
expect "Strength:"
|
18
|
+
send $strength
|
19
|
+
|
20
|
+
# expect "overwrite"
|
21
|
+
# send "y\n"
|
22
|
+
|
23
|
+
expect "Unlock passphrase:"
|
24
|
+
send $keypass
|
25
|
+
|
26
|
+
expect "Again to verify:"
|
27
|
+
send $keypass
|
28
|
+
|
29
|
+
expect "EOF"
|
30
|
+
|
31
|
+
exit
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/expect
|
2
|
+
|
3
|
+
set email "$env(STORJ_EMAIL)\n"
|
4
|
+
set pass "$env(STORJ_PASS)\n"
|
5
|
+
set keypass "$env(STORJ_KEYPASS)\n"
|
6
|
+
set mnemonic "$env(STORJ_MNEMONIC)\n"
|
7
|
+
set timeout 3
|
8
|
+
|
9
|
+
spawn storj import-keys
|
10
|
+
|
11
|
+
expect "Would you like to overwrite"
|
12
|
+
send "y\n"
|
13
|
+
|
14
|
+
expect "Bridge username"
|
15
|
+
send $email
|
16
|
+
|
17
|
+
expect "Bridge password:"
|
18
|
+
send $pass
|
19
|
+
|
20
|
+
expect "Encryption key:"
|
21
|
+
send $mnemonic
|
22
|
+
|
23
|
+
expect "Unlock passphrase:"
|
24
|
+
send $keypass
|
25
|
+
|
26
|
+
expect "Again to verify:"
|
27
|
+
send $keypass
|
28
|
+
|
29
|
+
expect "EOF"
|
30
|
+
|
31
|
+
exit
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"name": "setup-user",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "",
|
5
|
+
"main": "activate_user.js",
|
6
|
+
"scripts": {
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
8
|
+
},
|
9
|
+
"author": "",
|
10
|
+
"license": "ISC",
|
11
|
+
"dependencies": {
|
12
|
+
"mongodb": "^3.0.4"
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
. ~/.nvm/nvm.sh
|
3
|
+
|
4
|
+
root_dir="/root"
|
5
|
+
|
6
|
+
#redis
|
7
|
+
service redis-server start
|
8
|
+
|
9
|
+
#mongodb
|
10
|
+
service mongod start
|
11
|
+
|
12
|
+
#storjbridge
|
13
|
+
pm2 start -n bridge $root_dir/bin/storj-bridge -- -c $root_dir/config/storj-bridge/config.json -d $root_dir/config/storj-bridge
|
14
|
+
|
15
|
+
#wait for things to come up
|
16
|
+
echo "Sleeping for 5..."
|
17
|
+
sleep 5
|
18
|
+
|
19
|
+
./create_user.sh
|
20
|
+
./import_keys.sh
|
21
|
+
npm install
|
22
|
+
node ./activate_user.js
|
23
|
+
|
24
|
+
service redis-server stop
|
25
|
+
service mongod stop
|
26
|
+
pm2 delete all
|
data/dockerfiles/test.rb
ADDED
data/lib/ruby-libstorj/env.rb
CHANGED
@@ -6,8 +6,17 @@ module LibStorj
|
|
6
6
|
|
7
7
|
C_ANALOGUE = ::LibStorj::Ext::Storj::Env
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
9
|
+
def initialize(path:, **options)
|
10
|
+
# NB: ensure all options are pointers before passing them directly
|
11
|
+
options = {} unless options.all? {|_, o| o.is_a? ::FFI::Pointer}
|
12
|
+
|
13
|
+
if !path.nil? && File.exists?(path)
|
14
|
+
options = ::LibStorj.load_yaml_options(path).merge options
|
15
|
+
end
|
16
|
+
|
17
|
+
# puts options
|
18
|
+
@storj_env = ::LibStorj::Ext::Storj.method(:init_env).call(*options.values)
|
19
|
+
|
11
20
|
# use ruby libuv's default_loop
|
12
21
|
@storj_env[:loop] = ::Libuv::Ext.default_loop
|
13
22
|
end
|
@@ -15,8 +15,10 @@ module LibStorj
|
|
15
15
|
require 'ruby-libstorj/ext/upload_options'
|
16
16
|
require 'ruby-libstorj/ext/file'
|
17
17
|
|
18
|
-
require 'ruby-libstorj/env'
|
19
18
|
require 'ruby-libstorj/mixins/storj'
|
20
19
|
|
20
|
+
extend ::LibStorj::Storj::Mixins
|
21
21
|
extend ::LibStorj::Ext::Storj::Mixins
|
22
|
+
|
23
|
+
require 'ruby-libstorj/env'
|
22
24
|
end
|
@@ -1,4 +1,62 @@
|
|
1
1
|
module LibStorj
|
2
|
+
module Storj
|
3
|
+
module Mixins
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
def load_yaml_options(path)
|
7
|
+
throw(:ENOENT) unless File.exist?(path)
|
8
|
+
|
9
|
+
options_yml = YAML.load_file path
|
10
|
+
build_options(default_type_map, options_yml.to_hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_type_map
|
14
|
+
{
|
15
|
+
bridge: ::LibStorj::Ext::Storj::BridgeOptions,
|
16
|
+
encrypt: ::LibStorj::Ext::Storj::EncryptOptions,
|
17
|
+
http: ::LibStorj::Ext::Storj::HttpOptions,
|
18
|
+
log: ::LibStorj::Ext::Storj::LogOptions
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def build_options(type_map, option_groups)
|
23
|
+
Hash[option_groups.map do |group_name, options|
|
24
|
+
|
25
|
+
option_type = type_map[group_name.to_sym]
|
26
|
+
member_field_hash = Hash[option_type.members.zip option_type.layout.fields]
|
27
|
+
option_instance = option_type.new
|
28
|
+
|
29
|
+
options.map do |name, value|
|
30
|
+
name = name.to_sym
|
31
|
+
|
32
|
+
if name == :logger
|
33
|
+
option_instance[:logger] = ::LibStorj::Ext::Storj.const_get value
|
34
|
+
|
35
|
+
next
|
36
|
+
end
|
37
|
+
|
38
|
+
option_field = member_field_hash[name]
|
39
|
+
|
40
|
+
# TODO: check types and/or error handle
|
41
|
+
if option_field.nil?
|
42
|
+
option_instance = FFI::MemoryPointer::NULL
|
43
|
+
elsif option_field.is_a?(FFI::StructLayout::Pointer)
|
44
|
+
# Assuming pointers are strings
|
45
|
+
#
|
46
|
+
pointer = FFI::MemoryPointer.from_string(value.nil? ? '' : value)
|
47
|
+
option_instance[name] = pointer
|
48
|
+
else
|
49
|
+
option_instance[name] = value
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
[group_name, option_instance]
|
55
|
+
end]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
2
60
|
module Ext
|
3
61
|
module Storj
|
4
62
|
module Mixins
|
File without changes
|
data/ruby-libstorj.gemspec
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = 'ruby-libstorj'
|
7
|
-
gem.version = '
|
7
|
+
gem.version = '2.0.0' #LibStorj::VERSION
|
8
8
|
gem.license = 'AGPL-3.0'
|
9
9
|
gem.authors = ['Bryan White']
|
10
10
|
gem.email = ['bryanchriswhite@gmail.com', 'bryan@storj.io']
|
@@ -1,52 +1,6 @@
|
|
1
1
|
module LibStorjTest
|
2
|
-
require 'yaml'
|
3
2
|
require 'ruby-libstorj'
|
4
3
|
|
5
|
-
def build_options(type_map)
|
6
|
-
options_yml = YAML.load_file "#{__dir__}/options.yml"
|
7
|
-
options_yml.to_a.map do |option_group|
|
8
|
-
group_name, options = option_group
|
9
|
-
|
10
|
-
option_type = type_map[group_name.to_sym]
|
11
|
-
member_field_hash = Hash[option_type.members.zip option_type.layout.fields]
|
12
|
-
option_instance = option_type.new
|
13
|
-
|
14
|
-
options.each do |option|
|
15
|
-
name, value = [option[0].to_sym, option[1]]
|
16
|
-
|
17
|
-
if name == :logger
|
18
|
-
option_instance[:logger] = ::LibStorj::Ext::Storj.const_get value
|
19
|
-
|
20
|
-
next
|
21
|
-
end
|
22
|
-
|
23
|
-
option_field = member_field_hash[name]
|
24
|
-
|
25
|
-
# TODO: check types and/or error handle
|
26
|
-
if option_field.nil?
|
27
|
-
option_instance = FFI::MemoryPointer::NULL
|
28
|
-
elsif option_field.is_a?(FFI::StructLayout::Pointer)
|
29
|
-
# Assuming pointers are strings
|
30
|
-
#
|
31
|
-
pointer = FFI::MemoryPointer.from_string(value.nil? ? '' : value)
|
32
|
-
option_instance[name] = pointer
|
33
|
-
else
|
34
|
-
option_instance[name] = value
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
option_instance
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def default_options
|
44
|
-
build_options bridge: ::LibStorj::Ext::Storj::BridgeOptions,
|
45
|
-
encrypt: ::LibStorj::Ext::Storj::EncryptOptions,
|
46
|
-
http: ::LibStorj::Ext::Storj::HttpOptions,
|
47
|
-
log: ::LibStorj::Ext::Storj::LogOptions
|
48
|
-
end
|
49
|
-
|
50
4
|
def get_test_bucket_id(&block)
|
51
5
|
instance.get_buckets do |error, buckets|
|
52
6
|
throw(:no_bucket) if buckets.nil?
|
@@ -5,8 +5,9 @@ include LibStorjTest
|
|
5
5
|
RSpec.describe LibStorj::Env do
|
6
6
|
let(:bucket_class) {::LibStorj::Ext::Storj::Bucket}
|
7
7
|
let(:file_class) {::LibStorj::Ext::Storj::File}
|
8
|
+
let(:default_path) {File.join %W(#{__dir__} .. .. options.yml)}
|
8
9
|
let(:instance) do
|
9
|
-
described_class.new(
|
10
|
+
described_class.new(path: default_path)
|
10
11
|
end
|
11
12
|
|
12
13
|
after :each do
|
@@ -69,7 +70,7 @@ RSpec.describe LibStorj::Env do
|
|
69
70
|
end
|
70
71
|
|
71
72
|
it 'yields a nil error and an array of buckets' do
|
72
|
-
expect do |block|
|
73
|
+
expect do |block|
|
73
74
|
instance.get_buckets do |error, buckets|
|
74
75
|
expect(error).to be(nil)
|
75
76
|
expect(buckets.length).to be(bucket_names.length)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-libstorj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan White
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -86,6 +86,12 @@ files:
|
|
86
86
|
- Rakefile
|
87
87
|
- dockerfiles/example.dockerfile
|
88
88
|
- dockerfiles/ruby-libstorj.dockerfile
|
89
|
+
- dockerfiles/setup-user/activate_user.js
|
90
|
+
- dockerfiles/setup-user/create_user.sh
|
91
|
+
- dockerfiles/setup-user/import_keys.sh
|
92
|
+
- dockerfiles/setup-user/package.json
|
93
|
+
- dockerfiles/setup-user/setup_user.sh
|
94
|
+
- dockerfiles/test.rb
|
89
95
|
- ext/libstorj/.gitignore
|
90
96
|
- ext/libstorj/.travis.yml
|
91
97
|
- ext/libstorj/CONTRIBUTING.md
|
@@ -157,8 +163,8 @@ files:
|
|
157
163
|
- lib/ruby-libstorj/libstorj.rb
|
158
164
|
- lib/ruby-libstorj/mixins/storj.rb
|
159
165
|
- lib/ruby-libstorj/struct.rb
|
166
|
+
- options.example.yml
|
160
167
|
- ruby-libstorj.gemspec
|
161
|
-
- spec/helpers/options.example.yml
|
162
168
|
- spec/helpers/shared_rake_examples.rb
|
163
169
|
- spec/helpers/storj_options.rb
|
164
170
|
- spec/helpers/upload.data
|