Method: Fog::Storage::Google::Mock#put_bucket

Defined in:
lib/fog/google/requests/storage/put_bucket.rb

#put_bucket(bucket_name, options = {}) ⇒ Object

[View source]

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fog/google/requests/storage/put_bucket.rb', line 42

def put_bucket(bucket_name, options = {})
  acl = options['x-goog-acl'] || 'private'
  if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl)
    raise Excon::Errors::BadRequest.new('invalid x-goog-acl')
  else
    self.data[:acls][:bucket][bucket_name] = self.class.acls(options[acl])
  end
  response = Excon::Response.new
  response.status = 200
  bucket = {
    :objects        => {},
    'Name'          => bucket_name,
    'CreationDate'  => Time.now,
    'Owner'         => { 'DisplayName' => 'owner', 'ID' => 'some_id'},
    'Payer'         => 'BucketOwner'
  }
  if options['LocationConstraint']
    bucket['LocationConstraint'] = options['LocationConstraint']
  else
    bucket['LocationConstraint'] = ''
  end
  if self.data[:buckets][bucket_name].nil?
    self.data[:buckets][bucket_name] = bucket
  else
    response.status = 409
    raise(Excon::Errors.status_error({:expects => 200}, response))
  end
  response
end