fog 0.0.3
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/.document +5 -0
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +98 -0
- data/VERSION +1 -0
- data/benchs/fog_vs.rb +135 -0
- data/benchs/headers_split_vs_match.rb +18 -0
- data/benchs/params.rb +43 -0
- data/benchs/parse_vs_push.rb +60 -0
- data/benchs/stripping.rb +26 -0
- data/lib/fog.rb +21 -0
- data/lib/fog/aws.rb +145 -0
- data/lib/fog/aws/ec2.rb +173 -0
- data/lib/fog/aws/models/ec2/address.rb +31 -0
- data/lib/fog/aws/models/ec2/addresses.rb +36 -0
- data/lib/fog/aws/models/ec2/key_pair.rb +35 -0
- data/lib/fog/aws/models/ec2/key_pairs.rb +36 -0
- data/lib/fog/aws/models/ec2/volume.rb +47 -0
- data/lib/fog/aws/models/ec2/volumes.rb +36 -0
- data/lib/fog/aws/models/s3/bucket.rb +77 -0
- data/lib/fog/aws/models/s3/buckets.rb +83 -0
- data/lib/fog/aws/models/s3/object.rb +76 -0
- data/lib/fog/aws/models/s3/objects.rb +97 -0
- data/lib/fog/aws/models/s3/owner.rb +18 -0
- data/lib/fog/aws/parsers/ec2/allocate_address.rb +19 -0
- data/lib/fog/aws/parsers/ec2/attach_volume.rb +22 -0
- data/lib/fog/aws/parsers/ec2/basic.rb +25 -0
- data/lib/fog/aws/parsers/ec2/create_key_pair.rb +20 -0
- data/lib/fog/aws/parsers/ec2/create_snapshot.rb +22 -0
- data/lib/fog/aws/parsers/ec2/create_volume.rb +24 -0
- data/lib/fog/aws/parsers/ec2/describe_addresses.rb +30 -0
- data/lib/fog/aws/parsers/ec2/describe_availability_zones.rb +30 -0
- data/lib/fog/aws/parsers/ec2/describe_images.rb +49 -0
- data/lib/fog/aws/parsers/ec2/describe_instances.rb +73 -0
- data/lib/fog/aws/parsers/ec2/describe_key_pairs.rb +30 -0
- data/lib/fog/aws/parsers/ec2/describe_regions.rb +30 -0
- data/lib/fog/aws/parsers/ec2/describe_security_groups.rb +75 -0
- data/lib/fog/aws/parsers/ec2/describe_snapshots.rb +30 -0
- data/lib/fog/aws/parsers/ec2/describe_volumes.rb +57 -0
- data/lib/fog/aws/parsers/ec2/detach_volume.rb +22 -0
- data/lib/fog/aws/parsers/ec2/get_console_output.rb +28 -0
- data/lib/fog/aws/parsers/ec2/run_instances.rb +65 -0
- data/lib/fog/aws/parsers/ec2/terminate_instances.rb +55 -0
- data/lib/fog/aws/parsers/s3/copy_object.rb +22 -0
- data/lib/fog/aws/parsers/s3/get_bucket.rb +46 -0
- data/lib/fog/aws/parsers/s3/get_bucket_location.rb +20 -0
- data/lib/fog/aws/parsers/s3/get_request_payment.rb +20 -0
- data/lib/fog/aws/parsers/s3/get_service.rb +32 -0
- data/lib/fog/aws/parsers/simpledb/basic.rb +31 -0
- data/lib/fog/aws/parsers/simpledb/domain_metadata.rb +30 -0
- data/lib/fog/aws/parsers/simpledb/get_attributes.rb +34 -0
- data/lib/fog/aws/parsers/simpledb/list_domains.rb +28 -0
- data/lib/fog/aws/parsers/simpledb/select.rb +39 -0
- data/lib/fog/aws/requests/ec2/allocate_address.rb +50 -0
- data/lib/fog/aws/requests/ec2/associate_address.rb +59 -0
- data/lib/fog/aws/requests/ec2/attach_volume.rb +71 -0
- data/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +32 -0
- data/lib/fog/aws/requests/ec2/create_key_pair.rb +60 -0
- data/lib/fog/aws/requests/ec2/create_security_group.rb +61 -0
- data/lib/fog/aws/requests/ec2/create_snapshot.rb +65 -0
- data/lib/fog/aws/requests/ec2/create_volume.rb +66 -0
- data/lib/fog/aws/requests/ec2/delete_key_pair.rb +49 -0
- data/lib/fog/aws/requests/ec2/delete_security_group.rb +52 -0
- data/lib/fog/aws/requests/ec2/delete_snapshot.rb +53 -0
- data/lib/fog/aws/requests/ec2/delete_volume.rb +55 -0
- data/lib/fog/aws/requests/ec2/describe_addresses.rb +61 -0
- data/lib/fog/aws/requests/ec2/describe_availability_zones.rb +64 -0
- data/lib/fog/aws/requests/ec2/describe_images.rb +41 -0
- data/lib/fog/aws/requests/ec2/describe_instances.rb +114 -0
- data/lib/fog/aws/requests/ec2/describe_key_pairs.rb +63 -0
- data/lib/fog/aws/requests/ec2/describe_regions.rb +61 -0
- data/lib/fog/aws/requests/ec2/describe_security_groups.rb +71 -0
- data/lib/fog/aws/requests/ec2/describe_snapshots.rb +78 -0
- data/lib/fog/aws/requests/ec2/describe_volumes.rb +85 -0
- data/lib/fog/aws/requests/ec2/detach_volume.rb +62 -0
- data/lib/fog/aws/requests/ec2/disassociate_address.rb +55 -0
- data/lib/fog/aws/requests/ec2/get_console_output.rb +26 -0
- data/lib/fog/aws/requests/ec2/reboot_instances.rb +24 -0
- data/lib/fog/aws/requests/ec2/release_address.rb +50 -0
- data/lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb +32 -0
- data/lib/fog/aws/requests/ec2/run_instances.rb +134 -0
- data/lib/fog/aws/requests/ec2/terminate_instances.rb +80 -0
- data/lib/fog/aws/requests/s3/copy_object.rb +79 -0
- data/lib/fog/aws/requests/s3/delete_bucket.rb +53 -0
- data/lib/fog/aws/requests/s3/delete_object.rb +52 -0
- data/lib/fog/aws/requests/s3/get_bucket.rb +100 -0
- data/lib/fog/aws/requests/s3/get_bucket_location.rb +53 -0
- data/lib/fog/aws/requests/s3/get_object.rb +82 -0
- data/lib/fog/aws/requests/s3/get_request_payment.rb +53 -0
- data/lib/fog/aws/requests/s3/get_service.rb +58 -0
- data/lib/fog/aws/requests/s3/head_object.rb +61 -0
- data/lib/fog/aws/requests/s3/put_bucket.rb +69 -0
- data/lib/fog/aws/requests/s3/put_object.rb +76 -0
- data/lib/fog/aws/requests/s3/put_request_payment.rb +56 -0
- data/lib/fog/aws/requests/simpledb/batch_put_attributes.rb +31 -0
- data/lib/fog/aws/requests/simpledb/create_domain.rb +25 -0
- data/lib/fog/aws/requests/simpledb/delete_attributes.rb +34 -0
- data/lib/fog/aws/requests/simpledb/delete_domain.rb +25 -0
- data/lib/fog/aws/requests/simpledb/domain_metadata.rb +30 -0
- data/lib/fog/aws/requests/simpledb/get_attributes.rb +35 -0
- data/lib/fog/aws/requests/simpledb/list_domains.rb +30 -0
- data/lib/fog/aws/requests/simpledb/put_attributes.rb +29 -0
- data/lib/fog/aws/requests/simpledb/select.rb +29 -0
- data/lib/fog/aws/s3.rb +157 -0
- data/lib/fog/aws/simpledb.rb +157 -0
- data/lib/fog/collection.rb +77 -0
- data/lib/fog/connection.rb +130 -0
- data/lib/fog/errors.rb +145 -0
- data/lib/fog/model.rb +72 -0
- data/lib/fog/parser.rb +30 -0
- data/lib/fog/response.rb +12 -0
- data/spec/aws/models/s3/bucket_spec.rb +130 -0
- data/spec/aws/models/s3/buckets_spec.rb +79 -0
- data/spec/aws/models/s3/object_spec.rb +121 -0
- data/spec/aws/models/s3/objects_spec.rb +112 -0
- data/spec/aws/models/s3/owner_spec.rb +18 -0
- data/spec/aws/requests/ec2/allocate_address_spec.rb +18 -0
- data/spec/aws/requests/ec2/associate_address_spec.rb +42 -0
- data/spec/aws/requests/ec2/attach_volume_spec.rb +53 -0
- data/spec/aws/requests/ec2/authorize_security_group_ingress_spec.rb +26 -0
- data/spec/aws/requests/ec2/create_key_pair_spec.rb +36 -0
- data/spec/aws/requests/ec2/create_security_group_spec.rb +34 -0
- data/spec/aws/requests/ec2/create_snapshot_spec.rb +37 -0
- data/spec/aws/requests/ec2/create_volume_spec.rb +23 -0
- data/spec/aws/requests/ec2/delete_key_pair_spec.rb +21 -0
- data/spec/aws/requests/ec2/delete_security_group_spec.rb +26 -0
- data/spec/aws/requests/ec2/delete_snapshot_spec.rb +35 -0
- data/spec/aws/requests/ec2/delete_volume_spec.rb +26 -0
- data/spec/aws/requests/ec2/describe_addresses_spec.rb +38 -0
- data/spec/aws/requests/ec2/describe_availability_zones_spec.rb +23 -0
- data/spec/aws/requests/ec2/describe_images_spec.rb +39 -0
- data/spec/aws/requests/ec2/describe_instances_spec.rb +86 -0
- data/spec/aws/requests/ec2/describe_key_pairs_spec.rb +42 -0
- data/spec/aws/requests/ec2/describe_regions_spec.rb +21 -0
- data/spec/aws/requests/ec2/describe_security_groups_spec.rb +51 -0
- data/spec/aws/requests/ec2/describe_snapshots_spec.rb +54 -0
- data/spec/aws/requests/ec2/describe_volumes_spec.rb +50 -0
- data/spec/aws/requests/ec2/detach_volume_spec.rb +43 -0
- data/spec/aws/requests/ec2/disassociate_address_spec.rb +35 -0
- data/spec/aws/requests/ec2/get_console_output_spec.rb +23 -0
- data/spec/aws/requests/ec2/reboot_instances_spec.rb +21 -0
- data/spec/aws/requests/ec2/release_address_spec.rb +26 -0
- data/spec/aws/requests/ec2/revoke_security_group_ingress_spec.rb +32 -0
- data/spec/aws/requests/ec2/run_instances_spec.rb +41 -0
- data/spec/aws/requests/ec2/terminate_instances_spec.rb +35 -0
- data/spec/aws/requests/s3/copy_object_spec.rb +62 -0
- data/spec/aws/requests/s3/delete_bucket_spec.rb +36 -0
- data/spec/aws/requests/s3/delete_object_spec.rb +37 -0
- data/spec/aws/requests/s3/get_bucket_location_spec.rb +30 -0
- data/spec/aws/requests/s3/get_bucket_spec.rb +110 -0
- data/spec/aws/requests/s3/get_object_spec.rb +45 -0
- data/spec/aws/requests/s3/get_request_payment_spec.rb +30 -0
- data/spec/aws/requests/s3/get_service_spec.rb +33 -0
- data/spec/aws/requests/s3/head_object_spec.rb +28 -0
- data/spec/aws/requests/s3/put_bucket_spec.rb +19 -0
- data/spec/aws/requests/s3/put_object_spec.rb +38 -0
- data/spec/aws/requests/s3/put_request_payment_spec.rb +29 -0
- data/spec/aws/requests/simpledb/batch_put_attributes_spec.rb +22 -0
- data/spec/aws/requests/simpledb/create_domain_spec.rb +21 -0
- data/spec/aws/requests/simpledb/delete_attributes_spec.rb +22 -0
- data/spec/aws/requests/simpledb/delete_domain_spec.rb +21 -0
- data/spec/aws/requests/simpledb/domain_metadata_spec.rb +43 -0
- data/spec/aws/requests/simpledb/get_attributes_spec.rb +31 -0
- data/spec/aws/requests/simpledb/list_domains_spec.rb +30 -0
- data/spec/aws/requests/simpledb/put_attributes_spec.rb +22 -0
- data/spec/aws/requests/simpledb/select_spec.rb +9 -0
- data/spec/lorem.txt +1 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +66 -0
- metadata +309 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Fog
|
|
2
|
+
module AWS
|
|
3
|
+
class SimpleDB
|
|
4
|
+
|
|
5
|
+
# List metadata for SimpleDB domain
|
|
6
|
+
#
|
|
7
|
+
# ==== Parameters
|
|
8
|
+
# * domain_name<~String> - Name of domain. Must be between 3 and 255 of the
|
|
9
|
+
# following characters: a-z, A-Z, 0-9, '_', '-' and '.'.
|
|
10
|
+
# * item_name<~String> - Name of the item. May use any UTF-8 characters valid
|
|
11
|
+
# in xml. Control characters and sequences not allowed in xml are not
|
|
12
|
+
# valid. Can be up to 1024 bytes long.
|
|
13
|
+
# * attributes<~Hash> - Name/value pairs to return from the item. Defaults to
|
|
14
|
+
# nil, which will return all attributes. Attribute names and values may use
|
|
15
|
+
# any UTF-8 characters valid in xml. Control characters and sequences not
|
|
16
|
+
# allowed in xml are not valid. Each name and value can be up to 1024
|
|
17
|
+
# bytes long.
|
|
18
|
+
#
|
|
19
|
+
# ==== Returns
|
|
20
|
+
# * response<~Fog::AWS::Response>:
|
|
21
|
+
# * body<~Hash>:
|
|
22
|
+
# * 'Attributes' - list of attribute name/values for the item
|
|
23
|
+
# * 'BoxUsage'
|
|
24
|
+
# * 'RequestId'
|
|
25
|
+
def get_attributes(domain_name, item_name, attributes = nil)
|
|
26
|
+
request({
|
|
27
|
+
'Action' => 'GetAttributes',
|
|
28
|
+
'DomainName' => domain_name,
|
|
29
|
+
'ItemName' => item_name,
|
|
30
|
+
}.merge!(encode_attribute_names(attributes)), Fog::Parsers::AWS::SimpleDB::GetAttributes.new(@nil_string))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Fog
|
|
2
|
+
module AWS
|
|
3
|
+
class SimpleDB
|
|
4
|
+
|
|
5
|
+
# List SimpleDB domains
|
|
6
|
+
#
|
|
7
|
+
# ==== Parameters
|
|
8
|
+
# * options<~Hash> - options, defaults to {}
|
|
9
|
+
# * 'MaxNumberOfDomains'<~Integer> - number of domains to return
|
|
10
|
+
# between 1 and 100, defaults to 100
|
|
11
|
+
# * 'NextToken'<~String> - Offset token to start listing, defaults to nil
|
|
12
|
+
#
|
|
13
|
+
# ==== Returns
|
|
14
|
+
# * response<~Fog::AWS::Response>:
|
|
15
|
+
# * body<~Hash>:
|
|
16
|
+
# * 'BoxUsage'
|
|
17
|
+
# * 'Domains' - array of domain names.
|
|
18
|
+
# * 'NextToken' - offset to start with if there are are more domains to list
|
|
19
|
+
# * 'RequestId'
|
|
20
|
+
def list_domains(options = {})
|
|
21
|
+
request({
|
|
22
|
+
'Action' => 'ListDomains',
|
|
23
|
+
'MaxNumberOfDomains' => options['MaxNumberOfDomains'],
|
|
24
|
+
'NextToken' => options['NextToken']
|
|
25
|
+
}, Fog::Parsers::AWS::SimpleDB::ListDomains.new(@nil_string))
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Fog
|
|
2
|
+
module AWS
|
|
3
|
+
class SimpleDB
|
|
4
|
+
|
|
5
|
+
# Put item attributes into a SimpleDB domain
|
|
6
|
+
#
|
|
7
|
+
# ==== Parameters
|
|
8
|
+
# * domain_name<~String> - Name of domain. Must be between 3 and 255 of the
|
|
9
|
+
# following characters: a-z, A-Z, 0-9, '_', '-' and '.'.
|
|
10
|
+
# * item_name<~String> - Name of the item. May use any UTF-8 characters valid
|
|
11
|
+
# in xml. Control characters and sequences not allowed in xml are not
|
|
12
|
+
# valid. Can be up to 1024 bytes long.
|
|
13
|
+
# * attributes<~Hash> - Name/value pairs to add to the item. Attribute names
|
|
14
|
+
# and values may use any UTF-8 characters valid in xml. Control characters
|
|
15
|
+
# and sequences not allowed in xml are not valid. Each name and value can
|
|
16
|
+
# be up to 1024 bytes long.
|
|
17
|
+
#
|
|
18
|
+
# ==== Returns
|
|
19
|
+
# * response<~Fog::AWS::Response>:
|
|
20
|
+
# * body<~Hash>:
|
|
21
|
+
# * 'BoxUsage'
|
|
22
|
+
# * 'RequestId'
|
|
23
|
+
def put_attributes(domain_name, item_name, attributes, replace_attributes = [])
|
|
24
|
+
batch_put_attributes(domain_name, { item_name => attributes }, { item_name => replace_attributes })
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Fog
|
|
2
|
+
module AWS
|
|
3
|
+
class SimpleDB
|
|
4
|
+
|
|
5
|
+
# Select item data from SimpleDB
|
|
6
|
+
#
|
|
7
|
+
# ==== Parameters
|
|
8
|
+
# * select_expression<~String> - Expression to query domain with.
|
|
9
|
+
# * next_token<~String> - Offset token to start list, defaults to nil.
|
|
10
|
+
#
|
|
11
|
+
# ==== Returns
|
|
12
|
+
# * response<~Fog::AWS::Response>:
|
|
13
|
+
# * body<~Hash>:
|
|
14
|
+
# * 'BoxUsage'<~Float>
|
|
15
|
+
# * 'RequestId'<~String>
|
|
16
|
+
# * 'Items'<~Hash> - list of attribute name/values for the items formatted as
|
|
17
|
+
# { 'item_name' => { 'attribute_name' => ['attribute_value'] }}
|
|
18
|
+
# * 'NextToken'<~String> - offset to start with if there are are more domains to list
|
|
19
|
+
def select(select_expression, next_token = nil)
|
|
20
|
+
request({
|
|
21
|
+
'Action' => 'Select',
|
|
22
|
+
'NextToken' => next_token,
|
|
23
|
+
'SelectExpression' => select_expression
|
|
24
|
+
}, Fog::Parsers::AWS::SimpleDB::Select.new(@nil_string))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/fog/aws/s3.rb
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
module Fog
|
|
2
|
+
module AWS
|
|
3
|
+
class S3
|
|
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.reload
|
|
15
|
+
current_directory = File.dirname(__FILE__)
|
|
16
|
+
load "#{current_directory}/../collection.rb"
|
|
17
|
+
load "#{current_directory}/../connection.rb"
|
|
18
|
+
load "#{current_directory}/../model.rb"
|
|
19
|
+
load "#{current_directory}/../parser.rb"
|
|
20
|
+
load "#{current_directory}/../response.rb"
|
|
21
|
+
|
|
22
|
+
models_directory = "#{current_directory}/models/s3"
|
|
23
|
+
load "#{models_directory}/bucket.rb"
|
|
24
|
+
load "#{models_directory}/buckets.rb"
|
|
25
|
+
load "#{models_directory}/object.rb"
|
|
26
|
+
load "#{models_directory}/objects.rb"
|
|
27
|
+
load "#{models_directory}/owner.rb"
|
|
28
|
+
|
|
29
|
+
parsers_directory = "#{current_directory}/parsers/s3"
|
|
30
|
+
load "#{parsers_directory}/copy_object.rb"
|
|
31
|
+
load "#{parsers_directory}/get_bucket.rb"
|
|
32
|
+
load "#{parsers_directory}/get_bucket_location.rb"
|
|
33
|
+
load "#{parsers_directory}/get_request_payment.rb"
|
|
34
|
+
load "#{parsers_directory}/get_service.rb"
|
|
35
|
+
|
|
36
|
+
requests_directory = "#{current_directory}/requests/s3"
|
|
37
|
+
load "#{requests_directory}/copy_object.rb"
|
|
38
|
+
load "#{requests_directory}/delete_bucket.rb"
|
|
39
|
+
load "#{requests_directory}/delete_object.rb"
|
|
40
|
+
load "#{requests_directory}/get_bucket.rb"
|
|
41
|
+
load "#{requests_directory}/get_bucket_location.rb"
|
|
42
|
+
load "#{requests_directory}/get_object.rb"
|
|
43
|
+
load "#{requests_directory}/get_request_payment.rb"
|
|
44
|
+
load "#{requests_directory}/get_service.rb"
|
|
45
|
+
load "#{requests_directory}/head_object.rb"
|
|
46
|
+
load "#{requests_directory}/put_bucket.rb"
|
|
47
|
+
load "#{requests_directory}/put_object.rb"
|
|
48
|
+
load "#{requests_directory}/put_request_payment.rb"
|
|
49
|
+
|
|
50
|
+
if Fog.mocking?
|
|
51
|
+
reset_data
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Initialize connection to S3
|
|
56
|
+
#
|
|
57
|
+
# ==== Notes
|
|
58
|
+
# options parameter must include values for :aws_access_key_id and
|
|
59
|
+
# :aws_secret_access_key in order to create a connection
|
|
60
|
+
#
|
|
61
|
+
# ==== Examples
|
|
62
|
+
# sdb = S3.new(
|
|
63
|
+
# :aws_access_key_id => your_aws_access_key_id,
|
|
64
|
+
# :aws_secret_access_key => your_aws_secret_access_key
|
|
65
|
+
# )
|
|
66
|
+
#
|
|
67
|
+
# ==== Parameters
|
|
68
|
+
# * options<~Hash> - config arguments for connection. Defaults to {}.
|
|
69
|
+
#
|
|
70
|
+
# ==== Returns
|
|
71
|
+
# * S3 object with connection to aws.
|
|
72
|
+
def initialize(options={})
|
|
73
|
+
@aws_access_key_id = options[:aws_access_key_id]
|
|
74
|
+
@aws_secret_access_key = options[:aws_secret_access_key]
|
|
75
|
+
@hmac = HMAC::SHA1.new(@aws_secret_access_key)
|
|
76
|
+
@host = options[:host] || 's3.amazonaws.com'
|
|
77
|
+
@port = options[:port] || 443
|
|
78
|
+
@scheme = options[:scheme] || 'https'
|
|
79
|
+
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
private
|
|
83
|
+
|
|
84
|
+
def parse_file(file)
|
|
85
|
+
metadata = {
|
|
86
|
+
:body => nil,
|
|
87
|
+
:headers => {}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
filename = File.basename(file.path)
|
|
91
|
+
unless (mime_types = MIME::Types.of(filename)).empty?
|
|
92
|
+
metadata[:headers]['Content-Type'] = mime_types.first.content_type
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
metadata[:body] = file.read
|
|
96
|
+
metadata[:headers]['Content-Length'] = metadata[:body].size.to_s
|
|
97
|
+
metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
|
|
98
|
+
metadata
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def request(params)
|
|
102
|
+
params[:headers]['Date'] = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
|
|
103
|
+
|
|
104
|
+
string_to_sign =
|
|
105
|
+
<<-DATA
|
|
106
|
+
#{params[:method]}
|
|
107
|
+
#{params[:headers]['Content-MD5']}
|
|
108
|
+
#{params[:headers]['Content-Type']}
|
|
109
|
+
#{params[:headers]['Date']}
|
|
110
|
+
DATA
|
|
111
|
+
|
|
112
|
+
amz_headers, canonical_amz_headers = {}, ''
|
|
113
|
+
for key, value in params[:headers]
|
|
114
|
+
if key[0..5] == 'x-amz-'
|
|
115
|
+
amz_headers[key] = value
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
amz_headers = amz_headers.sort {|x, y| x[0] <=> y[0]}
|
|
119
|
+
for pair in amz_headers
|
|
120
|
+
canonical_amz_headers << "#{pair[0]}:#{pair[1]}\n"
|
|
121
|
+
end
|
|
122
|
+
string_to_sign << "#{canonical_amz_headers}"
|
|
123
|
+
|
|
124
|
+
canonical_resource = "/"
|
|
125
|
+
subdomain = params[:host].split(".#{@host}").first
|
|
126
|
+
unless subdomain == @host
|
|
127
|
+
canonical_resource << "#{subdomain}/"
|
|
128
|
+
end
|
|
129
|
+
canonical_resource << "#{params[:path]}"
|
|
130
|
+
if ['acl', 'location', 'logging', 'requestPayment', 'torrent'].include?(params[:query])
|
|
131
|
+
canonical_resource << "?#{params[:query]}"
|
|
132
|
+
end
|
|
133
|
+
string_to_sign << "#{canonical_resource}"
|
|
134
|
+
|
|
135
|
+
hmac = @hmac.update(string_to_sign)
|
|
136
|
+
signature = Base64.encode64(hmac.digest).chomp!
|
|
137
|
+
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature}"
|
|
138
|
+
|
|
139
|
+
response = @connection.request({
|
|
140
|
+
:body => params[:body],
|
|
141
|
+
:expects => params[:expects],
|
|
142
|
+
:headers => params[:headers],
|
|
143
|
+
:host => params[:host],
|
|
144
|
+
:method => params[:method],
|
|
145
|
+
:parser => params[:parser],
|
|
146
|
+
:path => params[:path],
|
|
147
|
+
:query => params[:query]
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
response
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
Fog::AWS::S3.reload
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
module Fog
|
|
2
|
+
module AWS
|
|
3
|
+
class SimpleDB
|
|
4
|
+
|
|
5
|
+
def self.reload
|
|
6
|
+
current_directory = File.dirname(__FILE__)
|
|
7
|
+
load "#{current_directory}/../connection.rb"
|
|
8
|
+
load "#{current_directory}/../parser.rb"
|
|
9
|
+
load "#{current_directory}/../response.rb"
|
|
10
|
+
|
|
11
|
+
parsers_directory = "#{current_directory}/parsers/simpledb"
|
|
12
|
+
load "#{parsers_directory}/basic.rb"
|
|
13
|
+
load "#{parsers_directory}/domain_metadata.rb"
|
|
14
|
+
load "#{parsers_directory}/get_attributes.rb"
|
|
15
|
+
load "#{parsers_directory}/list_domains.rb"
|
|
16
|
+
load "#{parsers_directory}/select.rb"
|
|
17
|
+
|
|
18
|
+
requests_directory = "#{current_directory}/requests/simpledb"
|
|
19
|
+
load "#{requests_directory}/batch_put_attributes.rb"
|
|
20
|
+
load "#{requests_directory}/create_domain.rb"
|
|
21
|
+
load "#{requests_directory}/delete_attributes.rb"
|
|
22
|
+
load "#{requests_directory}/delete_domain.rb"
|
|
23
|
+
load "#{requests_directory}/domain_metadata.rb"
|
|
24
|
+
load "#{requests_directory}/get_attributes.rb"
|
|
25
|
+
load "#{requests_directory}/list_domains.rb"
|
|
26
|
+
load "#{requests_directory}/put_attributes.rb"
|
|
27
|
+
load "#{requests_directory}/select.rb"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Initialize connection to SimpleDB
|
|
31
|
+
#
|
|
32
|
+
# ==== Notes
|
|
33
|
+
# options parameter must include values for :aws_access_key_id and
|
|
34
|
+
# :aws_secret_access_key in order to create a connection
|
|
35
|
+
#
|
|
36
|
+
# ==== Examples
|
|
37
|
+
# sdb = SimpleDB.new(
|
|
38
|
+
# :aws_access_key_id => your_aws_access_key_id,
|
|
39
|
+
# :aws_secret_access_key => your_aws_secret_access_key
|
|
40
|
+
# )
|
|
41
|
+
#
|
|
42
|
+
# ==== Parameters
|
|
43
|
+
# * options<~Hash> - config arguments for connection. Defaults to {}.
|
|
44
|
+
#
|
|
45
|
+
# ==== Returns
|
|
46
|
+
# * SimpleDB object with connection to aws.
|
|
47
|
+
def initialize(options={})
|
|
48
|
+
@aws_access_key_id = options[:aws_access_key_id]
|
|
49
|
+
@aws_secret_access_key = options[:aws_secret_access_key]
|
|
50
|
+
@hmac = HMAC::SHA256.new(@aws_secret_access_key)
|
|
51
|
+
@host = options[:host] || 'sdb.amazonaws.com'
|
|
52
|
+
@nil_string = options[:nil_string]|| 'nil'
|
|
53
|
+
@port = options[:port] || 443
|
|
54
|
+
@scheme = options[:scheme] || 'https'
|
|
55
|
+
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
def encode_attributes(attributes, replace_attributes = [])
|
|
61
|
+
encoded_attributes = {}
|
|
62
|
+
if attributes
|
|
63
|
+
index = 0
|
|
64
|
+
for key in attributes.keys
|
|
65
|
+
for value in Array(attributes[key])
|
|
66
|
+
encoded_attributes["Attribute.#{index}.Name"] = key.to_s
|
|
67
|
+
if replace_attributes.include?(key)
|
|
68
|
+
encoded_attributes["Attribute.#{index}.Replace"] = 'true'
|
|
69
|
+
end
|
|
70
|
+
encoded_attributes["Attribute.#{index}.Value"] = sdb_encode(value)
|
|
71
|
+
index += 1
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
encoded_attributes
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def encode_attribute_names(attributes)
|
|
79
|
+
encoded_attribute_names = {}
|
|
80
|
+
if attributes
|
|
81
|
+
index = 0
|
|
82
|
+
for attribute in attributes
|
|
83
|
+
encoded_attribute_names["AttributeName.#{index}"] = attribute.to_s
|
|
84
|
+
index += 1
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
encoded_attribute_names
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def encode_batch_attributes(items, replace_attributes = Hash.new([]))
|
|
91
|
+
encoded_attributes = {}
|
|
92
|
+
if items
|
|
93
|
+
item_index = 0
|
|
94
|
+
for item_key in items.keys
|
|
95
|
+
encoded_attributes["Item.#{item_index}.ItemName"] = item_key.to_s
|
|
96
|
+
for attribute_key in items[item_key].keys
|
|
97
|
+
attribute_index = 0
|
|
98
|
+
for value in Array(items[item_key][attribute_key])
|
|
99
|
+
encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Name"] = attribute_key.to_s
|
|
100
|
+
if replace_attributes[item_key].include?(attribute_key)
|
|
101
|
+
encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Replace"] = 'true'
|
|
102
|
+
end
|
|
103
|
+
encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Value"] = sdb_encode(value)
|
|
104
|
+
attribute_index += 1
|
|
105
|
+
end
|
|
106
|
+
item_index += 1
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
encoded_attributes
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def request(params, parser)
|
|
114
|
+
params.merge!({
|
|
115
|
+
'AWSAccessKeyId' => @aws_access_key_id,
|
|
116
|
+
'SignatureMethod' => 'HmacSHA256',
|
|
117
|
+
'SignatureVersion' => '2',
|
|
118
|
+
'Timestamp' => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
119
|
+
'Version' => '2007-11-07'
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
body = ''
|
|
123
|
+
for key in params.keys.sort
|
|
124
|
+
unless (value = params[key]).nil?
|
|
125
|
+
body << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&"
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
string_to_sign = "POST\n#{@host}\n/\n" << body.chop
|
|
130
|
+
hmac = @hmac.update(string_to_sign)
|
|
131
|
+
body << "Signature=#{CGI.escape(Base64.encode64(hmac.digest).chomp!).gsub(/\+/, '%20')}"
|
|
132
|
+
|
|
133
|
+
response = @connection.request({
|
|
134
|
+
:body => body,
|
|
135
|
+
:expects => 200,
|
|
136
|
+
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
|
137
|
+
:host => @host,
|
|
138
|
+
:method => 'POST',
|
|
139
|
+
:parser => parser
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
response
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def sdb_encode(value)
|
|
146
|
+
if value.nil?
|
|
147
|
+
@nil_string
|
|
148
|
+
else
|
|
149
|
+
value.to_s
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
Fog::AWS::SimpleDB.reload
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
module Fog
|
|
2
|
+
class Collection < Hash
|
|
3
|
+
|
|
4
|
+
def self.attribute(name, other_names = [])
|
|
5
|
+
class_eval <<-EOS, __FILE__, __LINE__
|
|
6
|
+
attr_accessor :#{name}
|
|
7
|
+
EOS
|
|
8
|
+
attributes << name
|
|
9
|
+
for other_name in [*other_names]
|
|
10
|
+
aliases[other_name] = name
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.aliases
|
|
15
|
+
@aliases ||= {}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.attributes
|
|
19
|
+
@attributes ||= []
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def initialize(attributes = {})
|
|
23
|
+
merge_attributes(attributes)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def inspect
|
|
27
|
+
data = "#<#{self.class.name}"
|
|
28
|
+
for attribute in self.class.attributes
|
|
29
|
+
data << " #{attribute}=#{send(attribute).inspect}"
|
|
30
|
+
end
|
|
31
|
+
data << " ["
|
|
32
|
+
for key, value in self
|
|
33
|
+
data << "#{value.inspect},"
|
|
34
|
+
end
|
|
35
|
+
data.chomp!
|
|
36
|
+
data << "]>"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def attributes
|
|
40
|
+
attributes = {}
|
|
41
|
+
for attribute in self.class.attributes
|
|
42
|
+
attributes[attribute] = send(:"#{attribute}")
|
|
43
|
+
end
|
|
44
|
+
attributes
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def merge_attributes(new_attributes = {})
|
|
48
|
+
for key, value in new_attributes
|
|
49
|
+
if aliased_key = self.class.aliases[key]
|
|
50
|
+
send(:"#{aliased_key}=", value)
|
|
51
|
+
else
|
|
52
|
+
send(:"#{key}=", value)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
self
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
def connection=(new_connection)
|
|
61
|
+
@connection = new_connection
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def connection
|
|
65
|
+
@connection
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def remap_attributes(attributes, mapping)
|
|
69
|
+
for key, value in mapping
|
|
70
|
+
if attributes.key?(key)
|
|
71
|
+
attributes[value] = attributes.delete(key)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
end
|