-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from andyfelton-equatedigital/feat/AWSProvider
Feat/aws AWS S3 provider
- Loading branch information
Showing
30 changed files
with
1,128 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Submodule shared-infrastructure
updated
4 files
+7 −2 | .gitattributes | |
+11 −0 | codecov.yml | |
+1 −1 | msbuild/props/SixLabors.Tests.props | |
+1 −1 | msbuild/targets/SixLabors.Src.targets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
using System; | ||
using Amazon; | ||
using Amazon.S3; | ||
using SixLabors.ImageSharp.Web.Providers.AWS; | ||
|
||
namespace SixLabors.ImageSharp.Web | ||
{ | ||
internal static class AmazonS3ClientFactory | ||
{ | ||
/// <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> | ||
/// <returns> | ||
/// A new <see cref="AmazonS3Client"/>. | ||
/// </returns> | ||
public static AmazonS3Client CreateClient(AWSS3BucketClientOptions options) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(options.Endpoint)) | ||
{ | ||
// AccessKey can be empty. | ||
// AccessSecret can be empty. | ||
AmazonS3Config config = new() { ServiceURL = options.Endpoint, ForcePathStyle = true }; | ||
return new AmazonS3Client(options.AccessKey, options.AccessSecret, config); | ||
} | ||
else if (!string.IsNullOrWhiteSpace(options.AccessKey)) | ||
{ | ||
// AccessSecret can be empty. | ||
Guard.NotNullOrWhiteSpace(options.Region, nameof(options.Region)); | ||
var region = RegionEndpoint.GetBySystemName(options.Region); | ||
return new AmazonS3Client(options.AccessKey, options.AccessSecret, region); | ||
} | ||
else if (!string.IsNullOrWhiteSpace(options.Region)) | ||
{ | ||
var region = RegionEndpoint.GetBySystemName(options.Region); | ||
return new AmazonS3Client(region); | ||
} | ||
else | ||
{ | ||
throw new ArgumentException("Invalid configuration.", nameof(options)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
using System; | ||
using System.Globalization; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SixLabors.ImageSharp.Web | ||
{ | ||
/// <summary> | ||
/// <see href="https://github.com/aspnet/AspNetIdentity/blob/b7826741279450c58b230ece98bd04b4815beabf/src/Microsoft.AspNet.Identity.Core/AsyncHelper.cs"/> | ||
/// </summary> | ||
internal static class AsyncHelper | ||
{ | ||
private static readonly TaskFactory TaskFactory = new | ||
(CancellationToken.None, | ||
TaskCreationOptions.None, | ||
TaskContinuationOptions.None, | ||
TaskScheduler.Default); | ||
|
||
/// <summary> | ||
/// Executes an async <see cref="Task"/> method synchronously. | ||
/// </summary> | ||
/// <param name="task">The task to excecute.</param> | ||
public static void RunSync(Func<Task> task) | ||
{ | ||
CultureInfo cultureUi = CultureInfo.CurrentUICulture; | ||
CultureInfo culture = CultureInfo.CurrentCulture; | ||
TaskFactory.StartNew(() => | ||
{ | ||
Thread.CurrentThread.CurrentCulture = culture; | ||
Thread.CurrentThread.CurrentUICulture = cultureUi; | ||
return task(); | ||
}).Unwrap().GetAwaiter().GetResult(); | ||
} | ||
|
||
/// <summary> | ||
/// Executes an async <see cref="Task{TResult}"/> method which has | ||
/// a <paramref name="task"/> return type synchronously. | ||
/// </summary> | ||
/// <typeparam name="TResult">The type of result to return.</typeparam> | ||
/// <param name="task">The task to excecute.</param> | ||
/// <returns>The <typeparamref name="TResult"/>.</returns> | ||
public static TResult RunSync<TResult>(Func<Task<TResult>> task) | ||
{ | ||
CultureInfo cultureUi = CultureInfo.CurrentUICulture; | ||
CultureInfo culture = CultureInfo.CurrentCulture; | ||
return TaskFactory.StartNew(() => | ||
{ | ||
Thread.CurrentThread.CurrentCulture = culture; | ||
Thread.CurrentThread.CurrentUICulture = cultureUi; | ||
return task(); | ||
}).Unwrap().GetAwaiter().GetResult(); | ||
} | ||
} | ||
} |
Oops, something went wrong.