google / go-cloud

The Go Cloud Development Kit (Go CDK): A library and tools for open cloud development in Go.
https://gocloud.dev/
Apache License 2.0
9.57k stars 812 forks source link

blob/fileblob: expose URLSigner from fileblob.bucket #3503

Closed a-gierczak closed 1 month ago

a-gierczak commented 1 month ago

Is your feature request related to a problem? Please describe.

Currently, you can use the built-in URLSignerHMAC to presign URLs by passing base_url and secret_key_path query params to OpenBucket. However, there is no way to actually validate the signature later, as URLSigner is not publicly exposed in file blob.

Describe the solution you'd like

Make fileblob.bucket struct public, and add a URLSigner() method on bucket that would return bucket.opts.URLSigner

Describe alternatives you've considered

The workaround I'm using right now is having my own URLSigner constructor, which calls fileblob.NewURLSignerHMAC (basically copy-paste implementation from fileblob), and storing it in my struct along with the bucket. Then, I'm passing this URLSigner to fileblob.OpenBucket options.

vangent commented 1 month ago

You can either

  1. Create your own URLSigner (possibly a NewURLSignerHMAC, but also possibly a different implementation of the URLSigner interface), set it in Options.URLSigner, and pass it to the constructor. Then you have direct access to the signer. It sounds like this is what you're doing.
  2. If you want to use the Go Cloud URL constructor, you can pass base_url and secret_key_path to create the bucket, and separately create an URLSignerHMAC to use for validation; it should work as long as you pass the same parameters.

None of the provider structs are public, by design -- they are intended to be treated as blob.Bucket after construction, not have special functions for specific providers.