jnicklas/carrierwave — Issue #645: S3 authenticated urls don't use cname
Author: BRMatt
Created: 2012-03-06 20:09:04+00:00
State: open

I've setup carrierwave like so:

```ruby
# Choose what kind of storage to use for this uploader:
config.storage :fog

config.cache_dir = "#{Rails.root}/tmp/uploads"
config.fog_credentials = {
# ...
}

config.fog_directory = bucket_name
config.fog_public = false
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
config.fog_host = bucket_host
```

However, whenever I access the private files I'm sent to the stock s3 url instead of the cnamed version.

Had a quick poke around in `CarrierWave::Storage::S3` and noticed that unlike `#public_url`, `#authenticated_url` uses fog to generate the url.

```ruby
def authenticated_url
connection.get_object_https_url(bucket, path, Time.now + authentication_timeout)
end
```

Looking in the fog gem it seems that it only uses a custom host if the `:host` option is provided when the connection is created, which currently isn't happening:

```ruby
@connection ||= ::Fog::Storage.new(
:aws_access_key_id => uploader.s3_access_key_id,
:aws_secret_access_key => uploader.s3_secret_access_key,
:provider => 'AWS',
:region => uploader.s3_region
)
```