fog 0.0.56 → 0.0.57
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION.yml +1 -1
- data/fog.gemspec +4 -4
- data/lib/fog/aws.rb +4 -3
- data/lib/fog/aws/ec2.rb +136 -150
- data/lib/fog/aws/models/ec2/address.rb +3 -1
- data/lib/fog/aws/models/ec2/addresses.rb +20 -6
- data/lib/fog/aws/models/ec2/flavor.rb +3 -1
- data/lib/fog/aws/models/ec2/flavors.rb +14 -3
- data/lib/fog/aws/models/ec2/image.rb +3 -1
- data/lib/fog/aws/models/ec2/images.rb +14 -3
- data/lib/fog/aws/models/ec2/key_pair.rb +3 -1
- data/lib/fog/aws/models/ec2/key_pairs.rb +14 -3
- data/lib/fog/aws/models/ec2/security_group.rb +3 -1
- data/lib/fog/aws/models/ec2/security_groups.rb +14 -3
- data/lib/fog/aws/models/ec2/server.rb +3 -1
- data/lib/fog/aws/models/ec2/servers.rb +14 -3
- data/lib/fog/aws/models/ec2/snapshot.rb +3 -1
- data/lib/fog/aws/models/ec2/snapshots.rb +18 -5
- data/lib/fog/aws/models/ec2/volume.rb +3 -1
- data/lib/fog/aws/models/ec2/volumes.rb +18 -5
- data/lib/fog/aws/models/s3/directories.rb +14 -3
- data/lib/fog/aws/models/s3/directory.rb +4 -1
- data/lib/fog/aws/models/s3/file.rb +3 -1
- data/lib/fog/aws/models/s3/files.rb +4 -1
- data/lib/fog/aws/parsers/simpledb/domain_metadata.rb +2 -0
- data/lib/fog/aws/parsers/simpledb/get_attributes.rb +2 -0
- data/lib/fog/aws/parsers/simpledb/list_domains.rb +2 -0
- data/lib/fog/aws/parsers/simpledb/select.rb +2 -0
- data/lib/fog/aws/requests/ec2/allocate_address.rb +11 -16
- data/lib/fog/aws/requests/ec2/associate_address.rb +14 -19
- data/lib/fog/aws/requests/ec2/attach_volume.rb +16 -21
- data/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +29 -27
- data/lib/fog/aws/requests/ec2/create_key_pair.rb +13 -18
- data/lib/fog/aws/requests/ec2/create_security_group.rb +14 -19
- data/lib/fog/aws/requests/ec2/create_snapshot.rb +13 -18
- data/lib/fog/aws/requests/ec2/create_volume.rb +14 -19
- data/lib/fog/aws/requests/ec2/delete_key_pair.rb +12 -17
- data/lib/fog/aws/requests/ec2/delete_security_group.rb +13 -18
- data/lib/fog/aws/requests/ec2/delete_snapshot.rb +12 -17
- data/lib/fog/aws/requests/ec2/delete_volume.rb +13 -18
- data/lib/fog/aws/requests/ec2/describe_addresses.rb +11 -16
- data/lib/fog/aws/requests/ec2/describe_availability_zones.rb +9 -14
- data/lib/fog/aws/requests/ec2/describe_images.rb +9 -14
- data/lib/fog/aws/requests/ec2/describe_instances.rb +17 -22
- data/lib/fog/aws/requests/ec2/describe_key_pairs.rb +11 -16
- data/lib/fog/aws/requests/ec2/describe_regions.rb +9 -14
- data/lib/fog/aws/requests/ec2/describe_reserved_instances.rb +9 -14
- data/lib/fog/aws/requests/ec2/describe_security_groups.rb +11 -16
- data/lib/fog/aws/requests/ec2/describe_snapshots.rb +12 -17
- data/lib/fog/aws/requests/ec2/describe_volumes.rb +14 -19
- data/lib/fog/aws/requests/ec2/detach_volume.rb +11 -16
- data/lib/fog/aws/requests/ec2/disassociate_address.rb +12 -17
- data/lib/fog/aws/requests/ec2/get_console_output.rb +12 -17
- data/lib/fog/aws/requests/ec2/reboot_instances.rb +11 -16
- data/lib/fog/aws/requests/ec2/release_address.rb +12 -17
- data/lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb +10 -15
- data/lib/fog/aws/requests/ec2/run_instances.rb +36 -38
- data/lib/fog/aws/requests/ec2/terminate_instances.rb +16 -20
- data/lib/fog/aws/requests/s3/copy_object.rb +9 -15
- data/lib/fog/aws/requests/s3/delete_bucket.rb +9 -16
- data/lib/fog/aws/requests/s3/delete_object.rb +6 -14
- data/lib/fog/aws/requests/s3/get_bucket.rb +9 -14
- data/lib/fog/aws/requests/s3/get_bucket_location.rb +8 -14
- data/lib/fog/aws/requests/s3/get_object.rb +7 -15
- data/lib/fog/aws/requests/s3/get_request_payment.rb +7 -13
- data/lib/fog/aws/requests/s3/get_service.rb +7 -13
- data/lib/fog/aws/requests/s3/head_object.rb +6 -14
- data/lib/fog/aws/requests/s3/put_bucket.rb +13 -21
- data/lib/fog/aws/requests/s3/put_object.rb +8 -16
- data/lib/fog/aws/requests/s3/put_request_payment.rb +7 -16
- data/lib/fog/aws/requests/simpledb/batch_put_attributes.rb +14 -21
- data/lib/fog/aws/requests/simpledb/create_domain.rb +11 -18
- data/lib/fog/aws/requests/simpledb/delete_attributes.rb +15 -22
- data/lib/fog/aws/requests/simpledb/delete_domain.rb +11 -18
- data/lib/fog/aws/requests/simpledb/domain_metadata.rb +14 -19
- data/lib/fog/aws/requests/simpledb/get_attributes.rb +19 -23
- data/lib/fog/aws/requests/simpledb/list_domains.rb +11 -16
- data/lib/fog/aws/requests/simpledb/put_attributes.rb +15 -15
- data/lib/fog/aws/requests/simpledb/select.rb +12 -17
- data/lib/fog/aws/s3.rb +117 -121
- data/lib/fog/aws/simpledb.rb +127 -127
- data/lib/fog/rackspace/models/servers/images.rb +1 -1
- data/spec/aws/requests/ec2/authorize_security_group_ingress_spec.rb +11 -1
- metadata +4 -4
@@ -1,8 +1,9 @@
|
|
1
|
-
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
module SimpleDB
|
4
|
+
class Real
|
2
5
|
|
3
|
-
|
4
|
-
module AWS
|
5
|
-
class SimpleDB
|
6
|
+
require 'fog/aws/parsers/simpledb/list_domains'
|
6
7
|
|
7
8
|
# List SimpleDB domains
|
8
9
|
#
|
@@ -21,27 +22,22 @@ unless Fog.mocking?
|
|
21
22
|
# * 'RequestId'
|
22
23
|
def list_domains(options = {})
|
23
24
|
request({
|
24
|
-
'Action' => 'ListDomains'
|
25
|
-
|
25
|
+
'Action' => 'ListDomains',
|
26
|
+
:parser => Fog::Parsers::AWS::SimpleDB::ListDomains.new(@nil_string)
|
27
|
+
}.merge!(options))
|
26
28
|
end
|
27
29
|
|
28
30
|
end
|
29
|
-
end
|
30
|
-
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
module Fog
|
35
|
-
module AWS
|
36
|
-
class SimpleDB
|
32
|
+
class Mock
|
37
33
|
|
38
34
|
def list_domains(options = {})
|
39
35
|
response = Excon::Response.new
|
40
|
-
keys =
|
36
|
+
keys = @data[:domains].keys
|
41
37
|
max = options['MaxNumberOfDomains'] || keys.size
|
42
38
|
offset = options['NextToken'] || 0
|
43
39
|
domains = []
|
44
|
-
for key, value in
|
40
|
+
for key, value in @data[:domains].keys[offset...max]
|
45
41
|
domains << key
|
46
42
|
end
|
47
43
|
response.status = 200
|
@@ -59,5 +55,4 @@ else
|
|
59
55
|
end
|
60
56
|
end
|
61
57
|
end
|
62
|
-
|
63
58
|
end
|
@@ -1,8 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
class SimpleDB
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
module SimpleDB
|
4
|
+
class Real
|
6
5
|
|
7
6
|
# Put item attributes into a SimpleDB domain
|
8
7
|
#
|
@@ -23,25 +22,26 @@ unless Fog.mocking?
|
|
23
22
|
# * 'BoxUsage'
|
24
23
|
# * 'RequestId'
|
25
24
|
def put_attributes(domain_name, item_name, attributes, replace_attributes = [])
|
26
|
-
batch_put_attributes(
|
25
|
+
batch_put_attributes(
|
26
|
+
domain_name,
|
27
|
+
{ item_name => attributes },
|
28
|
+
{ item_name => replace_attributes }
|
29
|
+
)
|
27
30
|
end
|
28
31
|
|
29
32
|
end
|
30
|
-
end
|
31
|
-
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
module Fog
|
36
|
-
module AWS
|
37
|
-
class SimpleDb
|
34
|
+
class Mock
|
38
35
|
|
39
36
|
def put_attributes(domain_name, item_name, attributes, replace_attributes = [])
|
40
|
-
batch_put_attributes(
|
37
|
+
batch_put_attributes(
|
38
|
+
domain_name,
|
39
|
+
{ item_name => attributes },
|
40
|
+
{ item_name => replace_attributes }
|
41
|
+
)
|
41
42
|
end
|
42
43
|
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
46
|
-
|
47
47
|
end
|
@@ -1,8 +1,9 @@
|
|
1
|
-
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
module SimpleDB
|
4
|
+
class Real
|
2
5
|
|
3
|
-
|
4
|
-
module AWS
|
5
|
-
class SimpleDB
|
6
|
+
require 'fog/aws/parsers/simpledb/select'
|
6
7
|
|
7
8
|
# Select item data from SimpleDB
|
8
9
|
#
|
@@ -19,22 +20,17 @@ unless Fog.mocking?
|
|
19
20
|
# { 'item_name' => { 'attribute_name' => ['attribute_value'] }}
|
20
21
|
# * 'NextToken'<~String> - offset to start with if there are are more domains to list
|
21
22
|
def select(select_expression, next_token = nil)
|
22
|
-
request(
|
23
|
-
'Action'
|
24
|
-
'NextToken'
|
25
|
-
'SelectExpression'
|
26
|
-
|
23
|
+
request(
|
24
|
+
'Action' => 'Select',
|
25
|
+
'NextToken' => next_token,
|
26
|
+
'SelectExpression' => select_expression,
|
27
|
+
:parser => Fog::Parsers::AWS::SimpleDB::Select.new(@nil_string)
|
28
|
+
)
|
27
29
|
end
|
28
30
|
|
29
31
|
end
|
30
|
-
end
|
31
|
-
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
module Fog
|
36
|
-
module AWS
|
37
|
-
class SimpleDB
|
33
|
+
class Mock
|
38
34
|
|
39
35
|
def select(select_expression, next_token = nil)
|
40
36
|
raise MockNotImplemented.new("Contributions welcome!")
|
@@ -43,5 +39,4 @@ else
|
|
43
39
|
end
|
44
40
|
end
|
45
41
|
end
|
46
|
-
|
47
42
|
end
|
data/lib/fog/aws/s3.rb
CHANGED
@@ -1,82 +1,33 @@
|
|
1
|
+
require 'fog/aws/models/s3/directories'
|
2
|
+
require 'fog/aws/models/s3/directory'
|
3
|
+
require 'fog/aws/models/s3/files'
|
4
|
+
require 'fog/aws/models/s3/file'
|
5
|
+
require 'fog/aws/requests/s3/copy_object'
|
6
|
+
require 'fog/aws/requests/s3/delete_bucket'
|
7
|
+
require 'fog/aws/requests/s3/delete_object'
|
8
|
+
require 'fog/aws/requests/s3/get_bucket'
|
9
|
+
require 'fog/aws/requests/s3/get_bucket_location'
|
10
|
+
require 'fog/aws/requests/s3/get_object'
|
11
|
+
require 'fog/aws/requests/s3/get_request_payment'
|
12
|
+
require 'fog/aws/requests/s3/get_service'
|
13
|
+
require 'fog/aws/requests/s3/head_object'
|
14
|
+
require 'fog/aws/requests/s3/put_bucket'
|
15
|
+
require 'fog/aws/requests/s3/put_object'
|
16
|
+
require 'fog/aws/requests/s3/put_request_payment'
|
17
|
+
|
1
18
|
module Fog
|
2
19
|
module AWS
|
3
|
-
|
4
|
-
|
5
|
-
if Fog.mocking?
|
6
|
-
def self.reset_data
|
7
|
-
@data = { :buckets => {} }
|
8
|
-
end
|
9
|
-
def self.data
|
10
|
-
@data
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.dependencies
|
15
|
-
[
|
16
|
-
"fog/aws/models/s3/directory.rb",
|
17
|
-
"fog/aws/models/s3/directories.rb",
|
18
|
-
"fog/aws/models/s3/file.rb",
|
19
|
-
"fog/aws/models/s3/files.rb",
|
20
|
-
"fog/aws/parsers/s3/copy_object.rb",
|
21
|
-
"fog/aws/parsers/s3/get_bucket.rb",
|
22
|
-
"fog/aws/parsers/s3/get_bucket_location.rb",
|
23
|
-
"fog/aws/parsers/s3/get_request_payment.rb",
|
24
|
-
"fog/aws/parsers/s3/get_service.rb",
|
25
|
-
"fog/aws/requests/s3/copy_object.rb",
|
26
|
-
"fog/aws/requests/s3/delete_bucket.rb",
|
27
|
-
"fog/aws/requests/s3/delete_object.rb",
|
28
|
-
"fog/aws/requests/s3/get_bucket.rb",
|
29
|
-
"fog/aws/requests/s3/get_bucket_location.rb",
|
30
|
-
"fog/aws/requests/s3/get_object.rb",
|
31
|
-
"fog/aws/requests/s3/get_request_payment.rb",
|
32
|
-
"fog/aws/requests/s3/get_service.rb",
|
33
|
-
"fog/aws/requests/s3/head_object.rb",
|
34
|
-
"fog/aws/requests/s3/put_bucket.rb",
|
35
|
-
"fog/aws/requests/s3/put_object.rb",
|
36
|
-
"fog/aws/requests/s3/put_request_payment.rb"
|
37
|
-
]
|
38
|
-
end
|
20
|
+
module S3
|
39
21
|
|
40
|
-
def self.
|
41
|
-
self.dependencies.each {|dependency| load(dependency)}
|
22
|
+
def self.new(options={})
|
42
23
|
if Fog.mocking?
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
# Initialize connection to S3
|
48
|
-
#
|
49
|
-
# ==== Notes
|
50
|
-
# options parameter must include values for :aws_access_key_id and
|
51
|
-
# :aws_secret_access_key in order to create a connection
|
52
|
-
#
|
53
|
-
# ==== Examples
|
54
|
-
# s3 = S3.new(
|
55
|
-
# :aws_access_key_id => your_aws_access_key_id,
|
56
|
-
# :aws_secret_access_key => your_aws_secret_access_key
|
57
|
-
# )
|
58
|
-
#
|
59
|
-
# ==== Parameters
|
60
|
-
# * options<~Hash> - config arguments for connection. Defaults to {}.
|
61
|
-
#
|
62
|
-
# ==== Returns
|
63
|
-
# * S3 object with connection to aws.
|
64
|
-
def initialize(options={})
|
65
|
-
unless @aws_access_key_id = options[:aws_access_key_id]
|
66
|
-
raise ArgumentError.new('aws_access_key_id is required to access ec2')
|
67
|
-
end
|
68
|
-
unless @aws_secret_access_key = options[:aws_secret_access_key]
|
69
|
-
raise ArgumentError.new('aws_secret_access_key is required to access ec2')
|
24
|
+
Fog::AWS::S3::Mock.new(options)
|
25
|
+
else
|
26
|
+
Fog::AWS::S3::Real.new(options)
|
70
27
|
end
|
71
|
-
@hmac = HMAC::SHA1.new(@aws_secret_access_key)
|
72
|
-
@host = options[:host] || 's3.amazonaws.com'
|
73
|
-
@port = options[:port] || 443
|
74
|
-
@scheme = options[:scheme] || 'https'
|
75
28
|
end
|
76
29
|
|
77
|
-
|
78
|
-
|
79
|
-
def parse_data(data)
|
30
|
+
def self.parse_data(data)
|
80
31
|
metadata = {
|
81
32
|
:body => nil,
|
82
33
|
:headers => {}
|
@@ -97,27 +48,64 @@ module Fog
|
|
97
48
|
metadata
|
98
49
|
end
|
99
50
|
|
100
|
-
|
101
|
-
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
102
|
-
params[:headers]['Date'] = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
|
103
|
-
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature(params)}"
|
51
|
+
class Mock
|
104
52
|
|
105
|
-
|
53
|
+
def reset_data
|
54
|
+
@data = { :buckets => {} }
|
55
|
+
end
|
106
56
|
|
107
|
-
|
108
|
-
|
57
|
+
def initialize(options={})
|
58
|
+
reset_data
|
59
|
+
end
|
109
60
|
|
110
|
-
def url(params, expires)
|
111
|
-
params[:headers]['Date'] = expires.to_i
|
112
|
-
query = [params[:query]].compact
|
113
|
-
query << "AWSAccessKeyId=#{@aws_access_key_id}"
|
114
|
-
query << "Signature=#{CGI.escape(signature(params))}"
|
115
|
-
query << "Expires=#{params[:headers]['Date']}"
|
116
|
-
"http://#{params[:host]}/#{params[:path]}?#{query.join('&')}"
|
117
61
|
end
|
118
62
|
|
119
|
-
|
120
|
-
|
63
|
+
class Real
|
64
|
+
|
65
|
+
# Initialize connection to S3
|
66
|
+
#
|
67
|
+
# ==== Notes
|
68
|
+
# options parameter must include values for :aws_access_key_id and
|
69
|
+
# :aws_secret_access_key in order to create a connection
|
70
|
+
#
|
71
|
+
# ==== Examples
|
72
|
+
# s3 = S3.new(
|
73
|
+
# :aws_access_key_id => your_aws_access_key_id,
|
74
|
+
# :aws_secret_access_key => your_aws_secret_access_key
|
75
|
+
# )
|
76
|
+
#
|
77
|
+
# ==== Parameters
|
78
|
+
# * options<~Hash> - config arguments for connection. Defaults to {}.
|
79
|
+
#
|
80
|
+
# ==== Returns
|
81
|
+
# * S3 object with connection to aws.
|
82
|
+
def initialize(options={})
|
83
|
+
unless @aws_access_key_id = options[:aws_access_key_id]
|
84
|
+
raise ArgumentError.new('aws_access_key_id is required to access ec2')
|
85
|
+
end
|
86
|
+
unless @aws_secret_access_key = options[:aws_secret_access_key]
|
87
|
+
raise ArgumentError.new('aws_secret_access_key is required to access ec2')
|
88
|
+
end
|
89
|
+
@hmac = HMAC::SHA1.new(@aws_secret_access_key)
|
90
|
+
@host = options[:host] || 's3.amazonaws.com'
|
91
|
+
@port = options[:port] || 443
|
92
|
+
@scheme = options[:scheme] || 'https'
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def request(params)
|
98
|
+
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
99
|
+
params[:headers]['Date'] = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
|
100
|
+
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature(params)}"
|
101
|
+
|
102
|
+
response = @connection.request(params)
|
103
|
+
|
104
|
+
response
|
105
|
+
end
|
106
|
+
|
107
|
+
def signature(params)
|
108
|
+
string_to_sign =
|
121
109
|
<<-DATA
|
122
110
|
#{params[:method]}
|
123
111
|
#{params[:headers]['Content-MD5']}
|
@@ -125,46 +113,54 @@ module Fog
|
|
125
113
|
#{params[:headers]['Date']}
|
126
114
|
DATA
|
127
115
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
116
|
+
amz_headers, canonical_amz_headers = {}, ''
|
117
|
+
for key, value in params[:headers]
|
118
|
+
if key[0..5] == 'x-amz-'
|
119
|
+
amz_headers[key] = value
|
120
|
+
end
|
132
121
|
end
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
122
|
+
amz_headers = amz_headers.sort {|x, y| x[0] <=> y[0]}
|
123
|
+
for pair in amz_headers
|
124
|
+
canonical_amz_headers << "#{pair[0]}:#{pair[1]}\n"
|
125
|
+
end
|
126
|
+
string_to_sign << "#{canonical_amz_headers}"
|
127
|
+
|
128
|
+
subdomain = params[:host].split(".#{@host}").first
|
129
|
+
unless subdomain =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/
|
130
|
+
puts("[WARN] fog: the specified s3 bucket name(#{subdomain}) is not a valid dns name. See: http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?Introduction.html")
|
131
|
+
params[:host] = params[:host].split("#{subdomain}.")[-1]
|
132
|
+
if params[:path]
|
133
|
+
params[:path] = "#{subdomain}/#{params[:path]}"
|
134
|
+
else
|
135
|
+
params[:path] = "#{subdomain}"
|
136
|
+
end
|
137
|
+
subdomain = nil
|
148
138
|
end
|
149
|
-
subdomain = nil
|
150
|
-
end
|
151
139
|
|
152
|
-
|
153
|
-
|
154
|
-
|
140
|
+
canonical_resource = "/"
|
141
|
+
unless subdomain.nil? || subdomain == @host
|
142
|
+
canonical_resource << "#{CGI.escape(subdomain).downcase}/"
|
143
|
+
end
|
144
|
+
canonical_resource << "#{params[:path]}"
|
145
|
+
if ['acl', 'location', 'logging', 'requestPayment', 'torrent'].include?(params[:query])
|
146
|
+
canonical_resource << "?#{params[:query]}"
|
147
|
+
end
|
148
|
+
string_to_sign << "#{canonical_resource}"
|
149
|
+
|
150
|
+
hmac = @hmac.update(string_to_sign)
|
151
|
+
signature = Base64.encode64(hmac.digest).chomp!
|
155
152
|
end
|
156
|
-
|
157
|
-
|
158
|
-
|
153
|
+
|
154
|
+
def url(params, expires)
|
155
|
+
params[:headers]['Date'] = expires.to_i
|
156
|
+
query = [params[:query]].compact
|
157
|
+
query << "AWSAccessKeyId=#{@aws_access_key_id}"
|
158
|
+
query << "Signature=#{CGI.escape(signature(params))}"
|
159
|
+
query << "Expires=#{params[:headers]['Date']}"
|
160
|
+
"http://#{params[:host]}/#{params[:path]}?#{query.join('&')}"
|
159
161
|
end
|
160
|
-
string_to_sign << "#{canonical_resource}"
|
161
162
|
|
162
|
-
hmac = @hmac.update(string_to_sign)
|
163
|
-
signature = Base64.encode64(hmac.digest).chomp!
|
164
163
|
end
|
165
|
-
|
166
164
|
end
|
167
165
|
end
|
168
166
|
end
|
169
|
-
|
170
|
-
Fog::AWS::S3.reload
|
data/lib/fog/aws/simpledb.rb
CHANGED
@@ -1,159 +1,159 @@
|
|
1
|
+
require 'fog/aws/requests/simpledb/batch_put_attributes'
|
2
|
+
require 'fog/aws/requests/simpledb/create_domain'
|
3
|
+
require 'fog/aws/requests/simpledb/delete_attributes'
|
4
|
+
require 'fog/aws/requests/simpledb/delete_domain'
|
5
|
+
require 'fog/aws/requests/simpledb/domain_metadata'
|
6
|
+
require 'fog/aws/requests/simpledb/get_attributes'
|
7
|
+
require 'fog/aws/requests/simpledb/list_domains'
|
8
|
+
require 'fog/aws/requests/simpledb/put_attributes'
|
9
|
+
require 'fog/aws/requests/simpledb/select'
|
10
|
+
|
1
11
|
module Fog
|
2
12
|
module AWS
|
3
|
-
|
13
|
+
module SimpleDB
|
4
14
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@data
|
15
|
+
def self.new(options={})
|
16
|
+
if Fog.mocking?
|
17
|
+
Fog::AWS::SimpleDB::Mock.new(options)
|
18
|
+
else
|
19
|
+
Fog::AWS::SimpleDB::Real.new(options)
|
11
20
|
end
|
12
21
|
end
|
13
22
|
|
14
|
-
|
15
|
-
[
|
16
|
-
"fog/aws/parsers/simpledb/basic.rb",
|
17
|
-
"fog/aws/parsers/simpledb/domain_metadata.rb",
|
18
|
-
"fog/aws/parsers/simpledb/get_attributes.rb",
|
19
|
-
"fog/aws/parsers/simpledb/list_domains.rb",
|
20
|
-
"fog/aws/parsers/simpledb/select.rb",
|
21
|
-
"fog/aws/requests/simpledb/batch_put_attributes.rb",
|
22
|
-
"fog/aws/requests/simpledb/create_domain.rb",
|
23
|
-
"fog/aws/requests/simpledb/delete_attributes.rb",
|
24
|
-
"fog/aws/requests/simpledb/delete_domain.rb",
|
25
|
-
"fog/aws/requests/simpledb/domain_metadata.rb",
|
26
|
-
"fog/aws/requests/simpledb/get_attributes.rb",
|
27
|
-
"fog/aws/requests/simpledb/list_domains.rb",
|
28
|
-
"fog/aws/requests/simpledb/put_attributes.rb",
|
29
|
-
"fog/aws/requests/simpledb/select.rb"
|
30
|
-
]
|
31
|
-
end
|
23
|
+
class Mock
|
32
24
|
|
33
|
-
|
34
|
-
|
35
|
-
|
25
|
+
def reset_data
|
26
|
+
@data = { :domains => {} }
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(options={})
|
36
30
|
reset_data
|
37
31
|
end
|
38
|
-
end
|
39
32
|
|
40
|
-
# Initialize connection to SimpleDB
|
41
|
-
#
|
42
|
-
# ==== Notes
|
43
|
-
# options parameter must include values for :aws_access_key_id and
|
44
|
-
# :aws_secret_access_key in order to create a connection
|
45
|
-
#
|
46
|
-
# ==== Examples
|
47
|
-
# sdb = SimpleDB.new(
|
48
|
-
# :aws_access_key_id => your_aws_access_key_id,
|
49
|
-
# :aws_secret_access_key => your_aws_secret_access_key
|
50
|
-
# )
|
51
|
-
#
|
52
|
-
# ==== Parameters
|
53
|
-
# * options<~Hash> - config arguments for connection. Defaults to {}.
|
54
|
-
#
|
55
|
-
# ==== Returns
|
56
|
-
# * SimpleDB object with connection to aws.
|
57
|
-
def initialize(options={})
|
58
|
-
@aws_access_key_id = options[:aws_access_key_id]
|
59
|
-
@aws_secret_access_key = options[:aws_secret_access_key]
|
60
|
-
@hmac = HMAC::SHA256.new(@aws_secret_access_key)
|
61
|
-
@host = options[:host] || 'sdb.amazonaws.com'
|
62
|
-
@nil_string = options[:nil_string]|| 'nil'
|
63
|
-
@port = options[:port] || 443
|
64
|
-
@scheme = options[:scheme] || 'https'
|
65
33
|
end
|
66
34
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
35
|
+
class Real
|
36
|
+
|
37
|
+
# Initialize connection to SimpleDB
|
38
|
+
#
|
39
|
+
# ==== Notes
|
40
|
+
# options parameter must include values for :aws_access_key_id and
|
41
|
+
# :aws_secret_access_key in order to create a connection
|
42
|
+
#
|
43
|
+
# ==== Examples
|
44
|
+
# sdb = SimpleDB.new(
|
45
|
+
# :aws_access_key_id => your_aws_access_key_id,
|
46
|
+
# :aws_secret_access_key => your_aws_secret_access_key
|
47
|
+
# )
|
48
|
+
#
|
49
|
+
# ==== Parameters
|
50
|
+
# * options<~Hash> - config arguments for connection. Defaults to {}.
|
51
|
+
#
|
52
|
+
# ==== Returns
|
53
|
+
# * SimpleDB object with connection to aws.
|
54
|
+
def initialize(options={})
|
55
|
+
@aws_access_key_id = options[:aws_access_key_id]
|
56
|
+
@aws_secret_access_key = options[:aws_secret_access_key]
|
57
|
+
@hmac = HMAC::SHA256.new(@aws_secret_access_key)
|
58
|
+
@host = options[:host] || 'sdb.amazonaws.com'
|
59
|
+
@nil_string = options[:nil_string]|| 'nil'
|
60
|
+
@port = options[:port] || 443
|
61
|
+
@scheme = options[:scheme] || 'https'
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def encode_attributes(attributes, replace_attributes = [])
|
67
|
+
encoded_attributes = {}
|
68
|
+
if attributes
|
69
|
+
index = 0
|
70
|
+
for key in attributes.keys
|
71
|
+
for value in Array(attributes[key])
|
72
|
+
encoded_attributes["Attribute.#{index}.Name"] = key.to_s
|
73
|
+
if replace_attributes.include?(key)
|
74
|
+
encoded_attributes["Attribute.#{index}.Replace"] = 'true'
|
75
|
+
end
|
76
|
+
encoded_attributes["Attribute.#{index}.Value"] = sdb_encode(value)
|
77
|
+
index += 1
|
78
78
|
end
|
79
|
-
encoded_attributes["Attribute.#{index}.Value"] = sdb_encode(value)
|
80
|
-
index += 1
|
81
79
|
end
|
82
80
|
end
|
81
|
+
encoded_attributes
|
83
82
|
end
|
84
|
-
encoded_attributes
|
85
|
-
end
|
86
83
|
|
87
|
-
|
88
|
-
|
89
|
-
|
84
|
+
def encode_attribute_names(attributes)
|
85
|
+
AWS.indexed_param('AttributeName', attributes.map {|attribute| attributes.to_s})
|
86
|
+
end
|
90
87
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
88
|
+
def encode_batch_attributes(items, replace_attributes = Hash.new([]))
|
89
|
+
encoded_attributes = {}
|
90
|
+
if items
|
91
|
+
item_index = 0
|
92
|
+
for item_key in items.keys
|
93
|
+
encoded_attributes["Item.#{item_index}.ItemName"] = item_key.to_s
|
94
|
+
for attribute_key in items[item_key].keys
|
95
|
+
attribute_index = 0
|
96
|
+
for value in Array(items[item_key][attribute_key])
|
97
|
+
encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Name"] = attribute_key.to_s
|
98
|
+
if replace_attributes[item_key].include?(attribute_key)
|
99
|
+
encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Replace"] = 'true'
|
100
|
+
end
|
101
|
+
encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Value"] = sdb_encode(value)
|
102
|
+
attribute_index += 1
|
103
103
|
end
|
104
|
-
|
105
|
-
attribute_index += 1
|
104
|
+
item_index += 1
|
106
105
|
end
|
107
|
-
item_index += 1
|
108
106
|
end
|
109
107
|
end
|
108
|
+
encoded_attributes
|
110
109
|
end
|
111
|
-
encoded_attributes
|
112
|
-
end
|
113
110
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
111
|
+
def request(params)
|
112
|
+
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
113
|
+
idempotent = params.delete(:idempotent)
|
114
|
+
parser = params.delete(:parser)
|
115
|
+
|
116
|
+
params.merge!({
|
117
|
+
'AWSAccessKeyId' => @aws_access_key_id,
|
118
|
+
'SignatureMethod' => 'HmacSHA256',
|
119
|
+
'SignatureVersion' => '2',
|
120
|
+
'Timestamp' => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
|
121
|
+
'Version' => '2007-11-07'
|
122
|
+
})
|
123
|
+
|
124
|
+
body = ''
|
125
|
+
for key in params.keys.sort
|
126
|
+
unless (value = params[key]).nil?
|
127
|
+
body << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&"
|
128
|
+
end
|
128
129
|
end
|
129
|
-
end
|
130
|
-
|
131
|
-
string_to_sign = "POST\n#{@host}\n/\n" << body.chop
|
132
|
-
hmac = @hmac.update(string_to_sign)
|
133
|
-
body << "Signature=#{CGI.escape(Base64.encode64(hmac.digest).chomp!).gsub(/\+/, '%20')}"
|
134
|
-
|
135
|
-
response = @connection.request({
|
136
|
-
:body => body,
|
137
|
-
:expects => 200,
|
138
|
-
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
139
|
-
:host => @host,
|
140
|
-
:method => 'POST',
|
141
|
-
:parser => parser
|
142
|
-
})
|
143
130
|
|
144
|
-
|
145
|
-
|
131
|
+
string_to_sign = "POST\n#{@host}\n/\n" << body.chop
|
132
|
+
hmac = @hmac.update(string_to_sign)
|
133
|
+
body << "Signature=#{CGI.escape(Base64.encode64(hmac.digest).chomp!).gsub(/\+/, '%20')}"
|
134
|
+
|
135
|
+
response = @connection.request({
|
136
|
+
:body => body,
|
137
|
+
:expects => 200,
|
138
|
+
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
139
|
+
:host => @host,
|
140
|
+
:idempotent => idempotent,
|
141
|
+
:method => 'POST',
|
142
|
+
:parser => parser
|
143
|
+
})
|
144
|
+
|
145
|
+
response
|
146
|
+
end
|
146
147
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
148
|
+
def sdb_encode(value)
|
149
|
+
if value.nil?
|
150
|
+
@nil_string
|
151
|
+
else
|
152
|
+
value.to_s
|
153
|
+
end
|
152
154
|
end
|
153
|
-
end
|
154
155
|
|
156
|
+
end
|
155
157
|
end
|
156
158
|
end
|
157
159
|
end
|
158
|
-
|
159
|
-
Fog::AWS::SimpleDB.reload
|