diff options
author | vnugent <public@vaughnnugent.com> | 2023-03-09 01:48:39 -0500 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-03-09 01:48:39 -0500 |
commit | cc199f9748e2ac4b5434fdd707e1f4945ad1d623 (patch) | |
tree | abf9c9c6fc020146dafbc0ed256f6314b77e8abf /lib/Emails.Transactional.Plugin/src | |
parent | 7bdb0d637665c0699e802fd05271bc3df2aa4d8a (diff) |
Omega cache, session, and account provider complete overhaul
Diffstat (limited to 'lib/Emails.Transactional.Plugin/src')
3 files changed, 21 insertions, 29 deletions
diff --git a/lib/Emails.Transactional.Plugin/src/Api Endpoints/SendEndpoint.cs b/lib/Emails.Transactional.Plugin/src/Api Endpoints/SendEndpoint.cs index 9bcc966..e5ca88b 100644 --- a/lib/Emails.Transactional.Plugin/src/Api Endpoints/SendEndpoint.cs +++ b/lib/Emails.Transactional.Plugin/src/Api Endpoints/SendEndpoint.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: Transactional Emails @@ -26,7 +26,6 @@ using System; using System.IO; using System.Net; using System.Text; -using System.Text.Json; using System.Threading.Tasks; using System.Collections.Generic; @@ -94,7 +93,7 @@ namespace Emails.Transactional.Endpoints private SmtpProvider? EmailService; - public SendEndpoint(PluginBase plugin, IReadOnlyDictionary<string, JsonElement> config) + public SendEndpoint(PluginBase plugin, IConfigScope config) { string? path = config["path"].GetString(); FromAddress = config["from_address"].GetString() ?? throw new KeyNotFoundException("Missing required key 'from_address' in 'transaction_endpoint'"); @@ -105,13 +104,13 @@ namespace Emails.Transactional.Endpoints //Smtp setup { - IReadOnlyDictionary<string, JsonElement> smtp = plugin.GetConfig("smtp"); + IConfigScope smtp = plugin.GetConfig("smtp"); Uri serverUri = new(smtp["server_address"].GetString()!); string username = smtp["username"].GetString() ?? throw new KeyNotFoundException("Missing required key 'usename' in 'smtp' config"); TimeSpan timeout = smtp["timeout_sec"].GetTimeSpan(TimeParseType.Seconds); //Load SMTP - _ = plugin.ObserveTask(async () => + _ = plugin.ObserveWork(async () => { using SecretResult? password = await plugin.TryGetSecretAsync("smtp_password") ?? throw new KeyNotFoundException("Missing required 'smtp_password' in secrets"); //Copy the secre to the network credential @@ -129,24 +128,25 @@ namespace Emails.Transactional.Endpoints Client = new(); //Load the client when the secret finishes loading - _ = plugin.ObserveTask(async () => + _ = plugin.ObserveWork(async () => { using SecretResult? secret = await plugin.TryGetSecretAsync("s3_secret") ?? throw new KeyNotFoundException("Missing required s3 client secret in config"); + Client.WithEndpoint(S3Config.ServerAddress) .WithCredentials(S3Config.ClientId, secret.Result.ToString()); - if (S3Config.UseSsl == true) - { - Client.WithSSL(); - } + Client.WithSSL(S3Config.UseSsl.HasValue && S3Config.UseSsl.Value); + //Accept optional region if (!string.IsNullOrWhiteSpace(S3Config.Region)) { Client.WithRegion(S3Config.Region); } + //Build client Client.Build(); + //If the plugin is in debug mode, log requests to logger if (plugin.IsDebug()) { @@ -161,6 +161,7 @@ namespace Emails.Transactional.Endpoints TemplateCache = new(20, StringComparer.OrdinalIgnoreCase); } + protected override async ValueTask<VfReturnType> PostAsync(HttpEntity entity) { //Make sure the user has the required scope to send an email @@ -182,6 +183,7 @@ namespace Emails.Transactional.Endpoints { Success = false }; + //Set a default from name/address if not set by user transaction.From ??= FromAddress; transaction.FromName ??= FromAddress; diff --git a/lib/Emails.Transactional.Plugin/src/TEmailEntryPoint.cs b/lib/Emails.Transactional.Plugin/src/TEmailEntryPoint.cs index c95ca08..8e7319a 100644 --- a/lib/Emails.Transactional.Plugin/src/TEmailEntryPoint.cs +++ b/lib/Emails.Transactional.Plugin/src/TEmailEntryPoint.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: Transactional Emails @@ -61,17 +61,10 @@ namespace Emails.Transactional protected override void OnLoad() { - try - { - //Route send oauth endpoint - this.Route<SendEndpoint>(); + //Route send oauth endpoint + this.Route<SendEndpoint>(); - Log.Information("Plugin loaded"); - } - catch (KeyNotFoundException kne) - { - Log.Warn("Missing required configuration keys {err}", kne.Message); - } + Log.Information("Plugin loaded"); } diff --git a/lib/Emails.Transactional.Plugin/src/Transactional Emails.csproj b/lib/Emails.Transactional.Plugin/src/Transactional Emails.csproj index 267987d..0d628f8 100644 --- a/lib/Emails.Transactional.Plugin/src/Transactional Emails.csproj +++ b/lib/Emails.Transactional.Plugin/src/Transactional Emails.csproj @@ -5,8 +5,9 @@ <RootNamespace>Emails.Transactional</RootNamespace> <AssemblyName>Emails.Transactional</AssemblyName> <Nullable>enable</Nullable> - - <Version>1.0.0.1</Version> + + <!-- Resolve nuget dll files and store them in the output dir --> + <EnableDynamicLoading>true</EnableDynamicLoading> </PropertyGroup> @@ -21,10 +22,6 @@ </Description> </PropertyGroup> - <!-- Resolve nuget dll files and store them in the output dir --> - <PropertyGroup> - <EnableDynamicLoading>true</EnableDynamicLoading> - </PropertyGroup> <ItemGroup> <PackageReference Include="ErrorProne.NET.CoreAnalyzers" Version="0.1.2"> @@ -35,8 +32,8 @@ <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> - <PackageReference Include="Fluid.Core" Version="2.3.1" /> - <PackageReference Include="MailKit" Version="3.5.0" /> + <PackageReference Include="Fluid.Core" Version="2.4.0" /> + <PackageReference Include="MailKit" Version="3.6.0" /> <PackageReference Include="Minio" Version="4.0.7" /> </ItemGroup> |