cryptkeeper 0.2.1 → 0.2.2
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/cryptkeeper.gemspec +3 -2
- data/lib/buckets.rb +65 -27
- data/lib/crypt_keeper.rb +14 -30
- data/lib/crypt_keeper_http.rb +43 -0
- data/lib/objects.rb +0 -3
- metadata +4 -3
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.2"
|
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-15}
|
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 = [
|
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
"cryptkeeper.gemspec",
|
23
23
|
"lib/buckets.rb",
|
24
24
|
"lib/crypt_keeper.rb",
|
25
|
+
"lib/crypt_keeper_http.rb",
|
25
26
|
"lib/objects.rb"
|
26
27
|
]
|
27
28
|
s.homepage = %q{http://github.com/adamthedeveloper/cryptkeeper}
|
data/lib/buckets.rb
CHANGED
@@ -1,52 +1,67 @@
|
|
1
|
+
require 'hpricot'
|
1
2
|
module Buckets
|
2
3
|
# GET Service
|
3
4
|
# lists all of the buckets that you own
|
4
5
|
# return an array of Bucket objects
|
5
6
|
def buckets
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
req = Net::HTTP::Get.new("/")
|
11
|
-
req.add_field('Host', @host[:address])
|
12
|
-
req.add_field('Date', time)
|
13
|
-
req.add_field('Content-Length',0)
|
14
|
-
|
15
|
-
sig = signature("GET\n\n\n#{time}\n/")
|
16
|
-
|
17
|
-
req.add_field('Authorization', "#{@signature_id} #{@access_key}:#{sig}")
|
18
|
-
res = http.request(req)
|
19
|
-
end
|
20
|
-
|
21
|
-
hpr = Hpricot(res.body)
|
22
|
-
bucket_hashes = hpr.search("bucket").map do |el|
|
23
|
-
{
|
24
|
-
:name => el.search("name").inner_html,
|
25
|
-
:created_at => el.search("creationdate").inner_html
|
7
|
+
Hpricot(CryptKeeper::Connection.http_instance.get("/")).search("bucket").map do |el|
|
8
|
+
hsh = {
|
9
|
+
:name => el.search("name").inner_html,
|
10
|
+
:created_at => el.search("creationdate").inner_html
|
26
11
|
}
|
12
|
+
Bucket.new(hsh)
|
27
13
|
end
|
28
|
-
|
29
|
-
bucket_hashes.collect { |h| Bucket.new(h) }
|
30
14
|
end
|
31
15
|
|
32
16
|
# GET Bucket
|
33
17
|
# lists the contents of a bucket or retrieves the ACLs that are
|
34
18
|
# applied to a bucket.
|
35
|
-
# return
|
36
|
-
def
|
19
|
+
# return an array of BucketObjects
|
20
|
+
def bucket_meta_objects(bucket_name, *args)
|
21
|
+
options = {
|
22
|
+
:delimeter => nil,
|
23
|
+
:marker => nil,
|
24
|
+
:max_keys => nil,
|
25
|
+
:prefix => nil
|
26
|
+
}
|
27
|
+
options.merge!(args.pop) if args.last.is_a? Hash
|
28
|
+
|
29
|
+
path = "/?"
|
30
|
+
path << "delimeter=#{options[:delimeter]}&" if !options[:delimeter].nil?
|
31
|
+
path << "marker=#{options[:marker]}&" if !options[:marker].nil?
|
32
|
+
path << "max-keys=#{options[:max_keys]}&" if !options[:max_keys].nil?
|
33
|
+
path << "prefix=#{options[:prefix]}&" if !options[:prefix].nil?
|
34
|
+
path.gsub!(/[&]$/, '')
|
37
35
|
|
36
|
+
hpr = Hpricot(CryptKeeper::Connection.http_instance.get(path, bucket_name))
|
37
|
+
obj_hashes = hpr.search("contents").map do |el|
|
38
|
+
{
|
39
|
+
:bucket_name => bucket_name,
|
40
|
+
:key => el.search("key").inner_html,
|
41
|
+
:last_modified => el.search("lastmodified").inner_html,
|
42
|
+
:e_tag => el.search("etag").inner_html,
|
43
|
+
:size => el.search("size").inner_html,
|
44
|
+
:storage_class => el.search("storageclass").inner_html,
|
45
|
+
:owner_id => el.search("id").inner_html,
|
46
|
+
:owner_display_name => el.search("displayname").inner_html
|
47
|
+
}
|
48
|
+
end
|
49
|
+
obj_hashes.map { |obj| BucketMetaObject.new(obj) }
|
38
50
|
end
|
39
51
|
|
40
52
|
def create_bucket(*args)
|
41
|
-
|
53
|
+
|
42
54
|
end
|
43
55
|
|
56
|
+
|
57
|
+
|
44
58
|
class Bucket
|
45
59
|
attr_accessor :name, :created_at
|
60
|
+
|
46
61
|
def initialize(*args)
|
47
62
|
options = {}
|
48
63
|
options.merge!(args.pop) if args.last.is_a? Hash
|
49
|
-
@name
|
64
|
+
@name = options[:name]
|
50
65
|
@created_at = options[:created_at]
|
51
66
|
end
|
52
67
|
|
@@ -57,9 +72,32 @@ module Buckets
|
|
57
72
|
def update(*args)
|
58
73
|
|
59
74
|
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class BucketMetaObject
|
78
|
+
attr_accessor :properties,
|
79
|
+
:key, :last_modified, :e_tag, :size, :storage_class,
|
80
|
+
:owner_id, :owner_display_name,
|
81
|
+
:bucket_name
|
82
|
+
|
83
|
+
def initialize(*args)
|
84
|
+
@properties = args.first
|
85
|
+
@bucket_name = @properties[:bucket_name]
|
86
|
+
@key = @properties[:key]
|
87
|
+
@last_modified = @properties[:last_modified]
|
88
|
+
@e_tag = @properties[:e_tag]
|
89
|
+
@size = @properties[:size]
|
90
|
+
@storage_class = @properties[:storage_class]
|
91
|
+
@owner_id = @properties[:owner_id]
|
92
|
+
@owner_display_name = @properties[:owner_display_name]
|
93
|
+
end
|
60
94
|
|
61
|
-
def
|
95
|
+
def object
|
96
|
+
@object ||= object!
|
97
|
+
end
|
62
98
|
|
99
|
+
def object!
|
100
|
+
CryptKeeper::Connection.http_instance.get("/#{URI.escape(@key)}", @bucket_name)
|
63
101
|
end
|
64
102
|
end
|
65
103
|
end
|
data/lib/crypt_keeper.rb
CHANGED
@@ -1,47 +1,31 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require '
|
4
|
-
require 'iconv'
|
5
|
-
require 'hmac-sha1'
|
6
|
-
require 'base64'
|
1
|
+
ck_path = File.expand_path(File.dirname(__FILE__))
|
2
|
+
require ck_path + '/buckets.rb'
|
3
|
+
require ck_path + '/crypt_keeper_http.rb'
|
7
4
|
require 'uri'
|
8
|
-
require 'hpricot'
|
9
5
|
|
10
6
|
module CryptKeeper
|
11
|
-
VERSION = "0.2.
|
7
|
+
VERSION = "0.2.2"
|
12
8
|
class Connection
|
9
|
+
@@http_instance = nil
|
10
|
+
def self.http_instance
|
11
|
+
@@http_instance
|
12
|
+
end
|
13
13
|
def initialize(*args)
|
14
14
|
options = {
|
15
15
|
:signature_identifier => "GOOG1",
|
16
|
-
:host
|
17
|
-
:port
|
16
|
+
:host => "commondatastorage.googleapis.com",
|
17
|
+
:port => "80"
|
18
18
|
}
|
19
19
|
|
20
20
|
options.merge!(args.pop) if args.last.kind_of? Hash
|
21
|
-
|
22
|
-
@access_key
|
23
|
-
@secret_key
|
21
|
+
@host = options[:host]
|
22
|
+
@access_key = options[:access_key]
|
23
|
+
@secret_key = options[:secret_key]
|
24
24
|
@signature_id = options[:signature_identifier]
|
25
|
-
@host
|
26
|
-
:address => options[:host],
|
27
|
-
:port => options[:port]
|
28
|
-
}
|
29
|
-
@ic_utf8 = Iconv.new('ascii//TRANSLIT//IGNORE', 'UTF-8')
|
30
|
-
end
|
31
|
-
|
32
|
-
def signature(message)
|
33
|
-
utf8_message = @ic_utf8.iconv(message)
|
34
|
-
utf8_key = @ic_utf8.iconv(@secret_key)
|
35
|
-
sha1 = HMAC::SHA1.digest(utf8_key, utf8_message)
|
36
|
-
Base64.encode64(sha1).strip
|
37
|
-
end
|
38
|
-
|
39
|
-
def request_time
|
40
|
-
Time.now.strftime("%a, %d %b %Y %H:%M:%S %z")
|
25
|
+
@@http_instance = CryptKeeperHttp.new(@host, @access_key, @secret_key, @signature_id)
|
41
26
|
end
|
42
27
|
|
43
28
|
include Buckets
|
44
|
-
include Objects
|
45
29
|
end
|
46
30
|
|
47
31
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'iconv'
|
3
|
+
require 'hmac-sha1'
|
4
|
+
require 'base64'
|
5
|
+
class CryptKeeperHttp
|
6
|
+
def initialize(address, access_key, secret_key, signature_id)
|
7
|
+
@address = address
|
8
|
+
@access_key = access_key
|
9
|
+
@secret_key = secret_key
|
10
|
+
@signature_id = signature_id
|
11
|
+
end
|
12
|
+
|
13
|
+
def signature(message)
|
14
|
+
ic_utf8 = Iconv.new('ascii//TRANSLIT//IGNORE', 'UTF-8')
|
15
|
+
utf8_message = ic_utf8.iconv(message)
|
16
|
+
utf8_key = ic_utf8.iconv(@secret_key)
|
17
|
+
sha1 = HMAC::SHA1.digest(utf8_key, utf8_message)
|
18
|
+
Base64.encode64(sha1).strip
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(path, bucket_name='', additional_headers={})
|
22
|
+
bucket_name = "#{bucket_name}." if !bucket_name.empty?
|
23
|
+
res = nil
|
24
|
+
time = Time.now.strftime("%a, %d %b %Y %H:%M:%S %z")
|
25
|
+
Net::HTTP.start(@address) do |http|
|
26
|
+
|
27
|
+
req = Net::HTTP::Get.new(path)
|
28
|
+
req.add_field('Host', "#{bucket_name}#{@address}")
|
29
|
+
|
30
|
+
if !additional_headers.empty?
|
31
|
+
additional_headers.each { |k, v| req.add_field(k, v) }
|
32
|
+
end
|
33
|
+
|
34
|
+
req.add_field('Date', time)
|
35
|
+
req.add_field('Content-Length', 0)
|
36
|
+
sig = signature("GET\n\n\n#{time}\n#{!bucket_name.empty? ? "/#{bucket_name.gsub(/[\.]$/, path.gsub(/\?.*$/,''))}" : "/"}")
|
37
|
+
req.add_field('Authorization', "#{@signature_id} #{@access_key}:#{sig}")
|
38
|
+
res = http.request(req)
|
39
|
+
end
|
40
|
+
return res.body if res
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
end
|
data/lib/objects.rb
CHANGED
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
|
+
- 2
|
9
|
+
version: 0.2.2
|
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-15 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- cryptkeeper.gemspec
|
72
72
|
- lib/buckets.rb
|
73
73
|
- lib/crypt_keeper.rb
|
74
|
+
- lib/crypt_keeper_http.rb
|
74
75
|
- lib/objects.rb
|
75
76
|
has_rdoc: true
|
76
77
|
homepage: http://github.com/adamthedeveloper/cryptkeeper
|