cleversafe 1.0.7 → 1.0.8
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/Gemfile +2 -0
- data/Gemfile.lock +18 -0
- data/README.md +56 -0
- data/Rakefile +4 -0
- data/cleversafe-1.0.7.gem +0 -0
- data/cleversafe.gemspec +11 -0
- data/lib/cleversafe/connection.rb +21 -29
- data/lib/cleversafe/errors.rb +1 -1
- data/lib/cleversafe/object.rb +19 -18
- data/lib/cleversafe/vault.rb +5 -7
- data/lib/cleversafe.rb +6 -9
- metadata +18 -10
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cleversafe (1.0.7)
|
5
|
+
rest-client (~> 1.6.7)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
mime-types (1.22)
|
11
|
+
rest-client (1.6.7)
|
12
|
+
mime-types (>= 1.16)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
cleversafe!
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Cleversafe SOH
|
2
|
+
|
3
|
+
## Description
|
4
|
+
This is a Ruby interface into the Cleversafe's SOH API.
|
5
|
+
|
6
|
+
## Notes
|
7
|
+
* Multipart uploads are not supported by Cleversafe's API. Coming soon.
|
8
|
+
* If you upload a file with "X-Digest" you will get back a hash that includes :id and :x_content_digest.
|
9
|
+
|
10
|
+
## Todo
|
11
|
+
* Support range requests for getting an object
|
12
|
+
|
13
|
+
## Examples
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
#Setup Conection
|
17
|
+
request = Cleversafe::Connection.new("USERNAME", "PASSWORD", "HOSTNAME")
|
18
|
+
|
19
|
+
#Does a vault exist?
|
20
|
+
request.vault_exists?("VAULTNAME")
|
21
|
+
|
22
|
+
# load vault
|
23
|
+
vault = request.vault("VAULTNAME")
|
24
|
+
|
25
|
+
# bytes used in vault
|
26
|
+
vault.bytes_used
|
27
|
+
|
28
|
+
# list objects in vault
|
29
|
+
vault.objects(:limit => 10, :start_id => "1f1665dce23b515cedf29edaf1d033730000")
|
30
|
+
|
31
|
+
# load object
|
32
|
+
object = "1f1665dce23b515cedf29edaf1d033730000"
|
33
|
+
|
34
|
+
# get etag of object
|
35
|
+
vault.object(object).etag
|
36
|
+
|
37
|
+
# download object
|
38
|
+
File.open("downloaded.file", 'w') {|f| f.write(vault.object(object).data) }
|
39
|
+
|
40
|
+
# upload object, don't use multipart, it is not supported
|
41
|
+
uploaded_object = vault.create_object File.new("upload.file", "r"), :multipart => false, 'X-Digest' => "md5"
|
42
|
+
|
43
|
+
# uploaded object's digest
|
44
|
+
uploaded_object[:id]
|
45
|
+
|
46
|
+
# object's digest
|
47
|
+
uploaded_object[:x_content_digest]
|
48
|
+
|
49
|
+
# uploaded object exists?
|
50
|
+
vault.object_exists?(uploaded_object[:id])
|
51
|
+
|
52
|
+
# deleting the uploaded object
|
53
|
+
vault.delete_object(uploaded_object[:id])
|
54
|
+
|
55
|
+
```
|
56
|
+
|
data/Rakefile
ADDED
Binary file
|
data/cleversafe.gemspec
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "cleversafe"
|
3
|
+
s.summary = "A Ruby API into Cleversafe's REST interface."
|
4
|
+
s.author = "John Williams"
|
5
|
+
s.email = "john@37signals.com"
|
6
|
+
s.version = "1.0.8"
|
7
|
+
|
8
|
+
s.add_dependency 'rest-client', '~> 1.6.7'
|
9
|
+
|
10
|
+
s.files = Dir["#{File.dirname(__FILE__)}/**/*"]
|
11
|
+
end
|
@@ -1,11 +1,6 @@
|
|
1
1
|
module Cleversafe
|
2
2
|
class Connection
|
3
|
-
attr_reader
|
4
|
-
attr_accessor :password
|
5
|
-
attr_accessor :host
|
6
|
-
attr_accessor :protocol
|
7
|
-
attr_accessor :vault
|
8
|
-
attr_accessor :method
|
3
|
+
attr_reader :username, :password, :host, :protocol, :open_timeout
|
9
4
|
|
10
5
|
def initialize(*args)
|
11
6
|
if args[0].is_a?(Hash)
|
@@ -22,25 +17,15 @@ module Cleversafe
|
|
22
17
|
@protocol = args[3] || "http"
|
23
18
|
@open_timeout = args[4] || 10
|
24
19
|
end
|
25
|
-
|
26
|
-
@connection ||= begin
|
27
|
-
build_connection
|
28
|
-
end
|
29
|
-
return @connection
|
30
|
-
end
|
31
|
-
|
32
|
-
def build_connection
|
33
|
-
RestClient::Resource.new(base_url, :user => @username, :password => @password,
|
34
|
-
:raw_response => true, :open_timeout => @open_timeout)
|
35
20
|
end
|
36
21
|
|
37
22
|
def base_url
|
38
|
-
"#{
|
23
|
+
"#{protocol}://#{host}/"
|
39
24
|
end
|
40
25
|
|
41
26
|
def url_for(vault, objectname, options={})
|
42
|
-
protocol = options.fetch(:protocol,
|
43
|
-
host = options.fetch(:host,
|
27
|
+
protocol = options.fetch(:protocol, protocol)
|
28
|
+
host = options.fetch(:host, host)
|
44
29
|
|
45
30
|
"#{protocol}://#{host}/#{vault}/#{objectname}"
|
46
31
|
end
|
@@ -55,29 +40,36 @@ module Cleversafe
|
|
55
40
|
end
|
56
41
|
|
57
42
|
def vault_exists?(vault_name)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
false
|
63
|
-
end
|
43
|
+
get(vault_name)
|
44
|
+
true
|
45
|
+
rescue RestClient::ResourceNotFound
|
46
|
+
false
|
64
47
|
end
|
65
48
|
|
66
49
|
def get(path, options = {})
|
67
|
-
|
50
|
+
connection[path].get options
|
68
51
|
end
|
69
52
|
|
70
53
|
def head(path, options = {})
|
71
|
-
|
54
|
+
connection[path].head options
|
72
55
|
end
|
73
56
|
|
74
57
|
def put(path, payload, options = {})
|
75
|
-
|
58
|
+
connection[path].put payload, options
|
76
59
|
end
|
77
60
|
|
78
61
|
def delete(path)
|
79
|
-
|
62
|
+
connection[path].delete
|
80
63
|
end
|
81
64
|
|
65
|
+
private
|
66
|
+
def connection
|
67
|
+
@connection ||= RestClient::Resource.new(base_url,
|
68
|
+
:user => username,
|
69
|
+
:password => password,
|
70
|
+
:open_timeout => open_timeout,
|
71
|
+
:raw_response => true
|
72
|
+
)
|
73
|
+
end
|
82
74
|
end
|
83
75
|
end
|
data/lib/cleversafe/errors.rb
CHANGED
data/lib/cleversafe/object.rb
CHANGED
@@ -3,41 +3,44 @@ require 'fileutils'
|
|
3
3
|
module Cleversafe
|
4
4
|
class Object
|
5
5
|
|
6
|
-
attr_reader :name
|
7
|
-
attr_reader :vault
|
6
|
+
attr_reader :connection, :vault, :name
|
8
7
|
|
9
|
-
def initialize(vault,
|
10
|
-
@vault = vault.name
|
11
|
-
@name = objectname
|
8
|
+
def initialize(vault, name = {})
|
12
9
|
@connection = vault.connection
|
10
|
+
@vault = vault.name
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
|
14
|
+
def key
|
15
|
+
"#{vault}/#{name}"
|
13
16
|
end
|
14
17
|
|
15
18
|
def url(options={})
|
16
|
-
|
19
|
+
connection.url_for(vault, name, options)
|
17
20
|
end
|
18
21
|
|
19
22
|
def delete
|
20
23
|
handle_errors do
|
21
|
-
|
24
|
+
connection.delete(key)
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
25
28
|
def exists?
|
26
29
|
metadata
|
27
30
|
true
|
28
|
-
rescue
|
31
|
+
rescue Errors::NotFound
|
29
32
|
false
|
30
33
|
end
|
31
34
|
|
32
35
|
def data(options={})
|
33
36
|
handle_errors do
|
34
|
-
|
37
|
+
connection.get(key, options).to_s
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
38
41
|
def open(options={})
|
39
42
|
handle_errors do
|
40
|
-
response =
|
43
|
+
response = connection.get(key, options)
|
41
44
|
begin
|
42
45
|
yield response.file.open
|
43
46
|
ensure
|
@@ -48,14 +51,16 @@ module Cleversafe
|
|
48
51
|
|
49
52
|
def write_to(filename, options={})
|
50
53
|
handle_errors do
|
51
|
-
response =
|
54
|
+
response = connection.get(key, options)
|
52
55
|
FileUtils.cp(response.file.path, filename)
|
53
56
|
FileUtils.rm(response.file.path)
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
57
60
|
def metadata
|
58
|
-
@metadata ||= handle_errors
|
61
|
+
@metadata ||= handle_errors do
|
62
|
+
connection.head(key).headers
|
63
|
+
end
|
59
64
|
end
|
60
65
|
|
61
66
|
def etag
|
@@ -70,12 +75,8 @@ module Cleversafe
|
|
70
75
|
|
71
76
|
def handle_errors
|
72
77
|
yield
|
73
|
-
rescue RestClient::
|
74
|
-
|
75
|
-
raise Error::NotFound, "object `#{@name}' does not exist", caller[0..-2]
|
76
|
-
else
|
77
|
-
raise
|
78
|
-
end
|
78
|
+
rescue RestClient::ResourceNotFound
|
79
|
+
raise Cleversafe::Errors::NotFound, "object `#{name}' does not exist", caller[0..-2]
|
79
80
|
end
|
80
81
|
end
|
81
82
|
end
|
data/lib/cleversafe/vault.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module Cleversafe
|
2
2
|
class Vault
|
3
|
-
|
4
|
-
attr_reader :name
|
5
|
-
attr_reader :connection
|
3
|
+
attr_reader :connection, :name
|
6
4
|
|
7
5
|
def initialize(connection, name)
|
8
6
|
@connection = connection
|
@@ -10,7 +8,7 @@ module Cleversafe
|
|
10
8
|
end
|
11
9
|
|
12
10
|
def metadata
|
13
|
-
@metadata ||= JSON.parse(
|
11
|
+
@metadata ||= JSON.parse(connection.get(name))
|
14
12
|
end
|
15
13
|
|
16
14
|
def bytes_used
|
@@ -27,15 +25,15 @@ module Cleversafe
|
|
27
25
|
options['X-Operation'] = "list"
|
28
26
|
options['X-List-Length-Limit'] = params[:limit] if params[:limit]
|
29
27
|
options['X-Start-Id'] = params[:start_id] if params[:start_id]
|
30
|
-
|
28
|
+
connection.get(name, options).to_s.split("\n")
|
31
29
|
end
|
32
30
|
|
33
31
|
def create_object(payload, options = {})
|
34
|
-
response =
|
32
|
+
response = connection.put(name, payload, options)
|
35
33
|
id = response.to_s.strip
|
36
34
|
|
37
35
|
if response.headers[:x_content_digest]
|
38
|
-
{:id => id, :x_content_digest => response.headers[:x_content_digest] }
|
36
|
+
{ :id => id, :x_content_digest => response.headers[:x_content_digest] }
|
39
37
|
else
|
40
38
|
id
|
41
39
|
end
|
data/lib/cleversafe.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rest-client'
|
4
|
-
require 'json'
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
require 'cleversafe/connection'
|
4
|
+
require 'cleversafe/errors'
|
5
|
+
require 'cleversafe/vault'
|
6
|
+
require 'cleversafe/object'
|
7
|
+
require 'cleversafe/connection'
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 8
|
9
|
+
version: 1.0.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- John Williams
|
@@ -22,11 +22,13 @@ dependencies:
|
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ~>
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
segments:
|
28
|
-
-
|
29
|
-
|
28
|
+
- 1
|
29
|
+
- 6
|
30
|
+
- 7
|
31
|
+
version: 1.6.7
|
30
32
|
type: :runtime
|
31
33
|
version_requirements: *id001
|
32
34
|
description:
|
@@ -38,11 +40,17 @@ extensions: []
|
|
38
40
|
extra_rdoc_files: []
|
39
41
|
|
40
42
|
files:
|
41
|
-
-
|
42
|
-
-
|
43
|
-
-
|
44
|
-
-
|
45
|
-
- lib/cleversafe.rb
|
43
|
+
- ./cleversafe-1.0.7.gem
|
44
|
+
- ./cleversafe.gemspec
|
45
|
+
- ./Gemfile
|
46
|
+
- ./Gemfile.lock
|
47
|
+
- ./lib/cleversafe/connection.rb
|
48
|
+
- ./lib/cleversafe/errors.rb
|
49
|
+
- ./lib/cleversafe/object.rb
|
50
|
+
- ./lib/cleversafe/vault.rb
|
51
|
+
- ./lib/cleversafe.rb
|
52
|
+
- ./Rakefile
|
53
|
+
- ./README.md
|
46
54
|
has_rdoc: true
|
47
55
|
homepage:
|
48
56
|
licenses: []
|