MCPcopy Create free account
hub / github.com/google/go-cloud / SignedURL

Method SignedURL

blob/blob.go:1301–1341  ·  view source on GitHub ↗

SignedURL returns a URL that can be used to GET (default), PUT or DELETE the blob for the duration specified in opts.Expiry. A nil SignedURLOptions is treated the same as the zero value. It is valid to call SignedURL for a key that does not exist. If the driver does not support this functionality

(ctx context.Context, key string, opts *SignedURLOptions)

Source from the content-addressed store, hash-verified

1299// If the driver does not support this functionality, SignedURL
1300// will return an error for which gcerrors.Code will return gcerrors.Unimplemented.
1301func (b *Bucket) SignedURL(ctx context.Context, key string, opts *SignedURLOptions) (string, error) {
1302 if !utf8.ValidString(key) {
1303 return "", gcerr.Newf(gcerr.InvalidArgument, nil, "blob: SignedURL key must be a valid UTF-8 string: %q", key)
1304 }
1305 dopts := new(driver.SignedURLOptions)
1306 if opts == nil {
1307 opts = new(SignedURLOptions)
1308 }
1309 switch {
1310 case opts.Expiry < 0:
1311 return "", gcerr.Newf(gcerr.InvalidArgument, nil, "blob: SignedURLOptions.Expiry must be >= 0 (%v)", opts.Expiry)
1312 case opts.Expiry == 0:
1313 dopts.Expiry = DefaultSignedURLExpiry
1314 default:
1315 dopts.Expiry = opts.Expiry
1316 }
1317 switch opts.Method {
1318 case "":
1319 dopts.Method = http.MethodGet
1320 case http.MethodGet, http.MethodPut, http.MethodDelete:
1321 dopts.Method = opts.Method
1322 default:
1323 return "", fmt.Errorf("blob: unsupported SignedURLOptions.Method %q", opts.Method)
1324 }
1325 if opts.ContentType != "" && opts.Method != http.MethodPut {
1326 return "", fmt.Errorf("blob: SignedURLOptions.ContentType must be empty for signing a %s URL", opts.Method)
1327 }
1328 if opts.EnforceAbsentContentType && opts.Method != http.MethodPut {
1329 return "", fmt.Errorf("blob: SignedURLOptions.EnforceAbsentContentType must be false for signing a %s URL", opts.Method)
1330 }
1331 dopts.ContentType = opts.ContentType
1332 dopts.EnforceAbsentContentType = opts.EnforceAbsentContentType
1333 dopts.BeforeSign = opts.BeforeSign
1334 b.mu.RLock()
1335 defer b.mu.RUnlock()
1336 if b.closed {
1337 return "", errClosed
1338 }
1339 sURL, err := b.b.SignedURL(ctx, key, dopts)
1340 return sURL, wrapError(b.b, err, key)
1341}
1342
1343// Close releases any resources used for the bucket.
1344func (b *Bucket) Close() error {

Callers 2

TestErrorsAreWrappedFunction · 0.95
TestBucketIsClosedFunction · 0.95

Calls 3

NewfFunction · 0.92
wrapErrorFunction · 0.70
SignedURLMethod · 0.65

Tested by 2

TestErrorsAreWrappedFunction · 0.76
TestBucketIsClosedFunction · 0.76