Compare commits
65
Commits
1.3
..
a185fe5e80
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a185fe5e80 | ||
|
|
24c8f81391 | ||
|
|
d38272d58a | ||
|
|
d219a7727f | ||
|
|
80f40cb99f | ||
|
|
8cdcaa55e9 | ||
|
|
66dd7c4b14 | ||
|
|
7125f5b909 | ||
|
|
b7c30fbfb5 | ||
|
|
6f913ce9d4 | ||
|
|
5c7ef3525f | ||
|
|
86da0d843e | ||
|
|
59710e32a6 | ||
|
|
5190fcaa17 | ||
|
|
d0afc4f748 | ||
|
|
9a96c0ad0c | ||
|
|
8cdfba58fd | ||
|
|
41e1c9da4c | ||
|
|
01d3aa90ea | ||
|
|
c3981fd859 | ||
|
|
8cc4425dfb | ||
|
|
60579c6230 | ||
|
|
f3478270fb | ||
|
|
1039f6f2d5 | ||
|
|
765eee2060 | ||
|
|
ee250a18f0 | ||
|
|
5972f8906b | ||
|
|
b90c6381a0 | ||
|
|
c65398bdf6 | ||
|
|
2958ca8c00 | ||
|
|
e546b3e7ff | ||
|
|
1132ba0401 | ||
|
|
5e119818bb | ||
|
|
181056d70d | ||
|
|
c01a02ee97 | ||
|
|
dfb5ce8a4b | ||
|
|
36b2f365d9 | ||
|
|
9bff28cec2 | ||
|
|
c76438b881 | ||
|
|
857173af25 | ||
|
|
e29c1ef6fc | ||
|
|
c8a4a4cb17 | ||
|
|
56e002875e | ||
|
|
d485e78498 | ||
|
|
ba3f8f6f9b | ||
|
|
815470ab07 | ||
|
|
16a2516816 | ||
|
|
8842d92b9b | ||
|
|
fc25d7ea40 | ||
|
|
8d8c1436f6 | ||
|
|
0c14872602 | ||
|
|
d0ec655085 | ||
|
|
3e23217eb4 | ||
|
|
17d2ac409b | ||
|
|
2d5614c504 | ||
|
|
5bb7c4a959 | ||
|
|
08af08d3dc | ||
|
|
8be8eb52bc | ||
|
|
8eedf16a49 | ||
|
|
db0715ceca | ||
|
|
fc2f457add | ||
|
|
60e916d972 | ||
|
|
851ca72b46 | ||
|
|
27418322f4 | ||
|
|
99a307527a |
@@ -31,6 +31,8 @@ steps:
|
|||||||
registry: nexus.khongisa.co.za
|
registry: nexus.khongisa.co.za
|
||||||
repo: nexus.khongisa.co.za/midrandbooks-api
|
repo: nexus.khongisa.co.za/midrandbooks-api
|
||||||
tags: [ latest, "1.${DRONE_BUILD_NUMBER}" ]
|
tags: [ latest, "1.${DRONE_BUILD_NUMBER}" ]
|
||||||
|
use_cache: true
|
||||||
|
cache_from: nexus.khongisa.co.za/midrandbooks-api:latest
|
||||||
custom_labels:
|
custom_labels:
|
||||||
- org.opencontainers.image.source=https://gitea.khongisa.co.za/litecharms/midrandbooks-api
|
- org.opencontainers.image.source=https://gitea.khongisa.co.za/litecharms/midrandbooks-api
|
||||||
- org.opencontainers.image.version=1.${DRONE_BUILD_NUMBER}
|
- org.opencontainers.image.version=1.${DRONE_BUILD_NUMBER}
|
||||||
|
|||||||
@@ -361,3 +361,4 @@ MigrationBackup/
|
|||||||
|
|
||||||
# Fody - auto-generated XML schema
|
# Fody - auto-generated XML schema
|
||||||
FodyWeavers.xsd
|
FodyWeavers.xsd
|
||||||
|
/MidrandBooksApi/http/http-client.env.json
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace MidrandBooksApi;
|
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
|
||||||
public sealed class ApiVersionTargetAttribute(int majorVersion) : Attribute
|
|
||||||
{
|
|
||||||
public int MajorVersion { get; } = majorVersion;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace MidrandBooksApi;
|
|
||||||
|
|
||||||
public static class EndpointTags
|
|
||||||
{
|
|
||||||
public const string Books = nameof(Books);
|
|
||||||
public const string Payments = nameof(Payments);
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace MidrandBooksApi;
|
|
||||||
|
|
||||||
public interface IEndpoint
|
|
||||||
{
|
|
||||||
void Map(IEndpointRouteBuilder builder);
|
|
||||||
}
|
|
||||||
@@ -14,8 +14,8 @@
|
|||||||
<PackageReference Include="IdentityModel.AspNetCore.OAuth2introspection" Version="6.2.0" />
|
<PackageReference Include="IdentityModel.AspNetCore.OAuth2introspection" Version="6.2.0" />
|
||||||
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
|
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
|
||||||
<PackageReference Include="IdentityModel" Version="6.2.0" />
|
<PackageReference Include="IdentityModel" Version="6.2.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Certificate" Version="10.0.8" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.Certificate" Version="10.0.9" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.8" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.9" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Health Checks -->
|
<!-- Health Checks -->
|
||||||
@@ -34,12 +34,13 @@
|
|||||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="10.0.0" />
|
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="10.0.0" />
|
||||||
|
|
||||||
<Using Include="Asp.Versioning" />
|
<Using Include="Asp.Versioning" />
|
||||||
|
<Using Include="Asp.Versioning.Builder" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- API Documentation -->
|
<!-- API Documentation -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.8" />
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.9" />
|
||||||
<PackageReference Include="Scalar.AspNetCore" Version="2.14.14" />
|
<PackageReference Include="Scalar.AspNetCore" Version="2.16.3" />
|
||||||
|
|
||||||
<Using Include="Scalar.AspNetCore" />
|
<Using Include="Scalar.AspNetCore" />
|
||||||
<Using Include="Microsoft.OpenApi" />
|
<Using Include="Microsoft.OpenApi" />
|
||||||
@@ -53,13 +54,13 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="LiteCharms.Features" Version="1.61.0" />
|
<PackageReference Include="LiteCharms.Features" Version="1.137.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- UI -->
|
<!-- UI -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ANM.Blazored.Toast" Version="0.1.1" />
|
<PackageReference Include="ANM.Blazored.Toast" Version="0.1.1" />
|
||||||
<PackageReference Include="LiteCharms.Features.MidrandBooks" Version="1.61.0" />
|
<PackageReference Include="LiteCharms.Features.MidrandBooks" Version="1.137.0" />
|
||||||
|
|
||||||
<!-- Global Usings -->
|
<!-- Global Usings -->
|
||||||
<Using Include="Blazored.Toast.Services" />
|
<Using Include="Blazored.Toast.Services" />
|
||||||
@@ -85,7 +86,11 @@
|
|||||||
|
|
||||||
<!-- Shared Global Usings -->
|
<!-- Shared Global Usings -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Using Include="System.Web" />
|
||||||
|
<Using Include="System.Diagnostics" />
|
||||||
<Using Include="System.Reflection" />
|
<Using Include="System.Reflection" />
|
||||||
|
<Using Include="Microsoft.AspNetCore.Mvc" />
|
||||||
|
<Using Include="System.ComponentModel.DataAnnotations" />
|
||||||
<Using Include="Microsoft.Extensions.DependencyInjection.Extensions" />
|
<Using Include="Microsoft.Extensions.DependencyInjection.Extensions" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
namespace MidrandBooksApi;
|
|
||||||
|
|
||||||
public sealed class OpenApiBearerSecuritySchemeTransformer : IOpenApiDocumentTransformer
|
|
||||||
{
|
|
||||||
public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransformerContext context, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var bearerScheme = new OpenApiSecurityScheme
|
|
||||||
{
|
|
||||||
Type = SecuritySchemeType.Http,
|
|
||||||
Scheme = "bearer",
|
|
||||||
Description = "JWT Authorization header using the Bearer scheme. Example: \"Bearer {token}\""
|
|
||||||
};
|
|
||||||
|
|
||||||
document.AddComponent("Bearer", bearerScheme);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
using LiteCharms.Features.Extensions;
|
|
||||||
using LiteCharms.Features.Hasher;
|
|
||||||
using LiteCharms.Features.Models;
|
|
||||||
|
|
||||||
namespace MidrandBooksApi.Payments.Endpoints;
|
|
||||||
|
|
||||||
[ApiVersionTarget(1)]
|
|
||||||
public sealed class ConfirmationEndpoint : IEndpoint
|
|
||||||
{
|
|
||||||
public void Map(IEndpointRouteBuilder builder)
|
|
||||||
{
|
|
||||||
builder.MapPost("payments/confirm", async (HttpRequest request, HashService hashService,
|
|
||||||
CancellationToken cancellationToken) =>
|
|
||||||
{
|
|
||||||
var formCollection = await request.ReadFormAsync(cancellationToken);
|
|
||||||
|
|
||||||
if (!formCollection.TryGetValue("signature", out var signatureValues) || string.IsNullOrWhiteSpace(signatureValues.ToString()))
|
|
||||||
return Results.BadRequest("Missing Payfast validation signature.");
|
|
||||||
|
|
||||||
string incomingSignature = signatureValues.ToString();
|
|
||||||
|
|
||||||
var payload = new PayfastWebhookPayload
|
|
||||||
{
|
|
||||||
Amount = formCollection.TryGetValue("amount", out var amountValues) ? amountValues.ToString() : null,
|
|
||||||
ItemName = formCollection.TryGetValue("item_name", out var itemValues) ? itemValues.ToString() : null,
|
|
||||||
MPaymentId = formCollection.TryGetValue("m_payment_id", out var paymentIdValues) ? paymentIdValues.ToString() : null
|
|
||||||
};
|
|
||||||
|
|
||||||
var validationResult = hashService.VerifyPayfastWebhookSignature(payload, incomingSignature);
|
|
||||||
|
|
||||||
return validationResult.IsFailed || !validationResult.Value
|
|
||||||
? Results.Unauthorized()
|
|
||||||
: Results.Ok();
|
|
||||||
})
|
|
||||||
.WithDescription("Securely confirm and process an incoming Payfast merchant payment callback.")
|
|
||||||
.WithName(typeof(ConfirmationEndpoint).ToEndpointName())
|
|
||||||
.MapToApiVersion(new ApiVersion(1))
|
|
||||||
.Produces(StatusCodes.Status200OK)
|
|
||||||
.Produces(StatusCodes.Status400BadRequest)
|
|
||||||
.Produces(StatusCodes.Status401Unauthorized)
|
|
||||||
.WithTags(EndpointTags.Payments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
using LiteCharms.Features.Abstractions;
|
||||||
|
using LiteCharms.Features.Api;
|
||||||
|
using LiteCharms.Features.Extensions;
|
||||||
|
using LiteCharms.Features.MidrandBooks.Payments;
|
||||||
|
using LiteCharms.Features.MidrandBooks.Payments.Events;
|
||||||
|
using LiteCharms.Features.MidrandBooks.Payments.Models;
|
||||||
|
using static LiteCharms.Features.Extensions.Api;
|
||||||
|
|
||||||
|
namespace MidrandBooksApi.Payments.Payfast;
|
||||||
|
|
||||||
|
[ApiVersionTarget(1)]
|
||||||
|
public sealed class PayfastConfirmationEndpoint : IEndpoint
|
||||||
|
{
|
||||||
|
private static readonly ActivitySource PaymentActivitySource = new("MidrandBooksApi.Payments");
|
||||||
|
|
||||||
|
public void Map(IEndpointRouteBuilder builder)
|
||||||
|
{
|
||||||
|
builder.MapPost("payments/payfast/confirm", async (HttpRequest request, PayfastService payfastService,
|
||||||
|
IJobOrchestrator jobOrchestrator, IConfiguration configuration, IHostEnvironment hostEnvironment,
|
||||||
|
ILogger<PayfastConfirmationEndpoint> logger, CancellationToken cancellationToken) =>
|
||||||
|
{
|
||||||
|
using Activity? activity = PaymentActivitySource.StartActivity("ReceivePayfastWebhook", ActivityKind.Server);
|
||||||
|
|
||||||
|
activity?.SetTag("messaging.system", "payfast");
|
||||||
|
activity?.SetTag("messaging.destination.name", "payments/payfast/confirm");
|
||||||
|
|
||||||
|
var formCollection = await request.ReadFormAsync(cancellationToken);
|
||||||
|
|
||||||
|
if (!formCollection.TryGetValue("signature", out var signatureValues) || string.IsNullOrWhiteSpace(signatureValues.ToString()))
|
||||||
|
return Results.BadRequest("Missing Payfast validation signature.");
|
||||||
|
|
||||||
|
string incomingSignature = signatureValues.ToString().Trim();
|
||||||
|
var payload = ParseForm(formCollection, incomingSignature);
|
||||||
|
|
||||||
|
string? passphrase = configuration["PayfastSettings:Passphrase"];
|
||||||
|
|
||||||
|
if (!PayfastService.VerifyIncomingSignatureFromForm(formCollection, passphrase!))
|
||||||
|
{
|
||||||
|
logger.LogCritical($"Incoming signature failed validation: {incomingSignature}");
|
||||||
|
|
||||||
|
return Results.Unauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
var sortedPairs = formCollection
|
||||||
|
.Where(kvp => !kvp.Key.Equals("signature", StringComparison.OrdinalIgnoreCase))
|
||||||
|
.OrderBy(kvp => kvp.Key, StringComparer.Ordinal)
|
||||||
|
.Select(kvp => $"{kvp.Key}={HttpUtility.UrlEncode(kvp.Value.ToString().Trim())}");
|
||||||
|
|
||||||
|
string rawQueryParamString = string.Join("&", sortedPairs);
|
||||||
|
|
||||||
|
bool isSandbox = !hostEnvironment.IsProduction();
|
||||||
|
var serverConfirmation = await payfastService.ValidateServerConfirmationAsync(rawQueryParamString, isSandbox, cancellationToken);
|
||||||
|
|
||||||
|
if (serverConfirmation.IsFailed || !serverConfirmation.Value)
|
||||||
|
{
|
||||||
|
logger.LogCritical($"Payfast server validation ping rejected the request data: {rawQueryParamString}");
|
||||||
|
|
||||||
|
return Results.Unauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
var notification = PayfastPaymentConfirmationReceivedEvent.Create(payload, payload.MerchantPaymentId!,
|
||||||
|
allowLoopback: !hostEnvironment.IsProduction(), performBackgroundChecks: false);
|
||||||
|
|
||||||
|
await jobOrchestrator.SendAsync(notification, cancellationToken);
|
||||||
|
|
||||||
|
activity?.SetStatus(ActivityStatusCode.Ok);
|
||||||
|
return Results.Ok();
|
||||||
|
})
|
||||||
|
.WithDescription("Securely confirm and process an incoming Payfast merchant payment callback.")
|
||||||
|
.WithName(typeof(PayfastConfirmationEndpoint).ToEndpointName())
|
||||||
|
.MapToApiVersion(new ApiVersion(1))
|
||||||
|
.Produces(StatusCodes.Status200OK)
|
||||||
|
.Produces(StatusCodes.Status400BadRequest)
|
||||||
|
.Produces(StatusCodes.Status401Unauthorized)
|
||||||
|
.WithTags(Api.Payments);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PayfastWebhookPayload ParseForm(IFormCollection formCollection, string incomingSignature) => new()
|
||||||
|
{
|
||||||
|
MerchantId = formCollection.TryGetValue("merchant_id", out var mId) ? mId.ToString() : null,
|
||||||
|
MerchantKey = formCollection.TryGetValue("merchant_key", out var mKey) ? mKey.ToString() : null,
|
||||||
|
Signature = incomingSignature,
|
||||||
|
MerchantPaymentId = formCollection.TryGetValue("m_payment_id", out var mPayId) ? mPayId.ToString() : null,
|
||||||
|
PaymentId = formCollection.TryGetValue("pf_payment_id", out var pfPayId) ? pfPayId.ToString() : null,
|
||||||
|
PaymentStatus = formCollection.TryGetValue("payment_status", out var status) ? status.ToString() : null,
|
||||||
|
ItemName = formCollection.TryGetValue("item_name", out var item) ? item.ToString() : null,
|
||||||
|
ItemDescription = formCollection.TryGetValue("item_description", out var desc) ? desc.ToString() : null,
|
||||||
|
AmountGross = formCollection.TryGetValue("amount_gross", out var gross) ? gross.ToString() : null,
|
||||||
|
AmountFee = formCollection.TryGetValue("amount_fee", out var fee) ? fee.ToString() : null,
|
||||||
|
AmountNet = formCollection.TryGetValue("amount_net", out var net) ? net.ToString() : null,
|
||||||
|
NameFirst = formCollection.TryGetValue("name_first", out var first) ? first.ToString() : null,
|
||||||
|
NameLast = formCollection.TryGetValue("name_last", out var last) ? last.ToString() : null,
|
||||||
|
EmailAddress = formCollection.TryGetValue("email_address", out var email) ? email.ToString() : null,
|
||||||
|
CustomStr1 = formCollection.TryGetValue("custom_str1", out var cStr1) ? cStr1.ToString() : null,
|
||||||
|
CustomInt1 = formCollection.TryGetValue("custom_int1", out var cInt1) ? cInt1.ToString() : null,
|
||||||
|
Token = formCollection.TryGetValue("token", out var tok) ? tok.ToString() : null
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
using Asp.Versioning.Builder;
|
|
||||||
using k8s.Models;
|
|
||||||
using LiteCharms.Features.Extensions;
|
using LiteCharms.Features.Extensions;
|
||||||
using LiteCharms.Features.Mediator;
|
using LiteCharms.Features.Mediator;
|
||||||
using LiteCharms.Features.MidrandBooks.Extensions;
|
using LiteCharms.Features.MidrandBooks.Extensions;
|
||||||
using MidrandBooksApi;
|
|
||||||
using static LiteCharms.Features.Extensions.Quartz;
|
using static LiteCharms.Features.Extensions.Quartz;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@@ -14,10 +11,8 @@ builder.Services.AddEndpointsApiExplorer();
|
|||||||
builder.Services.AddEndpoints(Assembly.GetExecutingAssembly());
|
builder.Services.AddEndpoints(Assembly.GetExecutingAssembly());
|
||||||
builder.Services.AddApiServices(builder.Configuration);
|
builder.Services.AddApiServices(builder.Configuration);
|
||||||
|
|
||||||
builder.Services.AddAuthorization();
|
|
||||||
builder.Services.AddAuthentication();
|
|
||||||
|
|
||||||
builder.Services.AddMediator();
|
builder.Services.AddMediator();
|
||||||
|
builder.Services.AddLiteCharmsApiSecurity(builder.Configuration);
|
||||||
|
|
||||||
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(TelemetryPipelineBehavior<,>));
|
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(TelemetryPipelineBehavior<,>));
|
||||||
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(LoggingPipelineBehavior<,>));
|
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(LoggingPipelineBehavior<,>));
|
||||||
@@ -27,7 +22,9 @@ builder.Services.AddQuartzSchedulerClient(MidrandShopSchedulerName, builder.Conf
|
|||||||
builder.Services.AddEmailServices(builder.Configuration);
|
builder.Services.AddEmailServices(builder.Configuration);
|
||||||
builder.Services.AddEmailServiceBus();
|
builder.Services.AddEmailServiceBus();
|
||||||
|
|
||||||
|
builder.Services.AddHttpClient();
|
||||||
builder.Services.AddShopServices();
|
builder.Services.AddShopServices();
|
||||||
|
builder.Services.AddPayfastServices(builder.Configuration);
|
||||||
builder.Services.AddHashServices(builder.Configuration);
|
builder.Services.AddHashServices(builder.Configuration);
|
||||||
builder.Services.AddMidrandShopDatabase(builder.Configuration);
|
builder.Services.AddMidrandShopDatabase(builder.Configuration);
|
||||||
|
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
namespace MidrandBooksApi;
|
|
||||||
|
|
||||||
public static class Setup
|
|
||||||
{
|
|
||||||
public static IApplicationBuilder MapEndpoints(this WebApplication app, Dictionary<int, RouteGroupBuilder> versionGroups)
|
|
||||||
{
|
|
||||||
var endpoints = app.Services.GetRequiredService<IEnumerable<IEndpoint>>();
|
|
||||||
|
|
||||||
foreach (var endpoint in endpoints)
|
|
||||||
{
|
|
||||||
var versionAttributes = endpoint.GetType().GetCustomAttributes<ApiVersionTargetAttribute>().ToList();
|
|
||||||
|
|
||||||
if (versionAttributes.Count != 0)
|
|
||||||
{
|
|
||||||
foreach (var attr in versionAttributes)
|
|
||||||
if (versionGroups.TryGetValue(attr.MajorVersion, out var targetGroup))
|
|
||||||
endpoint.Map(targetGroup);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
endpoint.Map(app);
|
|
||||||
}
|
|
||||||
|
|
||||||
return app;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IServiceCollection AddEndpoints(this IServiceCollection services, Assembly assembly)
|
|
||||||
{
|
|
||||||
ServiceDescriptor[] discriptors = [.. assembly.DefinedTypes
|
|
||||||
.Where(t => t is { IsInterface: false, IsAbstract: false })
|
|
||||||
.Where(t => t.IsAssignableTo(typeof(IEndpoint)))
|
|
||||||
.Select(t => ServiceDescriptor.Transient(typeof(IEndpoint), t))];
|
|
||||||
|
|
||||||
services.TryAddEnumerable(discriptors);
|
|
||||||
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string ToEndpointName(this Type target, string? annotation = "") =>
|
|
||||||
$"{target.Name.Replace("Endpoint", string.Empty)}{annotation}".ToLower();
|
|
||||||
|
|
||||||
public static IServiceCollection AddApiServices(this IServiceCollection services, IConfiguration configuration)
|
|
||||||
{
|
|
||||||
services.AddApiVersioning(options =>
|
|
||||||
{
|
|
||||||
options.DefaultApiVersion = new ApiVersion(1);
|
|
||||||
options.ReportApiVersions = true;
|
|
||||||
options.AssumeDefaultVersionWhenUnspecified = true;
|
|
||||||
options.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader(),
|
|
||||||
new QueryStringApiVersionReader("version"),
|
|
||||||
new QueryStringApiVersionReader("version"),
|
|
||||||
new MediaTypeApiVersionReader("version"));
|
|
||||||
})
|
|
||||||
.AddApiExplorer(options =>
|
|
||||||
{
|
|
||||||
options.GroupNameFormat = "'v'VVV";
|
|
||||||
options.SubstituteApiVersionInUrl = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
var urls = configuration["ASPNETCORE_URLS"] ?? configuration["Urls"];
|
|
||||||
var healthUrl = "http://localhost:8080/health";
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(urls))
|
|
||||||
{
|
|
||||||
string firstUrl = urls.Split(';').FirstOrDefault(s => s.Contains("http://"))!
|
|
||||||
.Replace("*", "localhost").Replace("+", "localhost");
|
|
||||||
|
|
||||||
healthUrl = $"{firstUrl.TrimEnd('/')}/health";
|
|
||||||
}
|
|
||||||
|
|
||||||
services.AddHealthChecksUI(setup =>
|
|
||||||
{
|
|
||||||
setup.SetNotifyUnHealthyOneTimeUntilChange();
|
|
||||||
setup.AddHealthCheckEndpoint("primary, heal", healthUrl);
|
|
||||||
setup.SetHeaderText("Midrand Books");
|
|
||||||
})
|
|
||||||
.AddInMemoryStorage();
|
|
||||||
|
|
||||||
services.AddOutputCache(options =>
|
|
||||||
{
|
|
||||||
options.AddBasePolicy(builder => builder.Cache());
|
|
||||||
options.DefaultExpirationTimeSpan = TimeSpan.FromSeconds(10);
|
|
||||||
});
|
|
||||||
|
|
||||||
services.AddOpenApi(options => options.AddDocumentTransformer<OpenApiBearerSecuritySchemeTransformer>());
|
|
||||||
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,20 @@
|
|||||||
{
|
{
|
||||||
|
"PayfastSettings": {
|
||||||
|
"CheckoutUrl": "https://sandbox.payfast.co.za/eng/process",
|
||||||
|
"ValidHosts": [
|
||||||
|
"www.payfast.co.za",
|
||||||
|
"sandbox.payfast.co.za",
|
||||||
|
"w1w.payfast.co.za",
|
||||||
|
"w2w.payfast.co.za",
|
||||||
|
"ips.payfast.co.za",
|
||||||
|
"api.payfast.co.za",
|
||||||
|
"payment.payfast.io"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"LiteCharmsSettings": {
|
||||||
|
"Authority": "https://sts.security.khongisa.co.za",
|
||||||
|
"Audience": "midrandbooks-api"
|
||||||
|
},
|
||||||
"HasherSettings": {
|
"HasherSettings": {
|
||||||
"MinHashLength": 11
|
"MinHashLength": 11
|
||||||
},
|
},
|
||||||
@@ -9,7 +25,6 @@
|
|||||||
"CdnBaseUrl": "https://bookshop.cdn.khongisa.co.za"
|
"CdnBaseUrl": "https://bookshop.cdn.khongisa.co.za"
|
||||||
},
|
},
|
||||||
"Monitoring": {
|
"Monitoring": {
|
||||||
"ApiKey": "",
|
|
||||||
"Address": "http://aspire-dashboard-service.aspire.svc.cluster.local:18889",
|
"Address": "http://aspire-dashboard-service.aspire.svc.cluster.local:18889",
|
||||||
"ServiceName": "MidrandBooks.DEV"
|
"ServiceName": "MidrandBooks.DEV"
|
||||||
},
|
},
|
||||||
|
|||||||
+12
-52
@@ -19,21 +19,14 @@ data:
|
|||||||
BookshopS3Settings__Region: "garage"
|
BookshopS3Settings__Region: "garage"
|
||||||
BookshopS3Settings__BucketName: "bookshop"
|
BookshopS3Settings__BucketName: "bookshop"
|
||||||
BookshopS3Settings__CdnBaseUrl: "https://bookshop.cdn.khongisa.co.za"
|
BookshopS3Settings__CdnBaseUrl: "https://bookshop.cdn.khongisa.co.za"
|
||||||
---
|
PayfastSettings__CheckoutUrl: "https://sandbox.payfast.co.za/eng/process"
|
||||||
apiVersion: v1
|
PayfastSettings__ValidHosts__0: "www.payfast.co.za"
|
||||||
kind: Secret
|
PayfastSettings__ValidHosts__1: "sandbox.payfast.co.za"
|
||||||
metadata:
|
PayfastSettings__ValidHosts__2: "ips.payfast.co.za"
|
||||||
name: midrandbooksapi-secrets
|
PayfastSettings__ValidHosts__3: "api.payfast.co.za"
|
||||||
namespace: midrandbooksapi-uat
|
PayfastSettings__ValidHosts__4: "payment.payfast.io"
|
||||||
type: Opaque
|
LiteCharmsSettings__Authority: "https://sts.security.khongisa.co.za"
|
||||||
data:
|
LiteCharmsSettings__Audience: "midrandbooks-api"
|
||||||
connection-string: SG9zdD0xOTIuMTY4LjEuMTcwO0RhdGFiYXNlPW1pZHJhbmRzaG9wLWRldjtVc2VybmFtZT1taWRyYW5kc2hvcC1kZXYtdXNlcjtQYXNzd29yZD1hUFh5a0tnM3RTOWNtRDtQZXJzaXN0IFNlY3VyaXR5IEluZm89VHJ1ZQ==
|
|
||||||
connection-string-quartz: SG9zdD0xOTIuMTY4LjEuMTcwO0RhdGFiYXNlPXNjaGVkdWxlci1kZXY7VXNlcm5hbWU9c2NoZWR1bGVyLWRldi11c2VyO1Bhc3N3b3JkPWtWVm1vV0tKM3h6Z1FYO1BlcnNpc3QgU2VjdXJpdHkgSW5mbz1UcnVl
|
|
||||||
aspire-apikey: bWMzRzYzSzJqNVpPRXNpMEFqTW9qTFRYbTFLRVpGY3R6SUlqU3dEaVRHdXQ4cUdTa1B1V3d4R1AxUmJzY0pVbw==
|
|
||||||
hasher-salt: VEdsbmFIUWdRMmhoY20xekxDQk5hV1J5WVc1a1FtOXZhM01nYldGclpTQnNiM1J6SUc5bUlHMXZibVY1SUdGdVpDQmhjbVVnWVNCemRXTmpaWE56Wm5Wc0lIWnBjbUZzSUhOMGIzSjVJR2x1SUZOdmRYUm9JRUZtY21sallRPT0=
|
|
||||||
hasher-payfastpassphrase: OUdBSVIwdFdwaFgwcU8=
|
|
||||||
bookshop-s3-accesskey: R0s1MTRkMmNlOGRjNjkyMzdhMDVjMDFlZWY=
|
|
||||||
bookshop-s3-secretkey: ZWFhZmVkYTFhZWQ0MDllY2ZlNjA3MTRlY2RhNTQ5YjgyYmRmNWEzZGFmOWYxOGRkNjFmNjZiNDk3M2E2NDgyZQ==
|
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: PersistentVolumeClaim
|
kind: PersistentVolumeClaim
|
||||||
@@ -54,6 +47,7 @@ metadata:
|
|||||||
namespace: midrandbooksapi-uat
|
namespace: midrandbooksapi-uat
|
||||||
spec:
|
spec:
|
||||||
replicas: 2
|
replicas: 2
|
||||||
|
revisionHistoryLimit: 0
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: midrandbooks-api
|
app: midrandbooks-api
|
||||||
@@ -85,42 +79,8 @@ spec:
|
|||||||
envFrom:
|
envFrom:
|
||||||
- configMapRef:
|
- configMapRef:
|
||||||
name: midrandbooksapi-config
|
name: midrandbooksapi-config
|
||||||
env:
|
- secretRef:
|
||||||
- name: BookshopS3Settings__AccessKey
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: midrandbooksapi-secrets
|
name: midrandbooksapi-secrets
|
||||||
key: bookshop-s3-accesskey
|
|
||||||
- name: BookshopS3Settings__SecretKey
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: midrandbooksapi-secrets
|
|
||||||
key: bookshop-s3-secretkey
|
|
||||||
- name: HasherSettings__Salt
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: midrandbooksapi-secrets
|
|
||||||
key: hasher-salt
|
|
||||||
- name: HasherSettings__PayfastPassphrase
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: midrandbooksapi-secrets
|
|
||||||
key: hasher-payfastpassphrase
|
|
||||||
- name: ConnectionStrings__PostgresScheduler
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: midrandbooksapi-secrets
|
|
||||||
key: connection-string-quartz
|
|
||||||
- name: ConnectionStrings__PostgresMidrandBooks
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: midrandbooksapi-secrets
|
|
||||||
key: connection-string
|
|
||||||
- name: Monitoring__ApiKey
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: midrandbooksapi-secrets
|
|
||||||
key: aspire-apikey
|
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: data
|
- name: data
|
||||||
mountPath: /app/wwwroot/content
|
mountPath: /app/wwwroot/content
|
||||||
@@ -129,8 +89,8 @@ spec:
|
|||||||
httpGet:
|
httpGet:
|
||||||
path: /health
|
path: /health
|
||||||
port: 8080
|
port: 8080
|
||||||
initialDelaySeconds: 5
|
initialDelaySeconds: 10
|
||||||
periodSeconds: 10
|
periodSeconds: 15
|
||||||
readinessProbe:
|
readinessProbe:
|
||||||
httpGet:
|
httpGet:
|
||||||
path: /health
|
path: /health
|
||||||
|
|||||||
Reference in New Issue
Block a user