Align .editorconfig files

When debugging only
app.Services.GetRequiredService<IPCRBService>();

Injected AppSettings instead of using GetEnvironmentVariable at Services level

Get ready to use VSCode IDE
This commit is contained in:
2024-12-03 12:23:56 -07:00
parent 89790f4fc1
commit 538b1f817e
72 changed files with 3420 additions and 391 deletions

View File

@ -1,17 +1,24 @@
using MesaFabApproval.Shared.Services;
using NLog.Web;
using MesaFabApprovalAPI.Services;
using Microsoft.OpenApi.Models;
using dotenv.net;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using System.Text;
using Microsoft.AspNetCore.Authorization;
using MesaFabApproval.API.Services;
using NLog.Extensions.Logging;
using MesaFabApproval.API.Clients;
using System.Diagnostics;
using System.Net.Mail;
using System.Text;
using dotenv.net;
using MesaFabApproval.API.Clients;
using MesaFabApproval.API.Services;
using MesaFabApproval.Models;
using MesaFabApproval.Shared.Services;
using MesaFabApprovalAPI.Services;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.HttpLogging;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using NLog.Extensions.Logging;
using NLog.Web;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
@ -21,7 +28,7 @@ builder.Logging.ClearProviders();
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Logging.AddNLog();
/*builder.Services.AddHttpLogging(o => {
/*builder.Services.AddHttpLogging(o => {
o.LoggingFields = HttpLoggingFields.All;
o.RequestHeaders.Add("bearer");
o.MediaTypeOptions.AddText("application/javascript");
@ -32,25 +39,28 @@ builder.Logging.AddNLog();
builder.Services.AddMemoryCache();
string jwtIssuer = Environment.GetEnvironmentVariable("FabApprovalJwtIssuer") ??
throw new ArgumentNullException("FabApprovalJwtIssuer environment variable not found");
string jwtAudience = Environment.GetEnvironmentVariable("FabApprovalJwtAudience") ??
throw new ArgumentNullException("FabApprovalJwtAudience environment variable not found");
string jwtKey = Environment.GetEnvironmentVariable("FabApprovalJwtKey") ??
throw new ArgumentNullException("FabApprovalJwtKey environment variable not found");
if (Debugger.IsAttached) {
string? jwtIssuer = Environment.GetEnvironmentVariable("FabApprovalJwtIssuer");
if (string.IsNullOrEmpty(jwtIssuer)) {
AppSettings.SetEnvironmentVariables(builder);
}
}
builder.Services.AddAuthentication(options => {
AppSettings appSettings = AppSettings.LoadEnvironmentVariables();
builder.Services.AddSingleton(_ => appSettings);
builder.Services.AddAuthentication(options => {
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options => {
.AddJwtBearer(options => {
options.RequireHttpsMetadata = false;
options.SaveToken = true;
options.TokenValidationParameters = new TokenValidationParameters {
ValidateIssuerSigningKey = true,
ValidIssuer = jwtIssuer,
ValidIssuer = appSettings.JwtIssuer,
ValidateAudience = false,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtKey)),
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(appSettings.JwtKey)),
ClockSkew = TimeSpan.Zero
};
});
@ -122,11 +132,13 @@ builder.Services.AddSwaggerGen(c => {
WebApplication app = builder.Build();
if (Debugger.IsAttached)
app.Services.GetRequiredService<IApprovalService>();
app.UseCors();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
if (app.Environment.IsDevelopment()) {
app.UseSwagger();
app.UseSwaggerUI();
}