Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #253 from JensDll/staging
Browse files Browse the repository at this point in the history
github-actions: merge staging into main
  • Loading branch information
JensDll committed Jun 1, 2023
2 parents 287fdb9 + 00fb211 commit edd0a72
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
50 changes: 28 additions & 22 deletions services/aspnet.common/src/aspnet.common/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Security.Cryptography.X509Certificates;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace aspnet.common;

Expand All @@ -22,32 +22,38 @@ public static IServiceCollection AddAspNetShared(this IServiceCollection service

public static void ConfigureCertificate(this WebHostBuilderContext context, KestrelServerOptions serverOptions)
{
if (context.HostingEnvironment.IsDevelopment())
IConfigurationSection kestrelSection =
context.Configuration.GetRequiredSection(options.kestrel.KestrelServerOptions.Section);

IConfigurationSection httpsSection = kestrelSection.GetSection("Endpoints:Https");

if (!httpsSection.Exists())
{
return;
}

serverOptions.Configure(context.Configuration.GetRequiredSection(options.kestrel.KestrelServerOptions.Section))
.Endpoint("Https", endpoint =>
KestrelConfigurationLoader loader = serverOptions.Configure(kestrelSection);

loader.Endpoint("Https", endpoint =>
{
string certPath =
endpoint.ConfigSection.GetValue<string>("Path") ??
throw new InvalidOperationException(
"Failed to find certificate path on https endpoint configuration");
string keyPath =
endpoint.ConfigSection.GetValue<string>("KeyPath") ??
throw new InvalidOperationException(
"Failed to find key path on https endpoint configuration");
X509Certificate2 certificate = X509Certificate2.CreateFromPemFile(certPath, keyPath);
endpoint.ListenOptions.UseHttps(certificate, httpsOptions =>
{
string certPath =
endpoint.ConfigSection.GetValue<string>("Path") ??
throw new InvalidOperationException(
"Failed to find certificate path on https endpoint configuration");
string keyPath =
endpoint.ConfigSection.GetValue<string>("KeyPath") ??
throw new InvalidOperationException(
"Failed to find key path on https endpoint configuration");
X509Certificate2 certificate = X509Certificate2.CreateFromPemFile(certPath, keyPath);
endpoint.ListenOptions.UseHttps(certificate, httpsOptions =>
{
X509Certificate2Collection chain = new();
chain.ImportFromPemFile(certPath);
httpsOptions.ServerCertificateChain = chain;
});
X509Certificate2Collection chain = new();
chain.ImportFromPemFile(certPath);
httpsOptions.ServerCertificateChain = chain;
});
});
}
}
2 changes: 1 addition & 1 deletion services/steganography.api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ USER appuser:appgroup

ENV ASPNETCORE_URLS=""

EXPOSE 8443
EXPOSE 8080 8443

ENTRYPOINT ["dotnet", "steganography.api.dll"]

0 comments on commit edd0a72

Please sign in to comment.