cryptkeeper 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +11 -0
- data/cryptkeeper.gemspec +2 -2
- data/lib/buckets.rb +35 -4
- data/lib/crypt_keeper.rb +11 -1
- data/lib/crypt_keeper_http.rb +3 -1
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -47,6 +47,17 @@ Add a new object to a bucket
|
|
47
47
|
data = File.open("/Users/user/Desktop/text_file.txt", 'r')
|
48
48
|
new_bucket.add_object("myTextFile.txt", data) # if you don't specify a content type, binary/octet-stream is used
|
49
49
|
|
50
|
+
Copy an object from one bucket to another
|
51
|
+
# Fetch an object
|
52
|
+
my_object = keeper.bucket_meta_objects('adam_new_bucket3', {:prefix => 'Picture%205.png'}).first
|
53
|
+
|
54
|
+
# Copy an object to another bucket
|
55
|
+
my_object.copy_to 'adam_first_bucket' # copy to a different bucket and keep the path intact
|
56
|
+
my_object.copy_to 'adam_new_bucket', 'path_1/path_2/path_3/Picture5.png' # copy to a different bucket and path
|
57
|
+
|
58
|
+
Delete an object
|
59
|
+
my_object.delete
|
60
|
+
|
50
61
|
Delete an object
|
51
62
|
keeper.bucket_meta_objects('adam_new_bucket3', {:prefix => 'Picture%205.png'}).first.delete
|
52
63
|
|
data/cryptkeeper.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cryptkeeper}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Adam Medeiros"]
|
12
|
-
s.date = %q{2011-02-
|
12
|
+
s.date = %q{2011-02-20}
|
13
13
|
s.description = %q{Use cryptkeeper to talk to Google Storage}
|
14
14
|
s.email = %q{adammede@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/buckets.rb
CHANGED
@@ -2,7 +2,6 @@ require 'hpricot'
|
|
2
2
|
require 'digest/md5'
|
3
3
|
module Buckets
|
4
4
|
|
5
|
-
# Bucket stuff
|
6
5
|
# GET Service
|
7
6
|
# lists all of the buckets that you own
|
8
7
|
# return an array of Bucket objects
|
@@ -10,16 +9,21 @@ module Buckets
|
|
10
9
|
find_buckets
|
11
10
|
end
|
12
11
|
|
12
|
+
# returns the connection object that was initialized
|
13
13
|
def connection
|
14
14
|
CryptKeeper::Connection.http_instance
|
15
15
|
end
|
16
16
|
|
17
|
+
# create a bucket. Takes a Hash as it's argument
|
18
|
+
# {:name => 'my_new_bucket_name'}
|
17
19
|
def create_bucket(*args)
|
18
20
|
options = args.last
|
19
21
|
connection.put("/", options[:name])
|
20
22
|
find_buckets(options)
|
21
23
|
end
|
22
24
|
|
25
|
+
# search for buckets by name
|
26
|
+
# {:name => 'my_bucket_name'}
|
23
27
|
def find_buckets(*args)
|
24
28
|
options = args.last
|
25
29
|
name = options[:name] if options.is_a? Hash
|
@@ -37,7 +41,13 @@ module Buckets
|
|
37
41
|
# GET Bucket
|
38
42
|
# lists the contents of a bucket or retrieves the ACLs that are
|
39
43
|
# applied to a bucket.
|
40
|
-
#
|
44
|
+
# returns an array of BucketMetaObjects
|
45
|
+
# takes a bucket name and hash for options.
|
46
|
+
# Possible keys for the hash are
|
47
|
+
# * :delimeter
|
48
|
+
# * :marker
|
49
|
+
# * :max_keys
|
50
|
+
# * :prefix
|
41
51
|
def bucket_meta_objects(bucket_name, *args)
|
42
52
|
options = {
|
43
53
|
:delimeter => nil,
|
@@ -70,12 +80,16 @@ module Buckets
|
|
70
80
|
obj_hashes.map { |obj| BucketMetaObject.new(obj) }
|
71
81
|
end
|
72
82
|
|
83
|
+
# Utils class
|
73
84
|
class Utils
|
85
|
+
|
86
|
+
# returns a connection instance
|
74
87
|
def connection
|
75
88
|
CryptKeeper::Connection.http_instance
|
76
89
|
end
|
77
90
|
end
|
78
91
|
|
92
|
+
# Bucket
|
79
93
|
class Bucket < Utils
|
80
94
|
attr_accessor :name, :created_at
|
81
95
|
|
@@ -86,14 +100,19 @@ module Buckets
|
|
86
100
|
@created_at = options[:created_at]
|
87
101
|
end
|
88
102
|
|
103
|
+
# Delete this bucket if it's empty
|
89
104
|
def delete(options={})
|
90
105
|
connection.delete("/", @name)
|
91
106
|
end
|
92
107
|
|
93
|
-
|
108
|
+
#
|
109
|
+
#def update(*args)
|
94
110
|
|
95
|
-
end
|
111
|
+
#end
|
96
112
|
|
113
|
+
# add an object to this bucket
|
114
|
+
# pass in a name, a File or IO object, it's content type and a hash
|
115
|
+
# containing additional headers (keys and values)
|
97
116
|
def add_object(name, data, content_type='binary/octet-stream', *args)
|
98
117
|
data.rewind
|
99
118
|
additional_headers = {
|
@@ -105,6 +124,8 @@ module Buckets
|
|
105
124
|
end
|
106
125
|
end
|
107
126
|
|
127
|
+
# BucketMetaObject
|
128
|
+
# Contains information about an object
|
108
129
|
class BucketMetaObject < Utils
|
109
130
|
attr_accessor :properties,
|
110
131
|
:key, :last_modified, :e_tag, :size, :storage_class,
|
@@ -123,16 +144,26 @@ module Buckets
|
|
123
144
|
@owner_display_name = @properties[:owner_display_name]
|
124
145
|
end
|
125
146
|
|
147
|
+
# When called, returns the previously set data of the object. If the object data
|
148
|
+
# hasn't been set, it will go fetch it from Google Storage and set it as an instance
|
149
|
+
# variable to be returned next time.
|
126
150
|
def object
|
127
151
|
@object ||= object!
|
128
152
|
end
|
129
153
|
|
154
|
+
# Forces retrieval of the object data from Google Storage.
|
130
155
|
def object!
|
131
156
|
connection.get("/#{URI.escape(@key)}", @bucket_name)
|
132
157
|
end
|
133
158
|
|
159
|
+
# Deletes the object from the bucket.
|
134
160
|
def delete
|
135
161
|
connection.delete("/#{URI.escape(@key)}", @bucket_name)
|
136
162
|
end
|
163
|
+
|
164
|
+
def copy_to(bucket_name, path=nil)
|
165
|
+
path = path.nil? ? "/#{URI.escape(@key)}" : "/#{URI.escape(path)}"
|
166
|
+
connection.put(path, bucket_name, nil, {'x-goog-copy-source' => "#{@bucket_name}/#{URI.escape(@key)}"})
|
167
|
+
end
|
137
168
|
end
|
138
169
|
end
|
data/lib/crypt_keeper.rb
CHANGED
@@ -4,7 +4,17 @@ require ck_path + '/crypt_keeper_http.rb'
|
|
4
4
|
require 'uri'
|
5
5
|
|
6
6
|
module CryptKeeper
|
7
|
-
VERSION = "0.2.
|
7
|
+
VERSION = "0.2.6"
|
8
|
+
|
9
|
+
# :title: Connection
|
10
|
+
# Author:: Adam R. Medeiros (AKA: ScaryThings)
|
11
|
+
# License:: MIT Style
|
12
|
+
|
13
|
+
# Builds the connection to Google Storage with the credentials
|
14
|
+
# passed in.
|
15
|
+
|
16
|
+
# For example:
|
17
|
+
# keeper = CryptKeeper::Connection.new({:access_key => 'your_access_key', :secret_key => 'your_secret_key'})
|
8
18
|
class Connection
|
9
19
|
@@http_instance = nil
|
10
20
|
def self.http_instance
|
data/lib/crypt_keeper_http.rb
CHANGED
@@ -48,10 +48,12 @@ class CryptKeeperHttp
|
|
48
48
|
|
49
49
|
content_md5 = ''
|
50
50
|
content_type = ''
|
51
|
+
x_headers = ''
|
51
52
|
|
52
53
|
if !additional_headers.empty?
|
53
54
|
additional_headers.each do |k, v|
|
54
55
|
req.add_field(k, v)
|
56
|
+
x_headers << "#{k}:#{v}\n" if k[0..5] == "x-goog"
|
55
57
|
if type==PUT
|
56
58
|
case k
|
57
59
|
when 'Content-MD5'
|
@@ -80,7 +82,7 @@ class CryptKeeperHttp
|
|
80
82
|
req.add_field('Host', "#{bucket_name}#{@address}")
|
81
83
|
req.add_field('Date', time)
|
82
84
|
req.add_field('Content-length', content_length)
|
83
|
-
sig = "#{type}\n#{content_md5}\n#{content_type}\n#{time}\n#{sig_path}"
|
85
|
+
sig = "#{type}\n#{content_md5}\n#{content_type}\n#{time}\n#{x_headers}#{sig_path}"
|
84
86
|
req.add_field('Authorization', "#{@signature_id} #{@access_key}:#{signature(sig)}")
|
85
87
|
|
86
88
|
res = http.request(req)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 6
|
9
|
+
version: 0.2.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Adam Medeiros
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-02-
|
17
|
+
date: 2011-02-20 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|