-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add presigned_url method. #35
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved codewise might be worth checking that we want this at all
lib/file_storage/disk.rb
Outdated
@@ -53,6 +53,12 @@ def delete!(bucket:, key:) | |||
true | |||
end | |||
|
|||
# rubocop: disable Lint/UnusedMethodArgument | |||
def presigned_url(bucket:, key:, expiry:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def presigned_url(bucket:, key:, expiry:) | |
def presigned_url(bucket:, key:, **args) |
Does this work? Might be able to get rid of the rubocop comments
I'm trying to figure out the main use cases for this from a caller perspective. I imagine we need to make these two things easy-ish:
If we don't implement presigned urls in here, I think clients can still do it (for GCS, at least) with something like this, which is not great but not too awful either: FileStorage.for("gs://bucket/url.txt").tap do |ks|
gcs = Google::Cloud::Storage.new # we don't explicitly configure auth via FileStorage, for now
gcs.bucket(ks.bucket, skip_lookup: true).file(ks.key).signed_url(...)
end Just wondering what options do we have available, off the top of my head:
FileStorage.for("gs://bucket/url.txt").tap do |ks|
ks.connection.bucket(ks.bucket, skip_lookup: true).file(ks.key).signed_url(...)
end
expect { URI.parse(FileStorage.for("inmemory://bucket/url.txt").presigned_url(expiry: 3.years)) }.to_not raise_error
FileStorage.for("gs://bucket/url.txt").presigned_url(expiry: 1.year, authentication: ...)
FileStorage.for("s3://bucket/url.txt").presigned_url(expiry: 1.year, authentication: ...) # crash if `authentication` is not supported
# disk and inmemory will ignore most options as they don't make sense for them while still returning a valid-looking URI
FileStorage.for("inmemory://bucket/url.txt").presigned_url(expiry: 1.year, authentication: ...)
FileStorage.for("disk://bucket/url.txt").presigned_url(expiry: 1.year, authentication: ...) I'm leaning more towards option 3 in this case which is not a huge change from what this PR is currently doing (I reckon we need to just proxy all the arguments to |
For GCS, return an actual presigned URL for the file. For disk, return a standard `file://` url. For inmemory, return the original URL, for the sake of completeness.
c943758
to
8237dc2
Compare
Rebased this against master, I'll try to revive it next week |
For GCS, return an actual presigned URL for the file. For disk, return a
standard
file://
url. For inmemory, return the original URL, for thesake of completeness.