geemus-fog 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. data/.document +5 -0
  2. data/.gitignore +6 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +7 -0
  5. data/Rakefile +94 -0
  6. data/VERSION +1 -0
  7. data/benchs/fog_vs.rb +76 -0
  8. data/benchs/headers_split_vs_match.rb +18 -0
  9. data/benchs/params.rb +43 -0
  10. data/benchs/parse_vs_push.rb +60 -0
  11. data/benchs/stripping.rb +26 -0
  12. data/lib/fog/aws/ec2.rb +159 -0
  13. data/lib/fog/aws/parsers/ec2/allocate_address.rb +19 -0
  14. data/lib/fog/aws/parsers/ec2/attach_volume.rb +22 -0
  15. data/lib/fog/aws/parsers/ec2/basic.rb +25 -0
  16. data/lib/fog/aws/parsers/ec2/create_key_pair.rb +20 -0
  17. data/lib/fog/aws/parsers/ec2/create_snapshot.rb +22 -0
  18. data/lib/fog/aws/parsers/ec2/create_volume.rb +24 -0
  19. data/lib/fog/aws/parsers/ec2/describe_addresses.rb +30 -0
  20. data/lib/fog/aws/parsers/ec2/describe_availability_zones.rb +30 -0
  21. data/lib/fog/aws/parsers/ec2/describe_images.rb +49 -0
  22. data/lib/fog/aws/parsers/ec2/describe_instances.rb +73 -0
  23. data/lib/fog/aws/parsers/ec2/describe_key_pairs.rb +30 -0
  24. data/lib/fog/aws/parsers/ec2/describe_regions.rb +30 -0
  25. data/lib/fog/aws/parsers/ec2/describe_security_groups.rb +75 -0
  26. data/lib/fog/aws/parsers/ec2/describe_snapshots.rb +30 -0
  27. data/lib/fog/aws/parsers/ec2/describe_volumes.rb +57 -0
  28. data/lib/fog/aws/parsers/ec2/detach_volume.rb +22 -0
  29. data/lib/fog/aws/parsers/ec2/get_console_output.rb +28 -0
  30. data/lib/fog/aws/parsers/ec2/run_instances.rb +65 -0
  31. data/lib/fog/aws/parsers/ec2/terminate_instances.rb +55 -0
  32. data/lib/fog/aws/parsers/s3/copy_object.rb +22 -0
  33. data/lib/fog/aws/parsers/s3/get_bucket.rb +46 -0
  34. data/lib/fog/aws/parsers/s3/get_bucket_location.rb +20 -0
  35. data/lib/fog/aws/parsers/s3/get_request_payment.rb +20 -0
  36. data/lib/fog/aws/parsers/s3/get_service.rb +32 -0
  37. data/lib/fog/aws/parsers/simpledb/basic.rb +31 -0
  38. data/lib/fog/aws/parsers/simpledb/domain_metadata.rb +30 -0
  39. data/lib/fog/aws/parsers/simpledb/get_attributes.rb +34 -0
  40. data/lib/fog/aws/parsers/simpledb/list_domains.rb +28 -0
  41. data/lib/fog/aws/parsers/simpledb/select.rb +39 -0
  42. data/lib/fog/aws/requests/ec2/allocate_address.rb +50 -0
  43. data/lib/fog/aws/requests/ec2/associate_address.rb +26 -0
  44. data/lib/fog/aws/requests/ec2/attach_volume.rb +32 -0
  45. data/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +32 -0
  46. data/lib/fog/aws/requests/ec2/create_key_pair.rb +60 -0
  47. data/lib/fog/aws/requests/ec2/create_security_group.rb +61 -0
  48. data/lib/fog/aws/requests/ec2/create_snapshot.rb +28 -0
  49. data/lib/fog/aws/requests/ec2/create_volume.rb +66 -0
  50. data/lib/fog/aws/requests/ec2/delete_key_pair.rb +49 -0
  51. data/lib/fog/aws/requests/ec2/delete_security_group.rb +52 -0
  52. data/lib/fog/aws/requests/ec2/delete_snapshot.rb +24 -0
  53. data/lib/fog/aws/requests/ec2/delete_volume.rb +55 -0
  54. data/lib/fog/aws/requests/ec2/describe_addresses.rb +61 -0
  55. data/lib/fog/aws/requests/ec2/describe_availability_zones.rb +27 -0
  56. data/lib/fog/aws/requests/ec2/describe_images.rb +41 -0
  57. data/lib/fog/aws/requests/ec2/describe_instances.rb +48 -0
  58. data/lib/fog/aws/requests/ec2/describe_key_pairs.rb +63 -0
  59. data/lib/fog/aws/requests/ec2/describe_regions.rb +26 -0
  60. data/lib/fog/aws/requests/ec2/describe_security_groups.rb +71 -0
  61. data/lib/fog/aws/requests/ec2/describe_snapshots.rb +29 -0
  62. data/lib/fog/aws/requests/ec2/describe_volumes.rb +85 -0
  63. data/lib/fog/aws/requests/ec2/detach_volume.rb +32 -0
  64. data/lib/fog/aws/requests/ec2/disassociate_address.rb +24 -0
  65. data/lib/fog/aws/requests/ec2/get_console_output.rb +26 -0
  66. data/lib/fog/aws/requests/ec2/reboot_instances.rb +24 -0
  67. data/lib/fog/aws/requests/ec2/release_address.rb +50 -0
  68. data/lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb +32 -0
  69. data/lib/fog/aws/requests/ec2/run_instances.rb +74 -0
  70. data/lib/fog/aws/requests/ec2/terminate_instances.rb +31 -0
  71. data/lib/fog/aws/requests/s3/copy_object.rb +80 -0
  72. data/lib/fog/aws/requests/s3/delete_bucket.rb +49 -0
  73. data/lib/fog/aws/requests/s3/delete_object.rb +52 -0
  74. data/lib/fog/aws/requests/s3/get_bucket.rb +92 -0
  75. data/lib/fog/aws/requests/s3/get_bucket_location.rb +53 -0
  76. data/lib/fog/aws/requests/s3/get_object.rb +81 -0
  77. data/lib/fog/aws/requests/s3/get_request_payment.rb +53 -0
  78. data/lib/fog/aws/requests/s3/get_service.rb +58 -0
  79. data/lib/fog/aws/requests/s3/head_object.rb +61 -0
  80. data/lib/fog/aws/requests/s3/put_bucket.rb +69 -0
  81. data/lib/fog/aws/requests/s3/put_object.rb +75 -0
  82. data/lib/fog/aws/requests/s3/put_request_payment.rb +56 -0
  83. data/lib/fog/aws/requests/simpledb/batch_put_attributes.rb +31 -0
  84. data/lib/fog/aws/requests/simpledb/create_domain.rb +25 -0
  85. data/lib/fog/aws/requests/simpledb/delete_attributes.rb +34 -0
  86. data/lib/fog/aws/requests/simpledb/delete_domain.rb +25 -0
  87. data/lib/fog/aws/requests/simpledb/domain_metadata.rb +30 -0
  88. data/lib/fog/aws/requests/simpledb/get_attributes.rb +35 -0
  89. data/lib/fog/aws/requests/simpledb/list_domains.rb +30 -0
  90. data/lib/fog/aws/requests/simpledb/put_attributes.rb +29 -0
  91. data/lib/fog/aws/requests/simpledb/select.rb +29 -0
  92. data/lib/fog/aws/s3.rb +143 -0
  93. data/lib/fog/aws/simpledb.rb +157 -0
  94. data/lib/fog/aws.rb +127 -0
  95. data/lib/fog/connection.rb +122 -0
  96. data/lib/fog/errors.rb +131 -0
  97. data/lib/fog/parser.rb +30 -0
  98. data/lib/fog/response.rb +12 -0
  99. data/lib/fog.rb +22 -0
  100. data/spec/aws/ec2/allocate_address_spec.rb +20 -0
  101. data/spec/aws/ec2/associate_address_spec.rb +22 -0
  102. data/spec/aws/ec2/attach_volume_spec.rb +33 -0
  103. data/spec/aws/ec2/authorize_security_group_ingress_spec.rb +25 -0
  104. data/spec/aws/ec2/create_key_pair_spec.rb +27 -0
  105. data/spec/aws/ec2/create_security_group_spec.rb +25 -0
  106. data/spec/aws/ec2/create_snapshot_spec.rb +27 -0
  107. data/spec/aws/ec2/create_volume_spec.rb +25 -0
  108. data/spec/aws/ec2/delete_key_pair_spec.rb +20 -0
  109. data/spec/aws/ec2/delete_security_group_spec.rb +22 -0
  110. data/spec/aws/ec2/delete_snapshot_spec.rb +25 -0
  111. data/spec/aws/ec2/delete_volume_spec.rb +22 -0
  112. data/spec/aws/ec2/describe_addresses_spec.rb +34 -0
  113. data/spec/aws/ec2/describe_availability_zones_spec.rb +25 -0
  114. data/spec/aws/ec2/describe_images_spec.rb +41 -0
  115. data/spec/aws/ec2/describe_instances_spec.rb +76 -0
  116. data/spec/aws/ec2/describe_key_pairs_spec.rb +38 -0
  117. data/spec/aws/ec2/describe_regions_spec.rb +23 -0
  118. data/spec/aws/ec2/describe_security_groups_spec.rb +47 -0
  119. data/spec/aws/ec2/describe_snapshot_spec.rb +44 -0
  120. data/spec/aws/ec2/describe_volumes_spec.rb +46 -0
  121. data/spec/aws/ec2/detach_volume_spec.rb +33 -0
  122. data/spec/aws/ec2/disassociate_address_spec.rb +23 -0
  123. data/spec/aws/ec2/get_console_output_spec.rb +22 -0
  124. data/spec/aws/ec2/reboot_instances_spec.rb +20 -0
  125. data/spec/aws/ec2/release_address_spec.rb +22 -0
  126. data/spec/aws/ec2/revoke_security_group_ingress_spec.rb +31 -0
  127. data/spec/aws/ec2/run_instances_spec.rb +43 -0
  128. data/spec/aws/ec2/terminate_instances_spec.rb +25 -0
  129. data/spec/aws/s3/copy_object_spec.rb +57 -0
  130. data/spec/aws/s3/delete_bucket_spec.rb +21 -0
  131. data/spec/aws/s3/delete_object_spec.rb +31 -0
  132. data/spec/aws/s3/get_bucket_location_spec.rb +30 -0
  133. data/spec/aws/s3/get_bucket_spec.rb +42 -0
  134. data/spec/aws/s3/get_object_spec.rb +40 -0
  135. data/spec/aws/s3/get_request_payment_spec.rb +26 -0
  136. data/spec/aws/s3/get_service_spec.rb +32 -0
  137. data/spec/aws/s3/head_object_spec.rb +27 -0
  138. data/spec/aws/s3/put_bucket_spec.rb +22 -0
  139. data/spec/aws/s3/put_object_spec.rb +34 -0
  140. data/spec/aws/s3/put_request_payment_spec.rb +25 -0
  141. data/spec/aws/simpledb/batch_put_attributes_spec.rb +21 -0
  142. data/spec/aws/simpledb/create_domain_spec.rb +20 -0
  143. data/spec/aws/simpledb/delete_attributes_spec.rb +21 -0
  144. data/spec/aws/simpledb/delete_domain_spec.rb +20 -0
  145. data/spec/aws/simpledb/domain_metadata_spec.rb +42 -0
  146. data/spec/aws/simpledb/get_attributes_spec.rb +30 -0
  147. data/spec/aws/simpledb/list_domains_spec.rb +29 -0
  148. data/spec/aws/simpledb/put_attributes_spec.rb +21 -0
  149. data/spec/aws/simpledb/select_spec.rb +7 -0
  150. data/spec/lorem.txt +1 -0
  151. data/spec/spec.opts +1 -0
  152. data/spec/spec_helper.rb +74 -0
  153. metadata +256 -0
