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,79 @@
|
|
|
1
|
+
unless Fog.mocking?
|
|
2
|
+
|
|
3
|
+
module Fog
|
|
4
|
+
module AWS
|
|
5
|
+
class S3
|
|
6
|
+
|
|
7
|
+
# Copy an object from one S3 bucket to another
|
|
8
|
+
#
|
|
9
|
+
# ==== Parameters
|
|
10
|
+
# * source_bucket_name<~String> - Name of source bucket
|
|
11
|
+
# * source_object_name<~String> - Name of source object
|
|
12
|
+
# * target_bucket_name<~String> - Name of bucket to create copy in
|
|
13
|
+
# * target_object_name<~String> - Name for new copy of object
|
|
14
|
+
# * options<~Hash>:
|
|
15
|
+
# * 'x-amz-metadata-directive'<~String> - Specifies whether to copy metadata from source or replace with data in request. Must be in ['COPY', 'REPLACE']
|
|
16
|
+
# * 'x-amz-copy_source-if-match'<~String> - Copies object if its etag matches this value
|
|
17
|
+
# * 'x-amz-copy_source-if-modified_since'<~Time> - Copies object it it has been modified since this time
|
|
18
|
+
# * 'x-amz-copy_source-if-none-match'<~String> - Copies object if its etag does not match this value
|
|
19
|
+
# * 'x-amz-copy_source-if-unmodified-since'<~Time> - Copies object it it has not been modified since this time
|
|
20
|
+
#
|
|
21
|
+
# ==== Returns
|
|
22
|
+
# * response<~Fog::AWS::Response>:
|
|
23
|
+
# * body<~Hash>:
|
|
24
|
+
# * 'ETag'<~String> - etag of new object
|
|
25
|
+
# * 'LastModified'<~Time> - date object was last modified
|
|
26
|
+
#
|
|
27
|
+
# TODO: allow specifying new metadata (support all/some of put_object?)
|
|
28
|
+
def copy_object(source_bucket_name, source_object_name, target_bucket_name, target_object_name, options = {})
|
|
29
|
+
headers = { 'x-amz-copy-source' => "/#{source_bucket_name}/#{source_object_name}" }.merge!(options)
|
|
30
|
+
request({
|
|
31
|
+
:expects => 200,
|
|
32
|
+
:headers => headers,
|
|
33
|
+
:host => "#{target_bucket_name}.#{@host}",
|
|
34
|
+
:method => 'PUT',
|
|
35
|
+
:parser => Fog::Parsers::AWS::S3::CopyObject.new,
|
|
36
|
+
:path => target_object_name
|
|
37
|
+
})
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
else
|
|
45
|
+
|
|
46
|
+
module Fog
|
|
47
|
+
module AWS
|
|
48
|
+
class S3
|
|
49
|
+
|
|
50
|
+
def copy_object(source_bucket_name, source_object_name, target_bucket_name, target_object_name, options = {})
|
|
51
|
+
response = Fog::Response.new
|
|
52
|
+
source_bucket = Fog::AWS::S3.data[:buckets][source_bucket_name]
|
|
53
|
+
source_object = source_bucket && source_bucket[:objects][source_object_name]
|
|
54
|
+
target_bucket = Fog::AWS::S3.data[:buckets][target_bucket_name]
|
|
55
|
+
|
|
56
|
+
if source_object && target_bucket
|
|
57
|
+
response.status = 200
|
|
58
|
+
target_object = source_object.dup
|
|
59
|
+
target_object.merge!({
|
|
60
|
+
'Name' => target_object_name
|
|
61
|
+
})
|
|
62
|
+
target_bucket[:objects][target_object_name] = target_object
|
|
63
|
+
response.body = {
|
|
64
|
+
'ETag' => target_object['ETag'],
|
|
65
|
+
'LastModified' => Time.parse(target_object['LastModified'])
|
|
66
|
+
}
|
|
67
|
+
else
|
|
68
|
+
response.status = 404
|
|
69
|
+
raise(Fog::Errors.status_error(200, 404, response))
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
response
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
unless Fog.mocking?
|
|
2
|
+
|
|
3
|
+
module Fog
|
|
4
|
+
module AWS
|
|
5
|
+
class S3
|
|
6
|
+
|
|
7
|
+
# Delete an S3 bucket
|
|
8
|
+
#
|
|
9
|
+
# ==== Parameters
|
|
10
|
+
# * bucket_name<~String> - name of bucket to delete
|
|
11
|
+
#
|
|
12
|
+
# ==== Returns
|
|
13
|
+
# * response<~Fog::AWS::Response>:
|
|
14
|
+
# * status<~Integer> - 204
|
|
15
|
+
def delete_bucket(bucket_name)
|
|
16
|
+
request({
|
|
17
|
+
:expects => 204,
|
|
18
|
+
:headers => {},
|
|
19
|
+
:host => "#{bucket_name}.#{@host}",
|
|
20
|
+
:method => 'DELETE'
|
|
21
|
+
})
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
else
|
|
29
|
+
|
|
30
|
+
module Fog
|
|
31
|
+
module AWS
|
|
32
|
+
class S3
|
|
33
|
+
|
|
34
|
+
def delete_bucket(bucket_name)
|
|
35
|
+
response = Fog::Response.new
|
|
36
|
+
if Fog::AWS::S3.data[:buckets][bucket_name].nil?
|
|
37
|
+
response.status = 404
|
|
38
|
+
raise(Fog::Errors.status_error(204, 404, response))
|
|
39
|
+
elsif Fog::AWS::S3.data[:buckets][bucket_name] && !Fog::AWS::S3.data[:buckets][bucket_name][:objects].empty?
|
|
40
|
+
response.status = 409
|
|
41
|
+
raise(Fog::Errors.status_error(204, 409, response))
|
|
42
|
+
else
|
|
43
|
+
Fog::AWS::S3.data[:buckets].delete(bucket_name)
|
|
44
|
+
response.status = 204
|
|
45
|
+
end
|
|
46
|
+
response
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
unless Fog.mocking?
|
|
2
|
+
|
|
3
|
+
module Fog
|
|
4
|
+
module AWS
|
|
5
|
+
class S3
|
|
6
|
+
|
|
7
|
+
# Delete an object from S3
|
|
8
|
+
#
|
|
9
|
+
# ==== Parameters
|
|
10
|
+
# * bucket_name<~String> - Name of bucket containing object to delete
|
|
11
|
+
# * object_name<~String> - Name of object to delete
|
|
12
|
+
#
|
|
13
|
+
# ==== Returns
|
|
14
|
+
# * response<~Fog::AWS::Response>:
|
|
15
|
+
# * status<~Integer> - 204
|
|
16
|
+
def delete_object(bucket_name, object_name)
|
|
17
|
+
request({
|
|
18
|
+
:expects => 204,
|
|
19
|
+
:headers => {},
|
|
20
|
+
:host => "#{bucket_name}.#{@host}",
|
|
21
|
+
:method => 'DELETE',
|
|
22
|
+
:path => object_name
|
|
23
|
+
})
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
else
|
|
31
|
+
|
|
32
|
+
module Fog
|
|
33
|
+
module AWS
|
|
34
|
+
class S3
|
|
35
|
+
|
|
36
|
+
def delete_object(bucket_name, object_name)
|
|
37
|
+
response = Fog::Response.new
|
|
38
|
+
if bucket = Fog::AWS::S3.data[:buckets][bucket_name]
|
|
39
|
+
response.status = 204
|
|
40
|
+
bucket[:objects].delete(object_name)
|
|
41
|
+
else
|
|
42
|
+
response.status = 404
|
|
43
|
+
raise(Fog::Errors.status_error(204, 404, response))
|
|
44
|
+
end
|
|
45
|
+
response
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
unless Fog.mocking?
|
|
2
|
+
|
|
3
|
+
module Fog
|
|
4
|
+
module AWS
|
|
5
|
+
class S3
|
|
6
|
+
|
|
7
|
+
# List information about objects in an S3 bucket
|
|
8
|
+
#
|
|
9
|
+
# ==== Parameters
|
|
10
|
+
# * bucket_name<~String> - name of bucket to list object keys from
|
|
11
|
+
# * options<~Hash> - config arguments for list. Defaults to {}.
|
|
12
|
+
# * 'prefix'<~String> - limits object keys to those beginning with its value.
|
|
13
|
+
# * 'marker'<~String> - limits object keys to only those that appear
|
|
14
|
+
# lexicographically after its value.
|
|
15
|
+
# * 'max-keys'<~Integer> - limits number of object keys returned
|
|
16
|
+
# * 'delimiter'<~String> - causes keys with the same string between the prefix
|
|
17
|
+
# value and the first occurence of delimiter to be rolled up
|
|
18
|
+
#
|
|
19
|
+
# ==== Returns
|
|
20
|
+
# * response<~Fog::AWS::Response>:
|
|
21
|
+
# * body<~Hash>:
|
|
22
|
+
# * 'Delimeter'<~String> - Delimiter specified for query
|
|
23
|
+
# * 'Marker'<~String> - Marker specified for query
|
|
24
|
+
# * 'MaxKeys'<~Integer> - Maximum number of keys specified for query
|
|
25
|
+
# * 'Name'<~String> - Name of the bucket
|
|
26
|
+
# * 'Prefix'<~String> - Prefix specified for query
|
|
27
|
+
# * 'Contents'<~Array>:
|
|
28
|
+
# * 'ETag'<~String>: Etag of object
|
|
29
|
+
# * 'Key'<~String>: Name of object
|
|
30
|
+
# * 'LastModified'<~String>: Timestamp of last modification of object
|
|
31
|
+
# * 'Owner'<~Hash>:
|
|
32
|
+
# * 'DisplayName'<~String> - Display name of object owner
|
|
33
|
+
# * 'ID'<~String> - Id of object owner
|
|
34
|
+
# * 'Size'<~Integer> - Size of object
|
|
35
|
+
# * 'StorageClass'<~String> - Storage class of object
|
|
36
|
+
def get_bucket(bucket_name, options = {})
|
|
37
|
+
query = ''
|
|
38
|
+
for key, value in options
|
|
39
|
+
query << "#{key}=#{value};"
|
|
40
|
+
end
|
|
41
|
+
query.chop!
|
|
42
|
+
request({
|
|
43
|
+
:expects => 200,
|
|
44
|
+
:headers => {},
|
|
45
|
+
:host => "#{bucket_name}.#{@host}",
|
|
46
|
+
:method => 'GET',
|
|
47
|
+
:parser => Fog::Parsers::AWS::S3::GetBucket.new,
|
|
48
|
+
:query => query
|
|
49
|
+
})
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
else
|
|
57
|
+
|
|
58
|
+
module Fog
|
|
59
|
+
module AWS
|
|
60
|
+
class S3
|
|
61
|
+
|
|
62
|
+
# FIXME: implement delimiter
|
|
63
|
+
def get_bucket(bucket_name, options = {})
|
|
64
|
+
response = Fog::Response.new
|
|
65
|
+
if bucket = Fog::AWS::S3.data[:buckets][bucket_name]
|
|
66
|
+
response.status = 200
|
|
67
|
+
response.body = {
|
|
68
|
+
'Contents' => bucket[:objects].values.sort {|x,y| x['Key'] <=> y['Key']}.reject do |object|
|
|
69
|
+
(options['prefix'] && object['Key'][0...options['prefix'].length] != options['prefix']) ||
|
|
70
|
+
(options['marker'] && object['Key'] <= options['marker'])
|
|
71
|
+
end.map do |object|
|
|
72
|
+
data = object.reject {|key, value| !['ETag', 'Key', 'LastModified', 'Owner', 'Size', 'StorageClass'].include?(key)}
|
|
73
|
+
data.merge!({
|
|
74
|
+
'LastModified' => Time.parse(data['LastModified']),
|
|
75
|
+
'Size' => data['Size'].to_i
|
|
76
|
+
})
|
|
77
|
+
data
|
|
78
|
+
end,
|
|
79
|
+
'IsTruncated' => false,
|
|
80
|
+
'Marker' => options['marker'] || '',
|
|
81
|
+
'MaxKeys' => options['max-keys'] || 1000,
|
|
82
|
+
'Name' => bucket['Name'],
|
|
83
|
+
'Prefix' => options['prefix'] || ''
|
|
84
|
+
}
|
|
85
|
+
if options['max-keys'] && options['max-keys'] < response.body['Contents'].length
|
|
86
|
+
response.body['IsTruncated'] = true
|
|
87
|
+
response.body['Contents'] = response.body['Contents'][0...options['max-keys']]
|
|
88
|
+
end
|
|
89
|
+
else
|
|
90
|
+
response.status = 404
|
|
91
|
+
raise(Fog::Errors.status_error(200, 404, response))
|
|
92
|
+
end
|
|
93
|
+
response
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
unless Fog.mocking?
|
|
2
|
+
|
|
3
|
+
module Fog
|
|
4
|
+
module AWS
|
|
5
|
+
class S3
|
|
6
|
+
|
|
7
|
+
# Get location constraint for an S3 bucket
|
|
8
|
+
#
|
|
9
|
+
# ==== Parameters
|
|
10
|
+
# * bucket_name<~String> - name of bucket to get location constraint for
|
|
11
|
+
#
|
|
12
|
+
# ==== Returns
|
|
13
|
+
# * response<~Fog::AWS::Response>:
|
|
14
|
+
# * body<~Hash>:
|
|
15
|
+
# * 'LocationConstraint'<~String> - Location constraint of the bucket
|
|
16
|
+
def get_bucket_location(bucket_name)
|
|
17
|
+
request({
|
|
18
|
+
:expects => 200,
|
|
19
|
+
:headers => {},
|
|
20
|
+
:host => "#{bucket_name}.#{@host}",
|
|
21
|
+
:method => 'GET',
|
|
22
|
+
:parser => Fog::Parsers::AWS::S3::GetBucketLocation.new,
|
|
23
|
+
:query => 'location'
|
|
24
|
+
})
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
else
|
|
32
|
+
|
|
33
|
+
module Fog
|
|
34
|
+
module AWS
|
|
35
|
+
class S3
|
|
36
|
+
|
|
37
|
+
def get_bucket_location(bucket_name)
|
|
38
|
+
response = Fog::Response.new
|
|
39
|
+
if bucket = Fog::AWS::S3.data[:buckets][bucket_name]
|
|
40
|
+
response.status = 200
|
|
41
|
+
response.body = {'LocationConstraint' => bucket['LocationConstraint'] }
|
|
42
|
+
else
|
|
43
|
+
response.status = 404
|
|
44
|
+
raise(Fog::Errors.status_error(200, 404, response))
|
|
45
|
+
end
|
|
46
|
+
response
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
unless Fog.mocking?
|
|
2
|
+
|
|
3
|
+
module Fog
|
|
4
|
+
module AWS
|
|
5
|
+
class S3
|
|
6
|
+
|
|
7
|
+
# Get an object from S3
|
|
8
|
+
#
|
|
9
|
+
# ==== Parameters
|
|
10
|
+
# * bucket_name<~String> - Name of bucket to read from
|
|
11
|
+
# * object_name<~String> - Name of object to read
|
|
12
|
+
# * options<~Hash>:
|
|
13
|
+
# * 'If-Match'<~String> - Returns object only if its etag matches this value, otherwise returns 412 (Precondition Failed).
|
|
14
|
+
# * 'If-Modified-Since'<~Time> - Returns object only if it has been modified since this time, otherwise returns 304 (Not Modified).
|
|
15
|
+
# * 'If-None-Match'<~String> - Returns object only if its etag differs from this value, otherwise returns 304 (Not Modified)
|
|
16
|
+
# * 'If-Unmodified-Since'<~Time> - Returns object only if it has not been modified since this time, otherwise returns 412 (Precodition Failed).
|
|
17
|
+
# * 'Range'<~String> - Range of object to download
|
|
18
|
+
# ==== Returns
|
|
19
|
+
# * response<~Fog::AWS::Response>:
|
|
20
|
+
# * body<~String> - Contents of object
|
|
21
|
+
# * headers<~Hash>:
|
|
22
|
+
# * 'Content-Length'<~String> - Size of object contents
|
|
23
|
+
# * 'Content-Type'<~String> - MIME type of object
|
|
24
|
+
# * 'ETag'<~String> - Etag of object
|
|
25
|
+
# * 'Last-Modified'<~String> - Last modified timestamp for object
|
|
26
|
+
def get_object(bucket_name, object_name, options = {})
|
|
27
|
+
headers = {}
|
|
28
|
+
headers['If-Modified-Since'] = options['If-Modified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
|
|
29
|
+
headers['If-Unmodified-Since'] = options['If-Unmodified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
|
|
30
|
+
headers.merge!(options)
|
|
31
|
+
request({
|
|
32
|
+
:expects => 200,
|
|
33
|
+
:headers => headers,
|
|
34
|
+
:host => "#{bucket_name}.#{@host}",
|
|
35
|
+
:method => 'GET',
|
|
36
|
+
:path => object_name
|
|
37
|
+
})
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
else
|
|
45
|
+
|
|
46
|
+
module Fog
|
|
47
|
+
module AWS
|
|
48
|
+
class S3
|
|
49
|
+
|
|
50
|
+
def get_object(bucket_name, object_name, options = {})
|
|
51
|
+
response = Fog::Response.new
|
|
52
|
+
if (bucket = Fog::AWS::S3.data[:buckets][bucket_name]) && (object = bucket[:objects][object_name])
|
|
53
|
+
if options['If-Match'] && options['If-Match'] != object['ETag']
|
|
54
|
+
response.status = 412
|
|
55
|
+
elsif options['If-Modified-Since'] && options['If-Modified-Since'] > Time.parse(object['LastModified'])
|
|
56
|
+
response.status = 304
|
|
57
|
+
elsif options['If-None-Match'] && options['If-None-Match'] == object['ETag']
|
|
58
|
+
response.status = 304
|
|
59
|
+
elsif options['If-Unmodified-Since'] && options['If-Unmodified-Since'] < Time.parse(object['LastModified'])
|
|
60
|
+
response.status = 412
|
|
61
|
+
else
|
|
62
|
+
response.status = 200
|
|
63
|
+
response.headers = {
|
|
64
|
+
'Content-Length' => object['Size'],
|
|
65
|
+
'Content-Type' => object['Content-Type'],
|
|
66
|
+
'ETag' => object['ETag'],
|
|
67
|
+
'Last-Modified' => object['LastModified']
|
|
68
|
+
}
|
|
69
|
+
response.body = object[:body]
|
|
70
|
+
end
|
|
71
|
+
else
|
|
72
|
+
response.status = 404
|
|
73
|
+
raise(Fog::Errors.status_error(200, 404, response))
|
|
74
|
+
end
|
|
75
|
+
response
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
unless Fog.mocking?
|
|
2
|
+
|
|
3
|
+
module Fog
|
|
4
|
+
module AWS
|
|
5
|
+
class S3
|
|
6
|
+
|
|
7
|
+
# Get configured payer for an S3 bucket
|
|
8
|
+
#
|
|
9
|
+
# ==== Parameters
|
|
10
|
+
# * bucket_name<~String> - name of bucket to get payer for
|
|
11
|
+
#
|
|
12
|
+
# ==== Returns
|
|
13
|
+
# * response<~Fog::AWS::Response>:
|
|
14
|
+
# * body<~Hash>:
|
|
15
|
+
# * 'Payer'<~String> - Specifies who pays for download and requests
|
|
16
|
+
def get_request_payment(bucket_name)
|
|
17
|
+
request({
|
|
18
|
+
:expects => 200,
|
|
19
|
+
:headers => {},
|
|
20
|
+
:host => "#{bucket_name}.#{@host}",
|
|
21
|
+
:method => 'GET',
|
|
22
|
+
:parser => Fog::Parsers::AWS::S3::GetRequestPayment.new,
|
|
23
|
+
:query => 'requestPayment'
|
|
24
|
+
})
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
else
|
|
32
|
+
|
|
33
|
+
module Fog
|
|
34
|
+
module AWS
|
|
35
|
+
class S3
|
|
36
|
+
|
|
37
|
+
def get_request_payment(bucket_name)
|
|
38
|
+
response = Fog::Response.new
|
|
39
|
+
if bucket = Fog::AWS::S3.data[:buckets][bucket_name]
|
|
40
|
+
response.status = 200
|
|
41
|
+
response.body = { 'Payer' => bucket['Payer'] }
|
|
42
|
+
else
|
|
43
|
+
response.status = 404
|
|
44
|
+
raise(Fog::Errors.status_error(200, 404, response))
|
|
45
|
+
end
|
|
46
|
+
response
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|