Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: ability to generate virtually-hosted/cnamed urls for a given bucket #786

Closed
jbr opened this issue Apr 21, 2015 · 4 comments
Closed
Labels
feature-request A feature should be added or improved.

Comments

@jbr
Copy link

jbr commented Apr 21, 2015

I have a us standard bucket with a bucket name that is also a cnamed fqdn like storage.mysite.com and would like any generated urls to use that cname / virtual host. By generated urls, I mean any url that might be public-facing, not necessarily urls that the gem uses internally to speak to s3. In my use case, this would include Aws::S3::Object#public_url and Aws::S3::Object#presigned_url, but there may be more methods like this. It would be ideal to set this on creation / access of the bucket, like:

BUCKET = Aws::S3::Resource.new(region, creds).
  bucket('storage.mysite.com', virtual_host: true)

It might be useful to someone if that could also be overridden per object method, so BUCKET.object('not-cnamed').public_url(virtual_host: false) would revert to default behavior, or so

Aws::S3::Resource.new(region, creds).
  bucket('storage.mysite.com').
  object('cnamed').
  public_url(virtual_host: true)

would result in something like http://storage.mysite.com/cnamed

This could also raise a useful exception if the bucket isn't us-standard and the user is trying to set virtual_host: true

I understand that this would be mutually exclusive with secure: true and would expect the gem to raise if I tried to specify both of them.

Thank you!

@trevorrowe trevorrowe added feature-request A feature should be added or improved. Version 2 labels Apr 21, 2015
@trevorrowe
Copy link
Member

Thanks for posting the feature request. I'm out traveling for the week, but lets continue the conversation early next week.

@bilus
Copy link

bilus commented Jun 30, 2015

@trevorrowe Have you been able to look into this? We badly need support for presigned urls using CNAMEd buckets. Unlike @jbr, we host the files outside us-standard so +1 to a solution that somehow takes that into account before we close this door and make it difficult to add this functionality in the future.

If there's any way I can help move it forward, please let me know.

@trevorrowe
Copy link
Member

@bilus I was previously looking at this. I have a local proof of concept branch which lacks tests. I got to the point where I needed a live bucket in S3 with a cname and I lacked one at the time. I need to circle back on this, but haven't had the opportunity too.

@bilus
Copy link

bilus commented Jul 2, 2015

Actually, I've been able to generate the urls using the code similar to this:

  bucket_name = "some-bucket.example.com"
  s3 = Aws::S3::Client.new(endpoint: "http://example.com", region: "eu-central-1")
  bucket = Aws::S3::Bucket.new("some-bucket", client: s3)
  object = bucket.object("some-key")
  object.presigned_url(:get, expires_in: 24 * 3600, secure: false)

This probably gives a better idea of what goes where (and should probably work but it's untested):

def generate_presigned_url(region, domain, bucket_basename, key, expire_after)
  bucket_name = "#{bucket_basename}.#{domain}"   
  s3 = Aws::S3::Client.new(endpoint: "http://#{domain}", region: region)   
  bucket = Aws::S3::Bucket.new(bucket_basename, client: s3)
  object = bucket.object(key)
  object.presigned_url(:get, expires_in: expire_after, secure: false)
end

As this based on stepping through the code with a debugger and not docs, I'm leaving stuff that can probably be omitted (e.g. region).

The secure: false bit is important because of lack of security certificates for some-bucket.example.com.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

3 participants