mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|storage] Updates reference to service
This commit is contained in:
parent
ca9fc51c82
commit
e4dd7c85b8
6 changed files with 34 additions and 35 deletions
|
@ -10,7 +10,7 @@ module Fog
|
|||
model Fog::Storage::AWS::Directory
|
||||
|
||||
def all
|
||||
data = connection.get_service.body['Buckets']
|
||||
data = service.get_service.body['Buckets']
|
||||
load(data)
|
||||
end
|
||||
|
||||
|
@ -21,7 +21,7 @@ module Fog
|
|||
:max_keys => 'max-keys',
|
||||
:prefix => 'prefix'
|
||||
})
|
||||
data = connection.get_bucket(key, options).body
|
||||
data = service.get_bucket(key, options).body
|
||||
directory = new(:key => data['Name'])
|
||||
options = {}
|
||||
for k, v in data
|
||||
|
|
|
@ -28,7 +28,7 @@ module Fog
|
|||
|
||||
def destroy
|
||||
requires :key
|
||||
connection.delete_bucket(key)
|
||||
service.delete_bucket(key)
|
||||
true
|
||||
rescue Excon::Errors::NotFound
|
||||
false
|
||||
|
@ -36,7 +36,7 @@ module Fog
|
|||
|
||||
def location
|
||||
requires :key
|
||||
attributes[:location] || bucket_location || self.connection.region
|
||||
attributes[:location] || bucket_location || self.service.region
|
||||
end
|
||||
|
||||
def location=(new_location)
|
||||
|
@ -48,34 +48,34 @@ module Fog
|
|||
end
|
||||
|
||||
def files
|
||||
@files ||= Fog::Storage::AWS::Files.new(:directory => self, :connection => connection)
|
||||
@files ||= Fog::Storage::AWS::Files.new(:directory => self, :service => service)
|
||||
end
|
||||
|
||||
def payer
|
||||
requires :key
|
||||
data = connection.get_request_payment(key)
|
||||
data = service.get_request_payment(key)
|
||||
data.body['Payer']
|
||||
end
|
||||
|
||||
def payer=(new_payer)
|
||||
requires :key
|
||||
connection.put_request_payment(key, new_payer)
|
||||
service.put_request_payment(key, new_payer)
|
||||
@payer = new_payer
|
||||
end
|
||||
|
||||
def versioning?
|
||||
requires :key
|
||||
data = connection.get_bucket_versioning(key)
|
||||
data = service.get_bucket_versioning(key)
|
||||
data.body['VersioningConfiguration']['Status'] == 'Enabled'
|
||||
end
|
||||
|
||||
def versioning=(new_versioning)
|
||||
requires :key
|
||||
connection.put_bucket_versioning(key, new_versioning ? 'Enabled' : 'Suspended')
|
||||
service.put_bucket_versioning(key, new_versioning ? 'Enabled' : 'Suspended')
|
||||
end
|
||||
|
||||
def versions
|
||||
@versions ||= Fog::Storage::AWS::Versions.new(:directory => self, :connection => connection)
|
||||
@versions ||= Fog::Storage::AWS::Versions.new(:directory => self, :service => service)
|
||||
end
|
||||
|
||||
def public=(new_public)
|
||||
|
@ -85,7 +85,7 @@ module Fog
|
|||
|
||||
def public_url
|
||||
requires :key
|
||||
if connection.get_bucket_acl(key).body['AccessControlList'].detect {|grant| grant['Grantee']['URI'] == 'http://acs.amazonaws.com/groups/global/AllUsers' && grant['Permission'] == 'READ'}
|
||||
if service.get_bucket_acl(key).body['AccessControlList'].detect {|grant| grant['Grantee']['URI'] == 'http://acs.amazonaws.com/groups/global/AllUsers' && grant['Permission'] == 'READ'}
|
||||
if key.to_s =~ Fog::AWS::COMPLIANT_BUCKET_NAMES
|
||||
"https://#{key}.s3.amazonaws.com"
|
||||
else
|
||||
|
@ -103,11 +103,11 @@ module Fog
|
|||
|
||||
options['x-amz-acl'] = acl if acl
|
||||
|
||||
if location = attributes[:location] || (self.connection.region != 'us-east-1' && self.connection.region)
|
||||
if location = attributes[:location] || (self.service.region != 'us-east-1' && self.service.region)
|
||||
options['LocationConstraint'] = location
|
||||
end
|
||||
|
||||
connection.put_bucket(key, options)
|
||||
service.put_bucket(key, options)
|
||||
|
||||
true
|
||||
end
|
||||
|
@ -115,7 +115,7 @@ module Fog
|
|||
private
|
||||
|
||||
def bucket_location
|
||||
data = connection.get_bucket_location(key)
|
||||
data = service.get_bucket_location(key)
|
||||
data.body['LocationConstraint']
|
||||
end
|
||||
|
||||
|
|
|
@ -90,8 +90,8 @@ module Fog
|
|||
#
|
||||
def copy(target_directory_key, target_file_key, options = {})
|
||||
requires :directory, :key
|
||||
connection.copy_object(directory.key, key, target_directory_key, target_file_key, options)
|
||||
target_directory = connection.directories.new(:key => target_directory_key)
|
||||
service.copy_object(directory.key, key, target_directory_key, target_file_key, options)
|
||||
target_directory = service.directories.new(:key => target_directory_key)
|
||||
target_directory.files.head(target_file_key)
|
||||
end
|
||||
|
||||
|
@ -107,7 +107,7 @@ module Fog
|
|||
def destroy(options = {})
|
||||
requires :directory, :key
|
||||
attributes[:body] = nil if options['versionId'] == version
|
||||
connection.delete_object(directory.key, key, options)
|
||||
service.delete_object(directory.key, key, options)
|
||||
true
|
||||
end
|
||||
|
||||
|
@ -162,7 +162,7 @@ module Fog
|
|||
#
|
||||
def public_url
|
||||
requires :directory, :key
|
||||
if connection.get_object_acl(directory.key, key).body['AccessControlList'].detect {|grant| grant['Grantee']['URI'] == 'http://acs.amazonaws.com/groups/global/AllUsers' && grant['Permission'] == 'READ'}
|
||||
if service.get_object_acl(directory.key, key).body['AccessControlList'].detect {|grant| grant['Grantee']['URI'] == 'http://acs.amazonaws.com/groups/global/AllUsers' && grant['Permission'] == 'READ'}
|
||||
if directory.key.to_s =~ Fog::AWS::COMPLIANT_BUCKET_NAMES
|
||||
"https://#{directory.key}.s3.amazonaws.com/#{Fog::AWS.escape(key)}".gsub('%2F','/')
|
||||
else
|
||||
|
@ -173,7 +173,6 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
# Save file with body as contents to directory.key with name key via http PUT
|
||||
#
|
||||
# required attributes: body, directory, key
|
||||
|
@ -210,7 +209,7 @@ module Fog
|
|||
data = multipart_save(options)
|
||||
merge_attributes(data.body)
|
||||
else
|
||||
data = connection.put_object(directory.key, key, body, options)
|
||||
data = service.put_object(directory.key, key, body, options)
|
||||
merge_attributes(data.headers.reject {|key, value| ['Content-Length', 'Content-Type'].include?(key)})
|
||||
end
|
||||
self.etag.gsub!('"','')
|
||||
|
@ -241,7 +240,7 @@ module Fog
|
|||
@versions ||= begin
|
||||
Fog::Storage::AWS::Versions.new(
|
||||
:file => self,
|
||||
:connection => connection
|
||||
:service => service
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -254,7 +253,7 @@ module Fog
|
|||
|
||||
def multipart_save(options)
|
||||
# Initiate the upload
|
||||
res = connection.initiate_multipart_upload(directory.key, key, options)
|
||||
res = service.initiate_multipart_upload(directory.key, key, options)
|
||||
upload_id = res.body["UploadId"]
|
||||
|
||||
# Store ETags of upload parts
|
||||
|
@ -267,17 +266,17 @@ module Fog
|
|||
body.rewind if body.respond_to?(:rewind)
|
||||
while (chunk = body.read(multipart_chunk_size)) do
|
||||
md5 = Base64.encode64(Digest::MD5.digest(chunk)).strip
|
||||
part_upload = connection.upload_part(directory.key, key, upload_id, part_tags.size + 1, chunk, 'Content-MD5' => md5 )
|
||||
part_upload = service.upload_part(directory.key, key, upload_id, part_tags.size + 1, chunk, 'Content-MD5' => md5 )
|
||||
part_tags << part_upload.headers["ETag"]
|
||||
end
|
||||
|
||||
rescue
|
||||
# Abort the upload & reraise
|
||||
connection.abort_multipart_upload(directory.key, key, upload_id) if upload_id
|
||||
service.abort_multipart_upload(directory.key, key, upload_id) if upload_id
|
||||
raise
|
||||
else
|
||||
# Complete the upload
|
||||
connection.complete_multipart_upload(directory.key, key, upload_id, part_tags)
|
||||
service.complete_multipart_upload(directory.key, key, upload_id, part_tags)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -60,7 +60,7 @@ module Fog
|
|||
|
||||
def get(key, options = {}, &block)
|
||||
requires :directory
|
||||
data = connection.get_object(directory.key, key, options, &block)
|
||||
data = service.get_object(directory.key, key, options, &block)
|
||||
file_data = data.headers.merge({
|
||||
:body => data.body,
|
||||
:key => key
|
||||
|
@ -80,22 +80,22 @@ module Fog
|
|||
|
||||
def get_url(key, expires, options = {})
|
||||
requires :directory
|
||||
connection.get_object_url(directory.key, key, expires, options)
|
||||
service.get_object_url(directory.key, key, expires, options)
|
||||
end
|
||||
|
||||
def get_http_url(key, expires, options = {})
|
||||
requires :directory
|
||||
connection.get_object_http_url(directory.key, key, expires, options)
|
||||
service.get_object_http_url(directory.key, key, expires, options)
|
||||
end
|
||||
|
||||
def get_https_url(key, expires, options = {})
|
||||
requires :directory
|
||||
connection.get_object_https_url(directory.key, key, expires, options)
|
||||
service.get_object_https_url(directory.key, key, expires, options)
|
||||
end
|
||||
|
||||
def head(key, options = {})
|
||||
requires :directory
|
||||
data = connection.head_object(directory.key, key, options)
|
||||
data = service.head_object(directory.key, key, options)
|
||||
file_data = data.headers.merge({
|
||||
:key => key
|
||||
})
|
||||
|
|
|
@ -24,9 +24,9 @@ module Fog
|
|||
|
||||
def destroy
|
||||
if collection.file
|
||||
collection.connection.delete_object(collection.file.directory.key, key, 'versionId' => version)
|
||||
collection.service.delete_object(collection.file.directory.key, key, 'versionId' => version)
|
||||
else
|
||||
collection.connection.delete_object(collection.directory.key, key, 'versionId' => version)
|
||||
collection.service.delete_object(collection.directory.key, key, 'versionId' => version)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,9 +14,9 @@ module Fog
|
|||
|
||||
def all(options = {})
|
||||
data = if file
|
||||
connection.get_bucket_object_versions(file.directory.key, options.merge('prefix' => file.key)).body['Versions']
|
||||
service.get_bucket_object_versions(file.directory.key, options.merge('prefix' => file.key)).body['Versions']
|
||||
else
|
||||
connection.get_bucket_object_versions(directory.key, options).body['Versions']
|
||||
service.get_bucket_object_versions(directory.key, options).body['Versions']
|
||||
end
|
||||
|
||||
load(data)
|
||||
|
@ -35,4 +35,4 @@ module Fog
|
|||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue