Skip to content

Commit

Permalink
Merge pull request #209 from andyfelton-equatedigital/feat/AWSProvider
Browse files Browse the repository at this point in the history
Feat/aws AWS S3 provider
  • Loading branch information
JimBobSquarePants authored Jan 31, 2022
2 parents 9c0231e + aaf0b62 commit df19a19
Show file tree
Hide file tree
Showing 30 changed files with 1,128 additions and 120 deletions.
9 changes: 7 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,13 @@
*.eot binary
*.exe binary
*.otf binary
*.pbm binary
*.pdf binary
*.ppt binary
*.pptx binary
*.pvr binary
*.snk binary
*.ttc binary
*.ttf binary
*.wbmp binary
*.woff binary
*.woff2 binary
*.xls binary
Expand Down Expand Up @@ -126,3 +124,10 @@
*.dds filter=lfs diff=lfs merge=lfs -text
*.ktx filter=lfs diff=lfs merge=lfs -text
*.ktx2 filter=lfs diff=lfs merge=lfs -text
*.pam filter=lfs diff=lfs merge=lfs -text
*.pbm filter=lfs diff=lfs merge=lfs -text
*.pgm filter=lfs diff=lfs merge=lfs -text
*.ppm filter=lfs diff=lfs merge=lfs -text
*.pnm filter=lfs diff=lfs merge=lfs -text
*.wbmp filter=lfs diff=lfs merge=lfs -text
*.exr filter=lfs diff=lfs merge=lfs -text
14 changes: 14 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ jobs:
npm install -g azurite
azurite --loose &
- name: Setup s3rver
if: matrix.options.os != 'windows-latest'
shell: bash
run: |
sudo npm install -g s3rver
sudo s3rver -d . &
- name: Setup s3rver Windows
if: matrix.options.os == 'windows-latest'
shell: bash
run: |
npm install -g s3rver
s3rver -d . &
- name: Setup NuGet Cache
uses: actions/cache@v2
id: nuget-cache
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
Expand Down Expand Up @@ -214,7 +214,7 @@ artifacts/
*.csproj.bak

#CodeCoverage
*.lcov
*.lcov

**/is-cache/

Expand Down
16 changes: 16 additions & 0 deletions ImageSharp.Web.sln
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Web.Benchmarks",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Web.Providers.Azure", "src\ImageSharp.Web.Providers.Azure\ImageSharp.Web.Providers.Azure.csproj", "{E2A545EC-B909-4EAD-B95F-397F68588BE3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Web.Providers.AWS", "src\ImageSharp.Web.Providers.AWS\ImageSharp.Web.Providers.AWS.csproj", "{E631D300-ACD5-40EA-A6BB-08E22092EC76}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{B8152C86-B657-4967-B297-42F89A10D23A}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SharedInfrastructure", "shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.shproj", "{68A8CC40-6AED-4E96-B524-31B1158FDEEA}"
Expand Down Expand Up @@ -69,6 +71,7 @@ Global
shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{2f1b36e2-5d92-4442-b816-d2a978246435}*SharedItemsImports = 5
shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{68a8cc40-6aed-4e96-b524-31b1158fdeea}*SharedItemsImports = 13
shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{e2a545ec-b909-4ead-b95f-397f68588be3}*SharedItemsImports = 5
shared-infrastructure\src\SharedInfrastructure\SharedInfrastructure.projitems*{e631d300-acd5-40ea-a6bb-08e22092ec76}*SharedItemsImports = 5
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -127,6 +130,18 @@ Global
{E2A545EC-B909-4EAD-B95F-397F68588BE3}.Release|x64.Build.0 = Release|Any CPU
{E2A545EC-B909-4EAD-B95F-397F68588BE3}.Release|x86.ActiveCfg = Release|Any CPU
{E2A545EC-B909-4EAD-B95F-397F68588BE3}.Release|x86.Build.0 = Release|Any CPU
{E631D300-ACD5-40EA-A6BB-08E22092EC76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E631D300-ACD5-40EA-A6BB-08E22092EC76}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E631D300-ACD5-40EA-A6BB-08E22092EC76}.Debug|x64.ActiveCfg = Debug|Any CPU
{E631D300-ACD5-40EA-A6BB-08E22092EC76}.Debug|x64.Build.0 = Debug|Any CPU
{E631D300-ACD5-40EA-A6BB-08E22092EC76}.Debug|x86.ActiveCfg = Debug|Any CPU
{E631D300-ACD5-40EA-A6BB-08E22092EC76}.Debug|x86.Build.0 = Debug|Any CPU
{E631D300-ACD5-40EA-A6BB-08E22092EC76}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E631D300-ACD5-40EA-A6BB-08E22092EC76}.Release|Any CPU.Build.0 = Release|Any CPU
{E631D300-ACD5-40EA-A6BB-08E22092EC76}.Release|x64.ActiveCfg = Release|Any CPU
{E631D300-ACD5-40EA-A6BB-08E22092EC76}.Release|x64.Build.0 = Release|Any CPU
{E631D300-ACD5-40EA-A6BB-08E22092EC76}.Release|x86.ActiveCfg = Release|Any CPU
{E631D300-ACD5-40EA-A6BB-08E22092EC76}.Release|x86.Build.0 = Release|Any CPU
{8F40DEC6-A97F-4002-A504-13E188665A98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F40DEC6-A97F-4002-A504-13E188665A98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F40DEC6-A97F-4002-A504-13E188665A98}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -148,6 +163,7 @@ Global
{8864C96C-94AA-454D-BAF5-779216C3745A} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
{0B15E490-7821-42DF-86A5-4DEAE921DE59} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
{E2A545EC-B909-4EAD-B95F-397F68588BE3} = {815C0625-CD3D-440F-9F80-2D83856AB7AE}
{E631D300-ACD5-40EA-A6BB-08E22092EC76} = {815C0625-CD3D-440F-9F80-2D83856AB7AE}
{B8152C86-B657-4967-B297-42F89A10D23A} = {C317F1B1-D75E-4C6D-83EB-80367343E0D7}
{68A8CC40-6AED-4E96-B524-31B1158FDEEA} = {815C0625-CD3D-440F-9F80-2D83856AB7AE}
{04955CD1-F249-4899-9F61-6C7487BEECE1} = {B8152C86-B657-4967-B297-42F89A10D23A}
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,26 @@ git submodule update --init --recursive

