blob: check that GCS/S3 bucket is present when the storage is opened

This commit is contained in:
Jarek Kowalski
2020-02-15 12:38:24 -08:00
parent a9670762fd
commit 0163a2da97
2 changed files with 14 additions and 0 deletions

View File

@@ -267,6 +267,11 @@ func New(ctx context.Context, opt *Options) (blob.Storage, error) {
return nil, errors.New("bucket name must be specified")
}
// make sure the bucket exists
if _, err := cli.Bucket(opt.BucketName).Attrs(ctx); err != nil {
return nil, errors.Wrap(err, "unable to read bucket")
}
return &gcsStorage{
Options: *opt,
ctx: ctx,

View File

@@ -233,6 +233,15 @@ func New(ctx context.Context, opt *Options) (blob.Storage, error) {
downloadThrottler := iothrottler.NewIOThrottlerPool(toBandwidth(opt.MaxDownloadSpeedBytesPerSecond))
uploadThrottler := iothrottler.NewIOThrottlerPool(toBandwidth(opt.MaxUploadSpeedBytesPerSecond))
ok, err := cli.BucketExistsWithContext(ctx, opt.BucketName)
if err != nil {
return nil, errors.Wrapf(err, "unable to determine if bucket %q exists", opt.BucketName)
}
if !ok {
return nil, errors.Errorf("bucket %q does not exist", opt.BucketName)
}
return &s3Storage{
Options: *opt,
ctx: ctx,