S3BinaryCacheStore: Don't create buckets

This meant that making a typo in an s3:// URI would cause a bucket to
be created. Also it didn't handle eventual consistency very well. Now
it's up to the user to create the bucket.
This commit is contained in:
Eelco Dolstra 2018-09-27 21:32:25 +02:00
parent f74e0b4786
commit 63786cbd3b
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -19,8 +19,6 @@
#include <aws/core/utils/logging/LogMacros.h> #include <aws/core/utils/logging/LogMacros.h>
#include <aws/core/utils/threading/Executor.h> #include <aws/core/utils/threading/Executor.h>
#include <aws/s3/S3Client.h> #include <aws/s3/S3Client.h>
#include <aws/s3/model/CreateBucketRequest.h>
#include <aws/s3/model/GetBucketLocationRequest.h>
#include <aws/s3/model/GetObjectRequest.h> #include <aws/s3/model/GetObjectRequest.h>
#include <aws/s3/model/HeadObjectRequest.h> #include <aws/s3/model/HeadObjectRequest.h>
#include <aws/s3/model/ListObjectsRequest.h> #include <aws/s3/model/ListObjectsRequest.h>
@ -202,32 +200,6 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore
{ {
if (!diskCache->cacheExists(getUri(), wantMassQuery_, priority)) { if (!diskCache->cacheExists(getUri(), wantMassQuery_, priority)) {
/* Create the bucket if it doesn't already exists. */
// FIXME: HeadBucket would be more appropriate, but doesn't return
// an easily parsed 404 message.
auto res = s3Helper.client->GetBucketLocation(
Aws::S3::Model::GetBucketLocationRequest().WithBucket(bucketName));
if (!res.IsSuccess()) {
if (res.GetError().GetErrorType() != Aws::S3::S3Errors::NO_SUCH_BUCKET)
throw Error(format("AWS error checking bucket '%s': %s") % bucketName % res.GetError().GetMessage());
printInfo("creating S3 bucket '%s'...", bucketName);
// Stupid S3 bucket locations.
auto bucketConfig = Aws::S3::Model::CreateBucketConfiguration();
if (s3Helper.config->region != "us-east-1")
bucketConfig.SetLocationConstraint(
Aws::S3::Model::BucketLocationConstraintMapper::GetBucketLocationConstraintForName(
s3Helper.config->region));
checkAws(format("AWS error creating bucket '%s'") % bucketName,
s3Helper.client->CreateBucket(
Aws::S3::Model::CreateBucketRequest()
.WithBucket(bucketName)
.WithCreateBucketConfiguration(bucketConfig)));
}
BinaryCacheStore::init(); BinaryCacheStore::init();
diskCache->createCache(getUri(), storeDir, wantMassQuery_, priority); diskCache->createCache(getUri(), storeDir, wantMassQuery_, priority);