#### Running the Tests

The unit tests require [Azurite Azure Storage Emulator](https://github.com/Azure/Azurite) in order to run.
The unit tests require [Azurite Azure Storage Emulator](https://github.com/Azure/Azurite) and [s3rver](https://github.com/jamhall/s3rver) in order to run.

On Windows to install and run the server as a background process run the following command

```bash
npm install -g azurite
start /B azurite --loose

npm install -g s3rver
start /B s3rver -d .
```

On Linux

```bash
sudo npm install -g azurite
sudo azurite --loose &

sudo npm install -g s3rver
sudo s3rver -d . &
```

## How can you help?
Expand All @@ -112,4 +118,4 @@ Please... Spread the word, contribute algorithms, submit performance improvement
- [Dirk Lemstra](https://github.com/dlemstra)
- [Anton Firsov](https://github.com/antonfirsov)
- [Scott Williams](https://github.com/tocsoft)
- [Brian Popow](https://github.com/brianpopow)
- [Brian Popow](https://github.com/brianpopow)
11 changes: 11 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ codecov:
# Avoid Report Expired
# https://docs.codecov.io/docs/codecov-yaml#section-expired-reports
max_report_age: off

coverage:
# Use integer precision
# https://docs.codecov.com/docs/codecovyml-reference#coverageprecision
precision: 0

# Explicitly control coverage status checks
# https://docs.codecov.com/docs/commit-status#disabling-a-status
status:
project: on
patch: off
Binary file modified samples/ImageSharp.Web.Sample/wwwroot/imagesharp-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<Import Project="$(MSBuildThisFileDirectory)..\Directory.Build.targets" />

<ItemGroup>
<PackageReference Update="AWSSDK.S3" Version="3.7.7.16" />
<PackageReference Update="Azure.Storage.Blobs" Version="12.10.0" />
<PackageReference Update="Microsoft.IO.RecyclableMemoryStream" Version="2.2.0" />
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
Expand Down
48 changes: 48 additions & 0 deletions src/ImageSharp.Web.Providers.AWS/AmazonS3ClientFactory.cs
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));
}
}
}
}
57 changes: 57 additions & 0 deletions src/ImageSharp.Web.Providers.AWS/AsyncHelper.cs
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();
}
}
}
Loading

0 comments on commit df19a19

Please sign in to comment.