Skip to content

Commit

Permalink
Merge pull request #71 from AngeloDotNet/develop
Browse files Browse the repository at this point in the history
Sync Main from Develop
  • Loading branch information
AngeloDotNet authored Dec 21, 2024
2 parents f5c5bb3 + cf8ade7 commit 0678751
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace AutenticazioneSvc.BusinessLayer.HostedService;

public class AuthStartupTask(IServiceProvider serviceProvider) : IHostedService
public class AuthStartupTask(IServiceProvider serviceProvider, ILogger<AuthStartupTask> logger) : IHostedService
{
private readonly ILogger<AuthStartupTask> _logger = logger;

public async Task StartAsync(CancellationToken cancellationToken)
{
using var scope = serviceProvider.CreateScope();
Expand All @@ -20,7 +23,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
await GenerateAdminUserProfileAsync(userManager);
}

private static async Task GenerateAdminUserProfileAsync(UserManager<ApplicationUser> userManager)
private async Task GenerateAdminUserProfileAsync(UserManager<ApplicationUser> userManager)
{
var administratorUser = new ApplicationUser
{
Expand All @@ -33,8 +36,10 @@ private static async Task GenerateAdminUserProfileAsync(UserManager<ApplicationU
LockoutEnabled = false
};

//TODO: Aggiungere un log per loggare la password generata
await CheckCreateUserAsync(administratorUser, GeneratePassword(15), RoleNames.Administrator);
var userPassword = GeneratePassword(15);
_logger.LogDebug($"Generated password for user {administratorUser.Email}: {userPassword}");

await CheckCreateUserAsync(administratorUser, userPassword, RoleNames.Administrator);

async Task CheckCreateUserAsync(ApplicationUser user, string password, params string[] roles)
{
Expand Down Expand Up @@ -86,4 +91,4 @@ private static async Task GenerateRolesAsync(RoleManager<ApplicationRole> roleMa
}

public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GSWCloudApp.Common" Version="1.0.61" />
<PackageReference Include="GSWCloudApp.Common" Version="1.0.63" />
</ItemGroup>

</Project>
7 changes: 6 additions & 1 deletion src/GSWCloudApp.Common/Constants/BusinessLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Contains constants used in the business layer of the application.
/// </summary>
public class BusinessLayer
public static class BusinessLayer
{
/// <summary>
/// The folder where uploads are stored.
Expand All @@ -25,6 +25,11 @@ public class BusinessLayer
/// </summary>
public static readonly string[] AllowedDocumentExtensions = [".pdf", ".txt"];

/// <summary>
/// The allowed extensions for image uploads.
/// </summary>
public static readonly string[] AllowedImageExtensions = [".jpg", ".jpeg", ".png", ".gif"];

/// <summary>
/// The current year in UTC.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"Routes": [
{
"DownstreamPathTemplate": "/api/v1/documenti/download/{fileName}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "alb-gestionedocumenti",
"Port": 5001
}
],
"UpstreamPathTemplate": "/documento/{fileName}",
"UpstreamHttpMethod": [ "Get" ],
"AuthenticationOptions": {
"AuthenticationProviderKey": "Bearer",
"AllowedScopes": []
}
},
{
"DownstreamPathTemplate": "/api/v1/documenti/upload",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "alb-gestionedocumenti",
"Port": 5001
}
],
"UpstreamPathTemplate": "/documento",
"UpstreamHttpMethod": [ "Post" ],
"AuthenticationOptions": {
"AuthenticationProviderKey": "Bearer",
"AllowedScopes": []
}
}
],
"GlobalConfiguration": {}
}
1 change: 1 addition & 0 deletions src/GatewaySvc/GatewaySvc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ COPY ["src/GatewaySvc/GatewaySvc/GatewaySvc.csproj", "src/GatewaySvc/GatewaySvc/

# Copy the Ocelot configuration files
COPY ["src/GatewaySvc/GatewaySvc/ConfigOcelot/ocelot.configurazioni.json", "src/GatewaySvc/GatewaySvc/ConfigOcelot/"]
COPY ["src/GatewaySvc/GatewaySvc/ConfigOcelot/ocelot.gestionedocumenti.json", "src/GatewaySvc/GatewaySvc/ConfigOcelot/"]

RUN dotnet restore "src/GatewaySvc/GatewaySvc/GatewaySvc.csproj"
COPY . .
Expand Down
2 changes: 1 addition & 1 deletion src/GatewaySvc/GatewaySvc/GatewaySvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GSWCloudApp.Common" Version="1.0.61" />
<PackageReference Include="GSWCloudApp.Common" Version="1.0.63" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Ocelot" Version="23.4.2" />
</ItemGroup>
Expand Down

0 comments on commit 0678751

Please sign in to comment.