diff --git a/Notesnook.API/Notesnook.API.csproj b/Notesnook.API/Notesnook.API.csproj index d98ad61..8f4d496 100644 --- a/Notesnook.API/Notesnook.API.csproj +++ b/Notesnook.API/Notesnook.API.csproj @@ -8,6 +8,7 @@ + diff --git a/Notesnook.API/Services/S3Service.cs b/Notesnook.API/Services/S3Service.cs index a9e6b30..9487019 100644 --- a/Notesnook.API/Services/S3Service.cs +++ b/Notesnook.API/Services/S3Service.cs @@ -28,6 +28,7 @@ using Amazon.Runtime; using Amazon.S3; using Amazon.S3.Model; using Microsoft.Extensions.Options; +using MongoDB.Driver; using Notesnook.API.Helpers; using Notesnook.API.Interfaces; using Notesnook.API.Models; @@ -65,18 +66,7 @@ namespace Notesnook.API.Services public S3Service(ISyncItemsRepositoryAccessor syncItemsRepositoryAccessor) { Repositories = syncItemsRepositoryAccessor; - var config = new AmazonS3Config - { -#if (DEBUG || STAGING) - ServiceURL = Servers.S3Server.ToString(), -#else - ServiceURL = Constants.S3_SERVICE_URL, - AuthenticationRegion = Constants.S3_REGION, -#endif - ForcePathStyle = true, - SignatureMethod = SigningAlgorithm.HmacSHA256, - SignatureVersion = "4" - }; + var config = CreateConfig(); #if (DEBUG || STAGING) S3Client = new AmazonS3Client("S3RVER", "S3RVER", config); #else @@ -98,6 +88,22 @@ namespace Notesnook.API.Services AWSConfigsS3.UseSignatureVersion4 = true; } + public static AmazonS3Config CreateConfig() + { + return new AmazonS3Config + { +#if (DEBUG || STAGING) + ServiceURL = Servers.S3Server.ToString(), +#else + ServiceURL = Constants.S3_SERVICE_URL, + AuthenticationRegion = Constants.S3_REGION, +#endif + ForcePathStyle = true, + SignatureMethod = SigningAlgorithm.HmacSHA256, + SignatureVersion = "4" + }; + } + public async Task DeleteObjectAsync(string userId, string name) { var objectName = GetFullObjectName(userId, name) ?? throw new Exception("Invalid object name."); diff --git a/Notesnook.API/Startup.cs b/Notesnook.API/Startup.cs index 872c088..de4511e 100644 --- a/Notesnook.API/Startup.cs +++ b/Notesnook.API/Startup.cs @@ -24,6 +24,7 @@ using System.Security.Claims; using System.Text; using System.Text.Encodings.Web; using System.Threading.Tasks; +using Amazon.Runtime; using IdentityModel.AspNetCore.OAuth2Introspection; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.JwtBearer; @@ -39,6 +40,7 @@ using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -198,7 +200,13 @@ namespace Notesnook.API services.AddControllers(); - services.AddHealthChecks(); // .AddMongoDb(dbSettings.ConnectionString, dbSettings.DatabaseName, "database-check"); + services.AddHealthChecks().AddS3((options) => + { + options.Credentials = new BasicAWSCredentials(Constants.S3_ACCESS_KEY_ID, Constants.S3_ACCESS_KEY); + options.S3Config = S3Service.CreateConfig(); + options.BucketName = Constants.S3_BUCKET_NAME; + }, "s3-check", HealthStatus.Degraded).AddMongoDb(Constants.MONGODB_CONNECTION_STRING, "mongodb-check", HealthStatus.Unhealthy); + services.AddSignalR((hub) => { hub.MaximumReceiveMessageSize = 100 * 1024 * 1024;