diff --git a/lib/fog/aws/requests/s3/get_bucket.rb b/lib/fog/aws/requests/s3/get_bucket.rb index 03e3f2a5b..9c6b41b64 100644 --- a/lib/fog/aws/requests/s3/get_bucket.rb +++ b/lib/fog/aws/requests/s3/get_bucket.rb @@ -55,7 +55,6 @@ unless Fog.mocking? else - # TODO: IsTruncated, Marker, MaxKeys, Name, Prefix module Fog module AWS class S3 @@ -68,12 +67,17 @@ else else response.status = 200 response.body = { - 'IsTruncated' => false, 'Contents' => bucket['Contents'].map do |object| - data = object.reject {|key, value| !['ETag', 'Key', 'LastModified', 'Owner', 'StorageClass'].include?(key)} - data['LastModified'] = Time.parse(data['LastModified']) + data = object.reject {|key, value| !['ETag', 'Key', 'LastModified', 'Owner', 'Size', 'StorageClass'].include?(key)} + data['LastModified'] = Time.parse(data['LastModified']) + data['Size'] = data['Size'].to_i data - end + end, + 'IsTruncated' => false, + 'Marker' => options['Marker'] || '', + 'MaxKeys' => options['MaxKeys'] || 1000, + 'Name' => bucket['Name'], + 'Prefix' => options['Prefix'] || '' } end response diff --git a/lib/fog/aws/requests/s3/get_bucket_location.rb b/lib/fog/aws/requests/s3/get_bucket_location.rb index a333d8915..3f38c7afb 100644 --- a/lib/fog/aws/requests/s3/get_bucket_location.rb +++ b/lib/fog/aws/requests/s3/get_bucket_location.rb @@ -1,27 +1,54 @@ -module Fog - module AWS - class S3 +unless Fog.mocking? + + module Fog + module AWS + class S3 + + # Get location constraint for an S3 bucket + # + # ==== Parameters + # * bucket_name<~String> - name of bucket to get location constraint for + # + # ==== Returns + # * response<~Fog::AWS::Response>: + # * body<~Hash>: + # * 'LocationConstraint'<~String> - Location constraint of the bucket + def get_bucket_location(bucket_name) + request({ + :expects => 200, + :headers => {}, + :host => "#{bucket_name}.#{@host}", + :method => 'GET', + :parser => Fog::Parsers::AWS::S3::GetBucketLocation.new, + :query => 'location' + }) + end - # Get location constraint for an S3 bucket - # - # ==== Parameters - # * bucket_name<~String> - name of bucket to get location constraint for - # - # ==== Returns - # * response<~Fog::AWS::Response>: - # * body<~Hash>: - # * 'LocationConstraint'<~String> - Location constraint of the bucket - def get_bucket_location(bucket_name) - request({ - :expects => 200, - :headers => {}, - :host => "#{bucket_name}.#{@host}", - :method => 'GET', - :parser => Fog::Parsers::AWS::S3::GetBucketLocation.new, - :query => 'location' - }) end - end end -end + +else + + module Fog + module AWS + class S3 + + def get_bucket_location(bucket_name) + response = Fog::Response.new + bucket_status = get_bucket(bucket_name).status + if bucket_status == 200 + response.status = 200 + bucket = @data['Buckets'].select {|bucket| bucket['Name'] == bucket_name}.first + response.body = {'LocationConstraint' => bucket['LocationConstraint'] } + else + response.status = bucket_status + end + response + end + + end + end + end + +end \ No newline at end of file diff --git a/lib/fog/aws/requests/s3/put_bucket.rb b/lib/fog/aws/requests/s3/put_bucket.rb index b4473c9ca..a9f7a441b 100644 --- a/lib/fog/aws/requests/s3/put_bucket.rb +++ b/lib/fog/aws/requests/s3/put_bucket.rb @@ -47,12 +47,18 @@ else def put_bucket(bucket_name, options = {}) response = Fog::Response.new response.status = 200 - @data['Buckets'] << { + bucket = { 'Name' => bucket_name, 'Contents' => [], 'CreationDate' => Time.now, 'Payer' => 'BucketOwner' } + if options['LocationConstraint'] + bucket['LocationConstraint'] = options['LocationConstraint'] + else + bucket['LocationConstraint'] = '' + end + @data['Buckets'] << bucket response end diff --git a/lib/fog/aws/s3.rb b/lib/fog/aws/s3.rb index 7cdac3a11..f4983b319 100644 --- a/lib/fog/aws/s3.rb +++ b/lib/fog/aws/s3.rb @@ -28,6 +28,10 @@ module Fog module AWS class S3 + if Fog.mocking? + attr_accessor :data + end + # Initialize connection to S3 # # ==== Notes diff --git a/spec/aws/s3/get_bucket_location_spec.rb b/spec/aws/s3/get_bucket_location_spec.rb index bb98bb921..c3b492546 100644 --- a/spec/aws/s3/get_bucket_location_spec.rb +++ b/spec/aws/s3/get_bucket_location_spec.rb @@ -3,15 +3,20 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe 'S3.get_bucket_location' do before(:all) do - s3.put_bucket('foggetlocation', 'LocationConstraint' => 'EU') + @s3 = s3 + @eu_s3 = eu_s3 + @s3.put_bucket('foggetlocation', 'LocationConstraint' => 'EU') end after(:all) do - eu_s3.delete_bucket('foggetlocation') + if Fog.mocking? + @eu_s3.data = @s3.data + end + @eu_s3.delete_bucket('foggetlocation') end it 'should return proper attributes' do - actual = s3.get_bucket_location('foggetlocation') + actual = @s3.get_bucket_location('foggetlocation') actual.status.should == 200 actual.body['LocationConstraint'].should == 'EU' end