mirror of
https://github.com/azaion/admin.git
synced 2026-04-22 09:06:33 +00:00
secure getinstaller endpoint
This commit is contained in:
+18
-4
@@ -210,18 +210,32 @@ app.MapPost("/resources/get/{dataFolder?}", //Need to have POST method for secur
|
|||||||
}).RequireAuthorization()
|
}).RequireAuthorization()
|
||||||
.WithOpenApi(op => new OpenApiOperation(op){ Summary = "Gets encrypted by users Password and HardwareHash resources. POST method for secure password"});
|
.WithOpenApi(op => new OpenApiOperation(op){ Summary = "Gets encrypted by users Password and HardwareHash resources. POST method for secure password"});
|
||||||
|
|
||||||
app.MapGet("/resources/get-installer/{dataFolder?}",
|
app.MapGet("/resources/get-installer",
|
||||||
async ([FromRoute]string? dataFolder, IAuthService authService, IResourcesService resourcesService, CancellationToken ct) =>
|
async (IAuthService authService, IResourcesService resourcesService, CancellationToken ct) =>
|
||||||
{
|
{
|
||||||
var user = await authService.GetCurrentUser();
|
var user = await authService.GetCurrentUser();
|
||||||
if (user == null)
|
if (user == null)
|
||||||
throw new UnauthorizedAccessException();
|
throw new UnauthorizedAccessException();
|
||||||
var (name, stream) = resourcesService.GetInstaller(dataFolder);
|
var (name, stream) = resourcesService.GetInstaller(isStage: false);
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
throw new FileNotFoundException("Installer file was not found!");
|
throw new FileNotFoundException("Installer file was not found!");
|
||||||
return Results.File(stream, "application/octet-stream", name);
|
return Results.File(stream, "application/octet-stream", name);
|
||||||
}).RequireAuthorization()
|
}).RequireAuthorization()
|
||||||
.WithOpenApi(op => new OpenApiOperation(op){ Summary = "Gets latest installer"});
|
.WithOpenApi(op => new OpenApiOperation(op) { Summary = "Gets latest installer" });
|
||||||
|
|
||||||
|
app.MapGet("/resources/get-installer/stage",
|
||||||
|
async (IAuthService authService, IResourcesService resourcesService, CancellationToken ct) =>
|
||||||
|
{
|
||||||
|
var user = await authService.GetCurrentUser();
|
||||||
|
if (user == null)
|
||||||
|
throw new UnauthorizedAccessException();
|
||||||
|
var (name, stream) = resourcesService.GetInstaller(isStage: true);
|
||||||
|
if (stream == null)
|
||||||
|
throw new FileNotFoundException("Installer file was not found!");
|
||||||
|
return Results.File(stream, "application/octet-stream", name);
|
||||||
|
}).RequireAuthorization()
|
||||||
|
.WithOpenApi(op => new OpenApiOperation(op) { Summary = "Gets latest installer" });
|
||||||
|
|
||||||
|
|
||||||
app.MapPost("/resources/check",
|
app.MapPost("/resources/check",
|
||||||
async (CheckResourceRequest request, IAuthService authService, IUserService userService) =>
|
async (CheckResourceRequest request, IAuthService authService, IUserService userService) =>
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ResourcesConfig": {
|
"ResourcesConfig": {
|
||||||
"ResourcesFolder": "Content",
|
"ResourcesFolder": "Content",
|
||||||
"SuiteInstallerFolder": "suite"
|
"SuiteInstallerFolder": "suite",
|
||||||
|
"SuiteStageInstallerFolder": "suite-stage"
|
||||||
},
|
},
|
||||||
"JwtConfig": {
|
"JwtConfig": {
|
||||||
"Issuer": "AzaionApi",
|
"Issuer": "AzaionApi",
|
||||||
|
|||||||
@@ -4,4 +4,5 @@ public class ResourcesConfig
|
|||||||
{
|
{
|
||||||
public string ResourcesFolder { get; set; } = null!;
|
public string ResourcesFolder { get; set; } = null!;
|
||||||
public string SuiteInstallerFolder { get; set; } = null!;
|
public string SuiteInstallerFolder { get; set; } = null!;
|
||||||
|
public string SuiteStageInstallerFolder { get; set; } = null!;
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ public class GetResourceRequestValidator : AbstractValidator<GetResourceRequest>
|
|||||||
{
|
{
|
||||||
RuleFor(r => r.Password)
|
RuleFor(r => r.Password)
|
||||||
.MinimumLength(8)
|
.MinimumLength(8)
|
||||||
.WithErrorCode(ExceptionEnum.PasswordLengthIncorrect.ToString())
|
.WithErrorCode(nameof(ExceptionEnum.PasswordLengthIncorrect))
|
||||||
.WithMessage(_ => BusinessException.GetMessage(ExceptionEnum.PasswordLengthIncorrect));
|
.WithMessage(_ => BusinessException.GetMessage(ExceptionEnum.PasswordLengthIncorrect));
|
||||||
|
|
||||||
RuleFor(r => r.Hardware)
|
RuleFor(r => r.Hardware)
|
||||||
@@ -29,7 +29,7 @@ public class GetResourceRequestValidator : AbstractValidator<GetResourceRequest>
|
|||||||
|
|
||||||
RuleFor(r => r.FileName)
|
RuleFor(r => r.FileName)
|
||||||
.NotEmpty()
|
.NotEmpty()
|
||||||
.WithErrorCode(ExceptionEnum.WrongResourceName.ToString())
|
.WithErrorCode(nameof(ExceptionEnum.WrongResourceName))
|
||||||
.WithMessage(_ => BusinessException.GetMessage(ExceptionEnum.WrongResourceName));
|
.WithMessage(_ => BusinessException.GetMessage(ExceptionEnum.WrongResourceName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ namespace Azaion.Services;
|
|||||||
|
|
||||||
public interface IResourcesService
|
public interface IResourcesService
|
||||||
{
|
{
|
||||||
(string?, Stream?) GetInstaller(string? dataFolder);
|
(string?, Stream?) GetInstaller(bool isStage);
|
||||||
Task<Stream> GetEncryptedResource(string? dataFolder, string fileName, string key, CancellationToken cancellationToken = default);
|
Task<Stream> GetEncryptedResource(string? dataFolder, string fileName, string key, CancellationToken cancellationToken = default);
|
||||||
Task SaveResource(string? dataFolder, IFormFile data, CancellationToken cancellationToken = default);
|
Task SaveResource(string? dataFolder, IFormFile data, CancellationToken cancellationToken = default);
|
||||||
Task<IEnumerable<string>> ListResources(string? dataFolder, string? search, CancellationToken cancellationToken = default);
|
Task<IEnumerable<string>> ListResources(string? dataFolder, string? search, CancellationToken cancellationToken = default);
|
||||||
@@ -24,9 +24,9 @@ public class ResourcesService(IOptions<ResourcesConfig> resourcesConfig, ILogger
|
|||||||
: Path.Combine(resourcesConfig.Value.ResourcesFolder, dataFolder);
|
: Path.Combine(resourcesConfig.Value.ResourcesFolder, dataFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public (string?, Stream?) GetInstaller(string? dataFolder)
|
public (string?, Stream?) GetInstaller(bool isStage)
|
||||||
{
|
{
|
||||||
var suiteFolder = Path.Combine(resourcesConfig.Value.ResourcesFolder, dataFolder ?? resourcesConfig.Value.SuiteInstallerFolder);
|
var suiteFolder = Path.Combine(isStage ? resourcesConfig.Value.SuiteStageInstallerFolder : resourcesConfig.Value.SuiteInstallerFolder);
|
||||||
var installer = new DirectoryInfo(suiteFolder).GetFiles("AzaionSuite.Iterative*").FirstOrDefault();
|
var installer = new DirectoryInfo(suiteFolder).GetFiles("AzaionSuite.Iterative*").FirstOrDefault();
|
||||||
if (installer == null)
|
if (installer == null)
|
||||||
return (null, null);
|
return (null, null);
|
||||||
|
|||||||
Reference in New Issue
Block a user