From 0163a2da97a574d3aaca40dc1680b46a9f97eb13 Mon Sep 17 00:00:00 2001 From: Jarek Kowalski Date: Sat, 15 Feb 2020 12:38:24 -0800 Subject: [PATCH] blob: check that GCS/S3 bucket is present when the storage is opened --- repo/blob/gcs/gcs_storage.go | 5 +++++ repo/blob/s3/s3_storage.go | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/repo/blob/gcs/gcs_storage.go b/repo/blob/gcs/gcs_storage.go index b0fc0fb02..600eebebc 100644 --- a/repo/blob/gcs/gcs_storage.go +++ b/repo/blob/gcs/gcs_storage.go @@ -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, diff --git a/repo/blob/s3/s3_storage.go b/repo/blob/s3/s3_storage.go index f9194680a..27261e7a6 100644 --- a/repo/blob/s3/s3_storage.go +++ b/repo/blob/s3/s3_storage.go @@ -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,