Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Commit 0bcb271

Browse files
committed
WIP
1 parent a018d00 commit 0bcb271

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// using BuildingOps.Data;
2+
// using Microsoft.AspNetCore.Builder;
3+
// using Microsoft.Extensions.DependencyInjection;
4+
//
5+
// namespace BuildingOps.Modules;
6+
//
7+
//
8+
// public class HealthChecksModule : IInfrastructureModule
9+
// {
10+
// public void Add(WebApplicationBuilder builder)
11+
// {
12+
// // https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-8.0
13+
// builder.Services
14+
// .AddHealthChecks()
15+
// .AddDbContextCheck<AppDbContext>();
16+
// }
17+
//
18+
//
19+
// public void Use(WebApplication app)
20+
// {
21+
// app
22+
// .MapHealthChecks("/health")
23+
// .RequireHost("*:5001");
24+
// // .RequireAuthorization()
25+
// }
26+
// }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Text;
2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.Extensions.DependencyInjection;
4+
5+
namespace Shiny.Modules;
6+
7+
public class JwtModule
8+
{
9+
public void Add(WebApplicationBuilder builder)
10+
{
11+
builder.Services.AddAuthorization();
12+
13+
// builder.Services.AddHealthChecks()
14+
// .AddNpgSql(builder.Configuration.GetConnectionString("DefaultConnection"));
15+
16+
var cfg = builder.Configuration;
17+
// builder
18+
// .Services
19+
// .AddAuthentication(options =>
20+
// {
21+
// options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
22+
// options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
23+
// options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
24+
// })
25+
// .AddJwtBearer(x => x.TokenValidationParameters = new TokenValidationParameters
26+
// {
27+
// ValidIssuer = cfg["Jwt:Issuer"],
28+
// ValidAudience = cfg["Jwt:Audience"],
29+
// IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(cfg["Jwt:Key"]!)),
30+
// ValidateIssuer = false, // TODO
31+
// ValidateAudience = false, // TODO
32+
// ValidateLifetime = true,
33+
// ValidateIssuerSigningKey = true
34+
// });
35+
}
36+
37+
public void Use(WebApplication app)
38+
{
39+
app.UseAuthentication();
40+
app.UseAuthorization();
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.RateLimiting;
3+
4+
namespace Shiny.Modules;
5+
6+
public class RateLimitModule : IInfrastructureModule
7+
{
8+
public void Add(WebApplicationBuilder builder)
9+
{
10+
11+
builder.Services.AddRateLimiter(options =>
12+
{
13+
options.AddFixedWindowLimiter("fixed", x =>
14+
{
15+
x.PermitLimit = 3;
16+
x.Window = TimeSpan.FromSeconds(3);
17+
x.QueueLimit = 2;
18+
});
19+
// options.GeneralRules.Add(new RateLimitRule
20+
// {
21+
// Endpoint = "*",
22+
// Period = "1m",
23+
// Limit = 100
24+
// });
25+
});
26+
}
27+
28+
29+
public void Use(WebApplication app) => app.UseRateLimiter();
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// using Microsoft.AspNetCore.Builder;
2+
// using Microsoft.Extensions.DependencyInjection;
3+
// using Microsoft.Extensions.Hosting;
4+
//
5+
// namespace BuildingOps.Modules;
6+
//
7+
//
8+
// public class SwaggerModule : IInfrastructureModule
9+
// {
10+
// public void Add(WebApplicationBuilder builder)
11+
// {
12+
// builder.Services.AddEndpointsApiExplorer();
13+
// builder.Services.AddSwaggerGen(x =>
14+
// {
15+
// // x.CustomOperationIds(y =>
16+
// // {
17+
// // });
18+
// x.CustomSchemaIds(y =>
19+
// {
20+
// var typeName = y.Name.Replace("`1", String.Empty);
21+
// var prefix = y.Namespace!.Substring(y.Namespace!.LastIndexOf(".") + 1);
22+
// if (prefix.Equals("Contracts"))
23+
// return typeName;
24+
//
25+
// var schemaId = $"{prefix}{typeName}";
26+
// return schemaId;
27+
// });
28+
// });
29+
// }
30+
//
31+
// public void Use(WebApplication app)
32+
// {
33+
// if (app.Environment.IsDevelopment())
34+
// {
35+
// app.UseSwagger();
36+
// app.UseSwaggerUI();
37+
// }
38+
// }
39+
// }

0 commit comments

Comments
 (0)