Beispiel #1
0
        private static async Task <PutBucketResponse> CreateIfNotExistsAsync(
            AWSS3StorageCacheOptions options,
            S3CannedACL acl)
        {
            AmazonS3Client client = AmazonS3ClientFactory.CreateClient(options);

            bool foundBucket = false;
            ListBucketsResponse listBucketsResponse = await client.ListBucketsAsync();

            foreach (S3Bucket b in listBucketsResponse.Buckets)
            {
                if (b.BucketName == options.BucketName)
                {
                    foundBucket = true;
                    break;
                }
            }

            if (!foundBucket)
            {
                var putBucketRequest = new PutBucketRequest
                {
                    BucketName   = options.BucketName,
                    BucketRegion = options.Region,
                    CannedACL    = acl
                };

                return(await client.PutBucketAsync(putBucketRequest));
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AWSS3StorageCache"/> class.
        /// </summary>
        /// <param name="cacheOptions">The cache options.</param>
        public AWSS3StorageCache(IOptions <AWSS3StorageCacheOptions> cacheOptions)
        {
            Guard.NotNull(cacheOptions, nameof(cacheOptions));
            AWSS3StorageCacheOptions options = cacheOptions.Value;

            this.bucket         = options.BucketName;
            this.amazonS3Client = AmazonS3ClientFactory.CreateClient(options);
        }
Beispiel #3
0
 /// <summary>
 /// Creates a new bucket under the specified account if a bucket
 /// with the same name does not already exist.
 /// </summary>
 /// <param name="options">The AWS S3 Storage cache options.</param>
 /// <param name="acl">
 /// Specifies whether data in the bucket may be accessed publicly and the level of access.
 /// <see cref="S3CannedACL.PublicRead"/> specifies full public read access for bucket
 /// and object data. <see cref="S3CannedACL.Private"/> specifies that the bucket
 /// data is private to the account owner.
 /// </param>
 /// <returns>
 /// If the bucket does not already exist, a <see cref="PutBucketResponse"/> describing the newly
 /// created bucket. If the container already exists, <see langword="null"/>.
 /// </returns>
 public static PutBucketResponse CreateIfNotExists(
     AWSS3StorageCacheOptions options,
     S3CannedACL acl)
 => AsyncHelper.RunSync(() => CreateIfNotExistsAsync(options, acl));