From ba6a4cb4543d47cd29b2060b26918d2d69eb1922 Mon Sep 17 00:00:00 2001 From: Duarte Henriques Date: Tue, 24 Feb 2015 19:39:57 +0000 Subject: [PATCH] Add support for cname buckets --- lib/fog/aws/storage.rb | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/fog/aws/storage.rb b/lib/fog/aws/storage.rb index 4fd74ea69..7221456c4 100644 --- a/lib/fog/aws/storage.rb +++ b/lib/fog/aws/storage.rb @@ -256,21 +256,25 @@ module Fog if params[:bucket_name] bucket_name = params[:bucket_name] - path_style = params.fetch(:path_style, @path_style) - if !path_style - if COMPLIANT_BUCKET_NAMES !~ bucket_name - Fog::Logger.warning("fog: the specified s3 bucket name(#{bucket_name}) is not a valid dns name, which will negatively impact performance. For details see: http://docs.amazonwebservices.com/AmazonS3/latest/dev/BucketRestrictions.html") - path_style = true - elsif scheme == 'https' && !path_style && bucket_name =~ /\./ - Fog::Logger.warning("fog: the specified s3 bucket name(#{bucket_name}) contains a '.' so is not accessible over https as a virtual hosted bucket, which will negatively impact performance. For details see: http://docs.amazonwebservices.com/AmazonS3/latest/dev/BucketRestrictions.html") - path_style = true - end - end - - if path_style - path = bucket_to_path bucket_name, path + if params[:bucket_cname] + host = bucket_name else - host = [bucket_name, host].join('.') + path_style = params.fetch(:path_style, @path_style) + if !path_style + if COMPLIANT_BUCKET_NAMES !~ bucket_name + Fog::Logger.warning("fog: the specified s3 bucket name(#{bucket_name}) is not a valid dns name, which will negatively impact performance. For details see: http://docs.amazonwebservices.com/AmazonS3/latest/dev/BucketRestrictions.html") + path_style = true + elsif scheme == 'https' && !path_style && bucket_name =~ /\./ + Fog::Logger.warning("fog: the specified s3 bucket name(#{bucket_name}) contains a '.' so is not accessible over https as a virtual hosted bucket, which will negatively impact performance. For details see: http://docs.amazonwebservices.com/AmazonS3/latest/dev/BucketRestrictions.html") + path_style = true + end + end + + if path_style + path = bucket_to_path bucket_name, path + else + host = [bucket_name, host].join('.') + end end end