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: make errors returned by URLSignerHMAC.KeyFromURL recognizable #3504

Open a-gierczak opened 1 month ago

a-gierczak commented 1 month ago

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

Pretty small change request, to make errors returned by URLSignerHMAC.KeyFromURL identifiable by errors.Is

Describe the solution you'd like

https://github.com/google/go-cloud/blob/master/blob/fileblob/fileblob.go#L1021

I'd change the returned errors in the linked function to:

var (
    ErrSignatureExpired = errors.New("signature expired")
    ErrInvalidSignature = errors.New("invalid signature")
)

...

if err != nil || time.Now().Unix() > exp {
    return "", ErrSignatureExpired
}

if !h.checkMAC(q) {
    return "", ErrInvalidSignature
}

Describe alternatives you've considered

Custom URLSigner implementation - but it's such a minor thing, that it'd be an overkill not to use the built-in one :)

vangent commented 1 month ago

This doesn't seem portable; other providers just return an error. How would you use this?