New project file, added Aspire, moved security
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
using MicCheck.Api.Common;
|
||||
using MicCheck.Api.Environments;
|
||||
using MicCheck.Api.Projects;
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
using MicCheck.Api.Users;
|
||||
|
||||
namespace MicCheck.Api.Authorization;
|
||||
|
||||
public interface ITokenService
|
||||
{
|
||||
TokenResponse GenerateToken(User user);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
namespace MicCheck.Api.Authorization;
|
||||
|
||||
public record LogoutRequest(string Token);
|
||||
@@ -1,3 +0,0 @@
|
||||
namespace MicCheck.Api.Authorization;
|
||||
|
||||
public record RefreshRequest(string Token);
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace MicCheck.Api.ApiKeys;
|
||||
namespace MicCheck.Api.Common.Security.ApiKeys;
|
||||
|
||||
public class ApiKey
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
namespace MicCheck.Api.ApiKeys;
|
||||
namespace MicCheck.Api.Common.Security.ApiKeys;
|
||||
|
||||
public static class ApiKeyEndpoints
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace MicCheck.Api.ApiKeys;
|
||||
namespace MicCheck.Api.Common.Security.ApiKeys;
|
||||
|
||||
public static class ApiKeyHasher
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace MicCheck.Api.ApiKeys;
|
||||
namespace MicCheck.Api.Common.Security.ApiKeys;
|
||||
|
||||
public record ApiKeyResponse(
|
||||
int Id,
|
||||
@@ -1,7 +1,7 @@
|
||||
using MicCheck.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MicCheck.Api.ApiKeys;
|
||||
namespace MicCheck.Api.Common.Security.ApiKeys;
|
||||
|
||||
public class ApiKeyService(MicCheckDbContext db)
|
||||
{
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace MicCheck.Api.ApiKeys;
|
||||
namespace MicCheck.Api.Common.Security.ApiKeys;
|
||||
|
||||
public record CreateApiKeyRequest(string Name, DateTimeOffset? ExpiresAt);
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace MicCheck.Api.ApiKeys;
|
||||
namespace MicCheck.Api.Common.Security.ApiKeys;
|
||||
|
||||
public record CreateApiKeyResponse(
|
||||
int Id,
|
||||
@@ -1,18 +1,14 @@
|
||||
using System.Security.Claims;
|
||||
using System.Text.Encodings.Web;
|
||||
using MicCheck.Api.ApiKeys;
|
||||
using MicCheck.Api.Common.Security.ApiKeys;
|
||||
using MicCheck.Api.Data;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace MicCheck.Api.Authentication;
|
||||
namespace MicCheck.Api.Common.Security.Authentication;
|
||||
|
||||
public class ApiKeyAuthenticationHandler(
|
||||
IOptionsMonitor<AuthenticationSchemeOptions> options,
|
||||
ILoggerFactory logger,
|
||||
UrlEncoder encoder,
|
||||
MicCheckDbContext db)
|
||||
public class ApiKeyAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder, MicCheckDbContext db)
|
||||
: AuthenticationHandler<AuthenticationSchemeOptions>(options, logger, encoder)
|
||||
{
|
||||
public const string SchemeName = "ApiKey";
|
||||
@@ -5,13 +5,9 @@ using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace MicCheck.Api.Authentication;
|
||||
namespace MicCheck.Api.Common.Security.Authentication;
|
||||
|
||||
public class EnvironmentKeyAuthenticationHandler(
|
||||
IOptionsMonitor<AuthenticationSchemeOptions> options,
|
||||
ILoggerFactory logger,
|
||||
UrlEncoder encoder,
|
||||
MicCheckDbContext db)
|
||||
public class EnvironmentKeyAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder, MicCheckDbContext db)
|
||||
: AuthenticationHandler<AuthenticationSchemeOptions>(options, logger, encoder)
|
||||
{
|
||||
public const string SchemeName = "EnvironmentKey";
|
||||
@@ -1,6 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MicCheck.Api.Authorization;
|
||||
namespace MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
public static class AuthEndpoints
|
||||
{
|
||||
@@ -8,10 +8,7 @@ public static class AuthEndpoints
|
||||
{
|
||||
var group = app.MapGroup("/api/v1/auth").AllowAnonymous().WithTags("Auth");
|
||||
|
||||
group.MapPost("/login", async (
|
||||
[FromBody] LoginRequest request,
|
||||
AuthService authService,
|
||||
CancellationToken ct) =>
|
||||
group.MapPost("/login", async ([FromBody] LoginRequest request, AuthService authService, CancellationToken ct) =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.Email) || string.IsNullOrWhiteSpace(request.Password))
|
||||
return Results.BadRequest("Email and password are required.");
|
||||
@@ -20,12 +17,10 @@ public static class AuthEndpoints
|
||||
return response is null
|
||||
? Results.Unauthorized()
|
||||
: Results.Ok(response);
|
||||
|
||||
}).WithName("Login");
|
||||
|
||||
group.MapPost("/register", async (
|
||||
[FromBody] RegisterRequest request,
|
||||
AuthService authService,
|
||||
CancellationToken ct) =>
|
||||
group.MapPost("/register", async ([FromBody] RegisterRequest request, AuthService authService, CancellationToken ct) =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.Email) || string.IsNullOrWhiteSpace(request.Password))
|
||||
return Results.BadRequest("Email and password are required.");
|
||||
@@ -38,12 +33,10 @@ public static class AuthEndpoints
|
||||
return response is null
|
||||
? Results.Conflict("An account with this email already exists.")
|
||||
: Results.Ok(response);
|
||||
|
||||
}).WithName("Register");
|
||||
|
||||
group.MapPost("/refresh", async (
|
||||
[FromBody] RefreshRequest request,
|
||||
AuthService authService,
|
||||
CancellationToken ct) =>
|
||||
group.MapPost("/refresh", async ([FromBody] RefreshRequest request, AuthService authService, CancellationToken ct) =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.Token))
|
||||
return Results.BadRequest("Refresh token is required.");
|
||||
@@ -52,15 +45,14 @@ public static class AuthEndpoints
|
||||
return response is null
|
||||
? Results.Unauthorized()
|
||||
: Results.Ok(response);
|
||||
|
||||
}).WithName("RefreshToken");
|
||||
|
||||
group.MapPost("/logout", async (
|
||||
[FromBody] LogoutRequest request,
|
||||
AuthService authService,
|
||||
CancellationToken ct) =>
|
||||
group.MapPost("/logout", async ([FromBody] LogoutRequest request, AuthService authService, CancellationToken ct) =>
|
||||
{
|
||||
await authService.LogoutAsync(request.Token, ct);
|
||||
return Results.NoContent();
|
||||
|
||||
}).WithName("Logout");
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using MicCheck.Api.Users;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MicCheck.Api.Authorization;
|
||||
namespace MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
public class AuthService(
|
||||
MicCheckDbContext db,
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace MicCheck.Api.Authorization;
|
||||
namespace MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
public static class AuthorizationPolicies
|
||||
{
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace MicCheck.Api.Authorization;
|
||||
namespace MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
public record LoginRequest(string Email, string Password);
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace MicCheck.Api.Authorization;
|
||||
namespace MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
public record LoginResponse(string AccessToken, string RefreshToken, DateTime ExpiresAt);
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
public record LogoutRequest(string Token);
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace MicCheck.Api.Authorization;
|
||||
namespace MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
public enum ProjectPermission
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace MicCheck.Api.Authorization;
|
||||
namespace MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
public class ProjectPermissionRequirement : IAuthorizationRequirement
|
||||
{
|
||||
@@ -4,7 +4,7 @@ using MicCheck.Api.Organizations;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MicCheck.Api.Authorization;
|
||||
namespace MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
public class ProjectPermissionRequirementHandler(
|
||||
MicCheckDbContext db,
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
public record RefreshRequest(string Token);
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace MicCheck.Api.Authorization;
|
||||
namespace MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
public record RegisterRequest(
|
||||
string Email,
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace MicCheck.Api.Authorization;
|
||||
namespace MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
public record TokenResponse(string Token, DateTime ExpiresAt);
|
||||
@@ -4,7 +4,7 @@ using System.Text;
|
||||
using MicCheck.Api.Users;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
namespace MicCheck.Api.Authorization;
|
||||
namespace MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
public class TokenService(IConfiguration configuration) : ITokenService
|
||||
{
|
||||
@@ -28,9 +28,7 @@ public class TokenService(IConfiguration configuration) : ITokenService
|
||||
new(JwtRegisteredClaimNames.Email, user.Email),
|
||||
new(JwtRegisteredClaimNames.GivenName, user.FirstName),
|
||||
new(JwtRegisteredClaimNames.FamilyName, user.LastName),
|
||||
new(JwtRegisteredClaimNames.Iat,
|
||||
DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(),
|
||||
ClaimValueTypes.Integer64),
|
||||
new(JwtRegisteredClaimNames.Iat, DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(), ClaimValueTypes.Integer64),
|
||||
new(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
|
||||
};
|
||||
|
||||
@@ -50,3 +48,8 @@ public class TokenService(IConfiguration configuration) : ITokenService
|
||||
return new TokenResponse(new JwtSecurityTokenHandler().WriteToken(token), expiresAt);
|
||||
}
|
||||
}
|
||||
|
||||
public interface ITokenService
|
||||
{
|
||||
TokenResponse GenerateToken(User user);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace MicCheck.Api.Authorization;
|
||||
namespace MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
public class UserProjectPermission
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.ApiKeys;
|
||||
using MicCheck.Api.Common.Security.ApiKeys;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
|
||||
24
src/api/MicCheck.Api/Data/DatabaseStartupExtensions.cs
Normal file
24
src/api/MicCheck.Api/Data/DatabaseStartupExtensions.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MicCheck.Api.Data;
|
||||
|
||||
public static class DatabaseStartupExtensions
|
||||
{
|
||||
public static async Task ApplyMigrationsAsync(this WebApplication app, CancellationToken ct = default)
|
||||
{
|
||||
using var scope = app.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<MicCheckDbContext>();
|
||||
|
||||
if (db.Database.ProviderName is null or "Microsoft.EntityFrameworkCore.InMemory")
|
||||
return;
|
||||
|
||||
await db.Database.MigrateAsync(ct);
|
||||
}
|
||||
|
||||
public static async Task SeedDevelopmentDataAsync(this WebApplication app, CancellationToken ct = default)
|
||||
{
|
||||
using var scope = app.Services.CreateScope();
|
||||
var seeder = scope.ServiceProvider.GetRequiredService<DatabaseSeeder>();
|
||||
await seeder.SeedAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using MicCheck.Api.ApiKeys;
|
||||
using MicCheck.Api.Common.Security.ApiKeys;
|
||||
using MicCheck.Api.Audit;
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
using MicCheck.Api.Features;
|
||||
using MicCheck.Api.Identities;
|
||||
using MicCheck.Api.Organizations;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.ApiKeys;
|
||||
using MicCheck.Api.Common.Security.ApiKeys;
|
||||
using MicCheck.Api.Audit;
|
||||
using MicCheck.Api.Data;
|
||||
using MicCheck.Api.Features;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
using MicCheck.Api.Common;
|
||||
using MicCheck.Api.Webhooks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
using MicCheck.Api.Common;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -31,8 +31,7 @@ public class FeaturesController(FeatureService featureService) : ControllerBase
|
||||
{
|
||||
try
|
||||
{
|
||||
var feature = await featureService.CreateAsync(
|
||||
projectId, request.Name, request.Type, request.InitialValue, request.Description, ct);
|
||||
var feature = await featureService.CreateAsync(projectId, request.Name, request.Type, request.InitialValue, request.Description, ct);
|
||||
|
||||
return CreatedAtAction(nameof(GetById), new { projectId, id = feature.Id }, FeatureResponse.From(feature));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
using MicCheck.Api.Features;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -23,4 +23,8 @@
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.16.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\MicCheck.ServiceDefaults\MicCheck.ServiceDefaults.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// <auto-generated />
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MicCheck.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -25,7 +25,7 @@ namespace MicCheck.Api.Migrations
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.ApiKeys.ApiKey", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.ApiKeys.ApiKey", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -118,7 +118,7 @@ namespace MicCheck.Api.Migrations
|
||||
b.ToTable("AuditLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.Authorization.UserProjectPermission", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.Authorization.UserProjectPermission", b =>
|
||||
{
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
@@ -694,7 +694,7 @@ namespace MicCheck.Api.Migrations
|
||||
b.ToTable("WebhookDeliveryLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.ApiKeys.ApiKey", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.ApiKeys.ApiKey", b =>
|
||||
{
|
||||
b.HasOne("MicCheck.Api.Organizations.Organization", null)
|
||||
.WithMany("ApiKeys")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// <auto-generated />
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MicCheck.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -25,7 +25,7 @@ namespace MicCheck.Api.Migrations
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.ApiKeys.ApiKey", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.ApiKeys.ApiKey", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -118,7 +118,7 @@ namespace MicCheck.Api.Migrations
|
||||
b.ToTable("AuditLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.Authorization.UserProjectPermission", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.Authorization.UserProjectPermission", b =>
|
||||
{
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
@@ -697,7 +697,7 @@ namespace MicCheck.Api.Migrations
|
||||
b.ToTable("WebhookDeliveryLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.ApiKeys.ApiKey", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.ApiKeys.ApiKey", b =>
|
||||
{
|
||||
b.HasOne("MicCheck.Api.Organizations.Organization", null)
|
||||
.WithMany("ApiKeys")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// <auto-generated />
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MicCheck.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -40,7 +40,7 @@ namespace MicCheck.Api.Migrations
|
||||
b.ToTable("FeatureTags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.ApiKeys.ApiKey", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.ApiKeys.ApiKey", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -133,7 +133,7 @@ namespace MicCheck.Api.Migrations
|
||||
b.ToTable("AuditLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.Authorization.UserProjectPermission", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.Authorization.UserProjectPermission", b =>
|
||||
{
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
@@ -727,7 +727,7 @@ namespace MicCheck.Api.Migrations
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.ApiKeys.ApiKey", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.ApiKeys.ApiKey", b =>
|
||||
{
|
||||
b.HasOne("MicCheck.Api.Organizations.Organization", null)
|
||||
.WithMany("ApiKeys")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// <auto-generated />
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MicCheck.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -40,7 +40,7 @@ namespace MicCheck.Api.Migrations
|
||||
b.ToTable("FeatureTags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.ApiKeys.ApiKey", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.ApiKeys.ApiKey", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -133,7 +133,7 @@ namespace MicCheck.Api.Migrations
|
||||
b.ToTable("AuditLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.Authorization.UserProjectPermission", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.Authorization.UserProjectPermission", b =>
|
||||
{
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
@@ -727,7 +727,7 @@ namespace MicCheck.Api.Migrations
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.ApiKeys.ApiKey", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.ApiKeys.ApiKey", b =>
|
||||
{
|
||||
b.HasOne("MicCheck.Api.Organizations.Organization", null)
|
||||
.WithMany("ApiKeys")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// <auto-generated />
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MicCheck.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -40,7 +40,7 @@ namespace MicCheck.Api.Migrations
|
||||
b.ToTable("FeatureTags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.ApiKeys.ApiKey", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.ApiKeys.ApiKey", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -133,7 +133,7 @@ namespace MicCheck.Api.Migrations
|
||||
b.ToTable("AuditLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.Authorization.UserProjectPermission", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.Authorization.UserProjectPermission", b =>
|
||||
{
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
@@ -735,7 +735,7 @@ namespace MicCheck.Api.Migrations
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.ApiKeys.ApiKey", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.ApiKeys.ApiKey", b =>
|
||||
{
|
||||
b.HasOne("MicCheck.Api.Organizations.Organization", null)
|
||||
.WithMany("ApiKeys")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// <auto-generated />
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MicCheck.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -37,7 +37,7 @@ namespace MicCheck.Api.Migrations
|
||||
b.ToTable("FeatureTags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.ApiKeys.ApiKey", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.ApiKeys.ApiKey", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -130,7 +130,7 @@ namespace MicCheck.Api.Migrations
|
||||
b.ToTable("AuditLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.Authorization.UserProjectPermission", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.Authorization.UserProjectPermission", b =>
|
||||
{
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("integer");
|
||||
@@ -732,7 +732,7 @@ namespace MicCheck.Api.Migrations
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MicCheck.Api.ApiKeys.ApiKey", b =>
|
||||
modelBuilder.Entity("MicCheck.Api.Common.Security.ApiKeys.ApiKey", b =>
|
||||
{
|
||||
b.HasOne("MicCheck.Api.Organizations.Organization", null)
|
||||
.WithMany("ApiKeys")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.ApiKeys;
|
||||
using MicCheck.Api.Common.Security.ApiKeys;
|
||||
using MicCheck.Api.Projects;
|
||||
|
||||
namespace MicCheck.Api.Organizations;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
using MicCheck.Api.Common;
|
||||
using MicCheck.Api.Webhooks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
@@ -2,10 +2,10 @@ using System.Text;
|
||||
using System.Threading.RateLimiting;
|
||||
using FluentValidation;
|
||||
using FluentValidation.AspNetCore;
|
||||
using MicCheck.Api.ApiKeys;
|
||||
using MicCheck.Api.Common.Security.ApiKeys;
|
||||
using MicCheck.Api.Audit;
|
||||
using MicCheck.Api.Authentication;
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authentication;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
using MicCheck.Api.Data;
|
||||
using MicCheck.Api.Environments;
|
||||
using MicCheck.Api.Features;
|
||||
@@ -34,6 +34,8 @@ try
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.AddServiceDefaults();
|
||||
|
||||
builder.Host.UseSerilog((context, services, config) =>
|
||||
config.ReadFrom.Configuration(context.Configuration)
|
||||
.ReadFrom.Services(services)
|
||||
@@ -139,21 +141,17 @@ try
|
||||
builder.Services.AddHttpClient("Webhooks", client =>
|
||||
client.DefaultRequestHeaders.Add("User-Agent", "MicCheck-Webhook/1.0"));
|
||||
|
||||
var connectionString = System.Environment.GetEnvironmentVariable("DATABASE_URL") is { } databaseUrl
|
||||
? DatabaseUrlParser.ToNpgsqlConnectionString(databaseUrl)
|
||||
: builder.Configuration.GetConnectionString("DefaultConnection")!;
|
||||
var connectionString = builder.Configuration.GetConnectionString("miccheck")
|
||||
?? (System.Environment.GetEnvironmentVariable("DATABASE_URL") is { } databaseUrl
|
||||
? DatabaseUrlParser.ToNpgsqlConnectionString(databaseUrl)
|
||||
: builder.Configuration.GetConnectionString("DefaultConnection")!);
|
||||
|
||||
builder.Services.AddDbContext<MicCheckDbContext>(options =>
|
||||
options.UseNpgsql(connectionString));
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Apply any pending EF Core migrations on startup (safe to run on every boot)
|
||||
using (var migrationScope = app.Services.CreateScope())
|
||||
{
|
||||
var db = migrationScope.ServiceProvider.GetRequiredService<MicCheckDbContext>();
|
||||
await db.Database.MigrateAsync();
|
||||
}
|
||||
await app.ApplyMigrationsAsync();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
@@ -161,9 +159,7 @@ try
|
||||
app.MapScalarApiReference();
|
||||
app.MapGet("/", () => Results.Redirect("/scalar/v1")).ExcludeFromDescription();
|
||||
|
||||
using var scope = app.Services.CreateScope();
|
||||
var seeder = scope.ServiceProvider.GetRequiredService<DatabaseSeeder>();
|
||||
await seeder.SeedAsync();
|
||||
await app.SeedDevelopmentDataAsync();
|
||||
}
|
||||
|
||||
app.UseSerilogRequestLogging();
|
||||
@@ -171,6 +167,7 @@ try
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapDefaultEndpoints();
|
||||
app.MapControllers();
|
||||
app.MapAuthEndpoints();
|
||||
app.MapApiKeyEndpoints();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
namespace MicCheck.Api.Projects;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using MicCheck.Api.Audit;
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
using MicCheck.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
using MicCheck.Api.Common;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -79,7 +79,7 @@ public class ProjectsController(ProjectService projectService) : ControllerBase
|
||||
if (project is null) return NotFound();
|
||||
|
||||
var permissions = request.Permissions
|
||||
.Select(p => Enum.Parse<Authorization.ProjectPermission>(p, ignoreCase: true))
|
||||
.Select(p => Enum.Parse<ProjectPermission>(p, ignoreCase: true))
|
||||
.ToList();
|
||||
|
||||
var perm = await projectService.SetUserPermissionsAsync(id, request.UserId, request.IsAdmin, permissions, ct);
|
||||
@@ -94,7 +94,7 @@ public class ProjectsController(ProjectService projectService) : ControllerBase
|
||||
if (project is null) return NotFound();
|
||||
|
||||
var permissions = request.Permissions
|
||||
.Select(p => Enum.Parse<Authorization.ProjectPermission>(p, ignoreCase: true))
|
||||
.Select(p => Enum.Parse<ProjectPermission>(p, ignoreCase: true))
|
||||
.ToList();
|
||||
|
||||
var perm = await projectService.SetUserPermissionsAsync(id, userId, request.IsAdmin, permissions, ct);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using FluentValidation;
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
|
||||
namespace MicCheck.Api.Projects;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
using MicCheck.Api.Common;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MicCheck.Api.Authorization;
|
||||
using MicCheck.Api.Common.Security.Authorization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
|
||||
Reference in New Issue
Block a user