Skip to content

Commit d3a834f

Browse files
Merge pull request #219 from SixLabors/js/aws-options
Separate AWS cache options and normalize implementations
2 parents 376c0e6 + c480a6f commit d3a834f

9 files changed

Lines changed: 109 additions & 49 deletions

File tree

src/ImageSharp.Web.Providers.AWS/AmazonS3ClientFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using Amazon;
66
using Amazon.S3;
7-
using SixLabors.ImageSharp.Web.Providers.AWS;
87

98
namespace SixLabors.ImageSharp.Web
109
{
@@ -18,7 +17,7 @@ internal static class AmazonS3ClientFactory
1817
/// <returns>
1918
/// A new <see cref="AmazonS3Client"/>.
2019
/// </returns>
21-
public static AmazonS3Client CreateClient(AWSS3BucketClientOptions options)
20+
public static AmazonS3Client CreateClient(IAWSS3BucketClientOptions options)
2221
{
2322
if (!string.IsNullOrWhiteSpace(options.Endpoint))
2423
{

src/ImageSharp.Web.Providers.AWS/Caching/AWSS3StorageCache.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Amazon.S3;
88
using Amazon.S3.Model;
99
using Microsoft.Extensions.Options;
10-
using SixLabors.ImageSharp.Web.Providers.AWS;
1110
using SixLabors.ImageSharp.Web.Resolvers;
1211
using SixLabors.ImageSharp.Web.Resolvers.AWS;
1312

@@ -25,10 +24,10 @@ public class AWSS3StorageCache : IImageCache
2524
/// Initializes a new instance of the <see cref="AWSS3StorageCache"/> class.
2625
/// </summary>
2726
/// <param name="cacheOptions">The cache options.</param>
28-
public AWSS3StorageCache(IOptions<AWSS3BucketClientOptions> cacheOptions)
27+
public AWSS3StorageCache(IOptions<AWSS3StorageCacheOptions> cacheOptions)
2928
{
3029
Guard.NotNull(cacheOptions, nameof(cacheOptions));
31-
AWSS3BucketClientOptions options = cacheOptions.Value;
30+
AWSS3StorageCacheOptions options = cacheOptions.Value;
3231
this.bucket = options.BucketName;
3332
this.amazonS3Client = AmazonS3ClientFactory.CreateClient(options);
3433
}
@@ -85,12 +84,12 @@ public Task SetAsync(string key, Stream stream, ImageCacheMetadata metadata)
8584
/// created bucket. If the container already exists, <see langword="null"/>.
8685
/// </returns>
8786
public static PutBucketResponse CreateIfNotExists(
88-
AWSS3BucketClientOptions options,
87+
AWSS3StorageCacheOptions options,
8988
S3CannedACL acl)
9089
=> AsyncHelper.RunSync(() => CreateIfNotExistsAsync(options, acl));
9190

9291
private static async Task<PutBucketResponse> CreateIfNotExistsAsync(
93-
AWSS3BucketClientOptions options,
92+
AWSS3StorageCacheOptions options,
9493
S3CannedACL acl)
9594
{
9695
AmazonS3Client client = AmazonS3ClientFactory.CreateClient(options);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
namespace SixLabors.ImageSharp.Web.Caching.AWS
5+
{
6+
/// <summary>
7+
/// Configuration options for the <see cref="AWSS3StorageCache"/> provider.
8+
/// </summary>
9+
public class AWSS3StorageCacheOptions : IAWSS3BucketClientOptions
10+
{
11+
/// <inheritdoc/>
12+
public string Region { get; set; }
13+
14+
/// <inheritdoc/>
15+
public string BucketName { get; set; }
16+
17+
/// <inheritdoc/>
18+
public string AccessKey { get; set; }
19+
20+
/// <inheritdoc/>
21+
public string AccessSecret { get; set; }
22+
23+
/// <inheritdoc/>
24+
public string Endpoint { get; set; }
25+
}
26+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
namespace SixLabors.ImageSharp.Web
5+
{
6+
/// <summary>
7+
/// Provides a common interface for AWS S3 Bucket Client Options.
8+
/// </summary>
9+
internal interface IAWSS3BucketClientOptions
10+
{
11+
/// <summary>
12+
/// Gets or sets the AWS region endpoint (us-east-1/us-west-1/ap-southeast-2).
13+
/// </summary>
14+
string Region { get; set; }
15+
16+
/// <summary>
17+
/// Gets or sets the AWS bucket name.
18+
/// </summary>
19+
string BucketName { get; set; }
20+
21+
/// <summary>
22+
/// Gets or sets the AWS key - Can be used to override keys provided by the environment.
23+
/// If deploying inside an EC2 instance AWS keys will already be available via environment
24+
/// variables and don't need to be specified. Follow AWS best security practices on <see href="https://docs.aws.amazon.com/general/latest/gr/aws-access-keys-best-practices.html"/>.
25+
/// </summary>
26+
string AccessKey { get; set; }
27+
28+
/// <summary>
29+
/// Gets or sets the AWS secret - Can be used to override keys provided by the environment.
30+
/// If deploying inside an EC2 instance AWS keys will already be available via environment
31+
/// variables and don't need to be specified. Follow AWS best security practices on <see href="https://docs.aws.amazon.com/general/latest/gr/aws-access-keys-best-practices.html"/>.
32+
/// </summary>
33+
string AccessSecret { get; set; }
34+
35+
/// <summary>
36+
/// Gets or sets the AWS endpoint - used for testing to over region endpoint allowing it
37+
/// to be set to localhost.
38+
/// </summary>
39+
string Endpoint { get; set; }
40+
}
41+
}

src/ImageSharp.Web.Providers.AWS/Providers/AWSS3StorageImageProviderOptions.cs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,21 @@ public class AWSS3StorageImageProviderOptions
1919
/// <summary>
2020
/// Configuration options for the <see cref="AWSS3StorageImageProvider"/> provider.
2121
/// </summary>
22-
public class AWSS3BucketClientOptions
22+
public class AWSS3BucketClientOptions : IAWSS3BucketClientOptions
2323
{
24-
/// <summary>
25-
/// Gets or sets the AWS region endpoint (us-east-1/us-west-1/ap-southeast-2).
26-
/// </summary>
24+
/// <inheritdoc/>
2725
public string Region { get; set; }
2826

29-
/// <summary>
30-
/// Gets or sets the AWS bucket name.
31-
/// </summary>
27+
/// <inheritdoc/>
3228
public string BucketName { get; set; }
3329

34-
/// <summary>
35-
/// Gets or sets the AWS key - Can be used to override keys provided by the environment.
36-
/// If deploying inside an EC2 instance AWS keys will already be available via environment
37-
/// variables and don't need to be specified. Follow AWS best security practices on <see href="https://docs.aws.amazon.com/general/latest/gr/aws-access-keys-best-practices.html"/>.
38-
/// </summary>
30+
/// <inheritdoc/>
3931
public string AccessKey { get; set; }
4032

41-
/// <summary>
42-
/// Gets or sets the AWS secret - Can be used to override keys provided by the environment.
43-
/// If deploying inside an EC2 instance AWS keys will already be available via environment
44-
/// variables and don't need to be specified. Follow AWS best security practices on <see href="https://docs.aws.amazon.com/general/latest/gr/aws-access-keys-best-practices.html"/>.
45-
/// </summary>
33+
/// <inheritdoc/>
4634
public string AccessSecret { get; set; }
4735

48-
/// <summary>
49-
/// Gets or sets the AWS endpoint - used for testing to over region endpoint allowing it
50-
/// to be set to localhost.
51-
/// </summary>
36+
/// <inheritdoc/>
5237
public string Endpoint { get; set; }
5338
}
5439
}

src/ImageSharp.Web.Providers.Azure/Caching/AzureBlobStorageCacheOptions.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,12 @@ namespace SixLabors.ImageSharp.Web.Caching.Azure
66
/// <summary>
77
/// Configuration options for the <see cref="AzureBlobStorageCache"/>.
88
/// </summary>
9-
public class AzureBlobStorageCacheOptions
9+
public class AzureBlobStorageCacheOptions : IAzureBlobContainerClientOptions
1010
{
11-
/// <summary>
12-
/// Gets or sets the Azure Blob Storage connection string.
13-
/// <see href="https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string."/>
14-
/// </summary>
11+
/// <inheritdoc/>
1512
public string ConnectionString { get; set; }
1613

17-
/// <summary>
18-
/// Gets or sets the Azure Blob Storage container name.
19-
/// Must conform to Azure Blob Storage containiner naming guidlines.
20-
/// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#container-names"/>
21-
/// </summary>
14+
/// <inheritdoc/>
2215
public string ContainerName { get; set; }
2316
}
2417
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
namespace SixLabors.ImageSharp.Web
5+
{
6+
/// <summary>
7+
/// Provides a common interface for Azure Blob Container Options.
8+
/// </summary>
9+
internal interface IAzureBlobContainerClientOptions
10+
{
11+
/// <summary>
12+
/// Gets or sets the Azure Blob Storage connection string.
13+
/// <see href="https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string."/>
14+
/// </summary>
15+
public string ConnectionString { get; set; }
16+
17+
/// <summary>
18+
/// Gets or sets the Azure Blob Storage container name.
19+
/// Must conform to Azure Blob Storage container naming guidlines.
20+
/// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#container-names"/>
21+
/// </summary>
22+
public string ContainerName { get; set; }
23+
}
24+
}

src/ImageSharp.Web.Providers.Azure/Providers/AzureBlobStorageImageProviderOptions.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,12 @@ public class AzureBlobStorageImageProviderOptions
1919
/// <summary>
2020
/// Represents a single Azure Blob Storage connection and container.
2121
/// </summary>
22-
public class AzureBlobContainerClientOptions
22+
public class AzureBlobContainerClientOptions : IAzureBlobContainerClientOptions
2323
{
24-
/// <summary>
25-
/// Gets or sets the Azure Blob Storage connection string.
26-
/// <see href="https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string."/>
27-
/// </summary>
24+
/// <inheritdoc/>
2825
public string ConnectionString { get; set; }
2926

30-
/// <summary>
31-
/// Gets or sets the Azure Blob Storage container name.
32-
/// Must conform to Azure Blob Storage containiner naming guidlines.
33-
/// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#container-names"/>
34-
/// </summary>
27+
/// <inheritdoc/>
3528
public string ContainerName { get; set; }
3629
}
3730
}

tests/ImageSharp.Web.Tests/TestUtilities/AWSS3StorageCacheTestServerFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected override void ConfigureServices(IServiceCollection services) =>
8888
.AddProvider(AWSS3StorageImageProviderFactory.Create)
8989
.AddProvider<PhysicalFileSystemProvider>()
9090
.AddProcessor<CacheBusterWebProcessor>()
91-
.Configure<AWSS3BucketClientOptions>(options =>
91+
.Configure<AWSS3StorageCacheOptions>(options =>
9292
{
9393
options.Endpoint = TestConstants.AWSEndpoint;
9494
options.BucketName = TestConstants.AWSCacheBucketName;

0 commit comments

Comments
 (0)