@@ -0,0 +1,50 @@
1
+ unless Fog.mocking?
2
+
3
+ module Fog
4
+ module AWS
5
+ class EC2
6
+
7
+ # Release an elastic IP address.
8
+ #
9
+ # ==== Returns
10
+ # * response<~Fog::AWS::Response>:
11
+ # * body<~Hash>:
12
+ # * 'requestId'<~String> - Id of request
13
+ # * 'return'<~Boolean> - success?
14
+ def release_address(public_ip)
15
+ request({
16
+ 'Action' => 'ReleaseAddress',
17
+ 'PublicIp' => public_ip
18
+ }, Fog::Parsers::AWS::EC2::Basic.new)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+
25
+ else
26
+
27
+ module Fog
28
+ module AWS
29
+ class EC2
30
+
31
+ def release_address(public_ip)
32
+ response = Fog::Response.new
33
+ if (address = @data[:addresses].delete(public_ip))
34
+ response.status = 200
35
+ response.body = {
36
+ 'requestId' => Fog::AWS::Mock.request_id,
37
+ 'return' => true
38
+ }
39
+ else
40
+ response.status = 400
41
+ raise(Fog::Errors.status_error(200, 400, response))
42
+ end
43
+ response
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,32 @@
1
+ module Fog
2
+ module AWS
3
+ class EC2
4
+
5
+ # Remove permissions from a security group
6
+ #
7
+ # ==== Parameters
8
+ # * options<~Hash>:
9
+ # * 'GroupName'<~String> - Name of group
10
+ # * 'SourceSecurityGroupName'<~String> - Name of security group to authorize
11
+ # * 'SourceSecurityGroupOwnerId'<~String> - Name of owner to authorize
12
+ # or
13
+ # * 'CidrIp' - CIDR range
14
+ # * 'FromPort' - Start of port range (or -1 for ICMP wildcard)
15
+ # * 'GroupName' - Name of group to modify
16
+ # * 'IpProtocol' - Ip protocol, must be in ['tcp', 'udp', 'icmp']
17
+ # * 'ToPort' - End of port range (or -1 for ICMP wildcard)
18
+ #
19
+ # === Returns
20
+ # * response<~Fog::AWS::Response>:
21
+ # * body<~Hash>:
22
+ # * 'requestId'<~String> - Id of request
23
+ # * 'return'<~Boolean> - success?
24
+ def revoke_security_group_ingress(options = {})
25
+ request({
26
+ 'Action' => 'RevokeSecurityGroupIngress'
27
+ }.merge!(options), Fog::Parsers::AWS::EC2::Basic.new)
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,74 @@
1
+ module Fog
2
+ module AWS
3
+ class EC2
4
+
5
+ # Launch specified instances
6
+ #
7
+ # ==== Parameters
8
+ # * image_id<~String> - Id of machine image to load on instances
9
+ # * min_count<~Integer> - Minimum number of instances to launch. If this
10
+ # exceeds the count of available instances, no instances will be
11
+ # launched. Must be between 1 and maximum allowed for your account
12
+ # (by default the maximum for an account is 20)
13
+ # * max_count<~Integer> - Maximum number of instances to launch. If this
14
+ # exceeds the number of available instances, the largest possible
15
+ # number of instances above min_count will be launched instead. Must
16
+ # be between 1 and maximum allowed for you account
17
+ # (by default the maximum for an account is 20)
18
+ # * options<~Hash>:
19
+ # * 'Placement.AvailabilityZone'<~String> - Placement constraint for instances
20
+ # * 'DeviceName'<~String> - ?
21
+ # * 'Encoding'<~String> - ?
22
+ # * 'GroupId'<~String> - Name of security group for instances
23
+ # * 'InstanceType'<~String> - Type of instance to boot. Valid options
24
+ # in ['m1.small', 'm1.large', 'm1.xlarge', 'c1.medium', 'c1.xlarge']
25
+ # default is 'm1.small'
26
+ # * 'KernelId'<~String> - Id of kernel with which to launch
27
+ # * 'KeyName'<~String> - Name of a keypair to add to booting instances
28
+ # * 'Monitoring.Enabled'<~Boolean> - Enables monitoring, defaults to
29
+ # disabled
30
+ # * 'RamdiskId'<~String> - Id of ramdisk with which to launch
31
+ # * 'UserData'<~String> - Additional data to provide to booting instances
32
+ # * 'Version'<~String> - ?
33
+ # * 'VirtualName'<~String> - ?
34
+ #
35
+ # ==== Returns
36
+ # * response<~Fog::AWS::Response>:
37
+ # * body<~Hash>:
38
+ # * 'groupSet'<~Array>: groups the instances are members in
39
+ # * 'groupName'<~String> - Name of group
40
+ # * 'instancesSet'<~Array>: returned instances
41
+ # * instance<~Hash>:
42
+ # * 'amiLaunchIndex'<~Integer> - reference to instance in launch group
43
+ # * 'dnsName'<~String> - public dns name, blank until instance is running
44
+ # * 'imageId'<~String> - image id of ami used to launch instance
45
+ # * 'instanceId'<~String> - id of the instance
46
+ # * 'instanceState'<~Hash>:
47
+ # * 'code'<~Integer> - current status code
48
+ # * 'name'<~String> - current status name
49
+ # * 'instanceType'<~String> - type of instance
50
+ # * 'kernelId'<~String> - Id of kernel used to launch instance
51
+ # * 'keyName'<~String> - name of key used launch instances or blank
52
+ # * 'launchTime'<~Time> - time instance was launched
53
+ # * 'monitoring'<~Hash>:
54
+ # * 'state'<~Boolean - state of monitoring
55
+ # * 'placement'<~Hash>:
56
+ # * 'availabilityZone'<~String> - Availability zone of the instance
57
+ # * 'privateDnsName'<~String> - private dns name, blank until instance is running
58
+ # * 'productCodes'<~Array> - Product codes for the instance
59
+ # * 'ramdiskId'<~String> - Id of ramdisk used to launch instance
60
+ # * 'reason'<~String> - reason for most recent state transition, or blank
61
+ # * 'ownerId'<~String> - Id of owner
62
+ # * 'requestId'<~String> - Id of request
63
+ def run_instances(image_id, min_count, max_count, options = {})
64
+ request({
65
+ 'Action' => 'RunInstances',
66
+ 'ImageId' => image_id,
67
+ 'MinCount' => min_count,
68
+ 'MaxCount' => max_count
69
+ }.merge!(options), Fog::Parsers::AWS::EC2::RunInstances.new)
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,31 @@
1
+ module Fog
2
+ module AWS
3
+ class EC2
4
+
5
+ # Terminate specified instances
6
+ #
7
+ # ==== Parameters
8
+ # * instance_id<~Array> - Ids of instances to terminates
9
+ #
10
+ # ==== Returns
11
+ # # * response<~Fog::AWS::Response>:
12
+ # * body<~Hash>:
13
+ # * 'requestId'<~String> - Id of request
14
+ # * 'instancesSet'<~Array>:
15
+ # * 'instanceId'<~String> - id of the terminated instance
16
+ # * 'previousState'<~Hash>: previous state of instance
17
+ # * 'code'<~Integer> - previous status code
18
+ # * 'name'<~String> - name of previous state
19
+ # * 'shutdownState'<~Hash>: shutdown state of instance
20
+ # * 'code'<~Integer> - current status code
21
+ # * 'name'<~String> - name of current state
22
+ def terminate_instances(instance_id)
23
+ params = indexed_params('InstanceId', instance_id)
24
+ request({
25
+ 'Action' => 'TerminateInstances'
26
+ }.merge!(params), Fog::Parsers::AWS::EC2::TerminateInstances.new)
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,80 @@
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 = @data[:buckets][source_bucket_name]
53
+ source_object = source_bucket && source_bucket[:objects][source_object_name]
54
+ target_bucket = @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
+ 'ETag' => Fog::AWS::Mock.etag,
61
+ 'Name' => target_object_name
62
+ })
63
+ target_bucket[:objects][target_object_name] = target_object
64
+ response.body = {
65
+ 'ETag' => target_object['ETag'],
66
+ 'LastModified' => Time.parse(target_object['LastModified'])
67
+ }
68
+ else
69
+ response.status = 404
70
+ raise(Fog::Errors.status_error(200, 404, response))
71
+ end
72
+
73
+ response
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,49 @@
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 @data[:buckets].delete(bucket_name)
37
+ response.status = 204
38
+ else
39
+ response.status = 404
40
+ raise(Fog::Errors.status_error(204, 404, response))
41
+ end
42
+ response
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+
49
+ 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 = @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,92 @@
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
+ def get_bucket(bucket_name, options = {})
63
+ response = Fog::Response.new
64
+ if bucket = @data[:buckets][bucket_name]
65
+ response.status = 200
66
+ response.body = {
67
+ 'Contents' => bucket[:objects].values.map do |object|
68
+ data = object.reject {|key, value| !['ETag', 'Key', 'LastModified', 'Owner', 'Size', 'StorageClass'].include?(key)}
69
+ data.merge!({
70
+ 'LastModified' => Time.parse(data['LastModified']),
71
+ 'Size' => data['Size'].to_i
72
+ })
73
+ data
74
+ end,
75
+ 'IsTruncated' => false,
76
+ 'Marker' => options['Marker'] || '',
77
+ 'MaxKeys' => options['MaxKeys'] || 1000,
78
+ 'Name' => bucket['Name'],
79
+ 'Prefix' => options['Prefix'] || ''
80
+ }
81
+ else
82
+ response.status = 404
83
+ raise(Fog::Errors.status_error(200, 404, response))
84
+ end
85
+ response
86
+ end
87
+
88
+ end
89
+ end
90
+ end
91
+
92
+ 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 = @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,81 @@
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 = @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
+ 'ETag' => object['ETag'],
66
+ 'Last-Modified' => object['LastModified']
67
+ }
68
+ response.body = object[:body]
69
+ end
70
+ else
71
+ response.status = 404
72
+ raise(Fog::Errors.status_error(200, 404, response))
73
+ end
74
+ response
75
+ end
76
+
77
+ end
78
+ end
79
+ end
80
+
81
+ 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 = @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