Skip to content

Commit

Permalink
Fix logic for increasing file size beyond 2GB
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceredron committed Nov 12, 2024
1 parent ce6c7f3 commit e2a4a4c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
using Altinn.Broker.Core.Helpers;
using Altinn.Broker.Core.Repositories;

using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

using OneOf;

namespace Altinn.Broker.Application.ConfigureResource;
public class ConfigureResourceHandler(IResourceRepository resourceRepository, IOptions<ApplicationSettings> applicationSettings, ILogger<ConfigureResourceHandler> logger) : IHandler<ConfigureResourceRequest, Task>
public class ConfigureResourceHandler(IResourceRepository resourceRepository, IHostEnvironment hostEnvironment, IOptions<ApplicationSettings> applicationSettings, ILogger<ConfigureResourceHandler> logger) : IHandler<ConfigureResourceRequest, Task>
{
private readonly long _maxFileUploadSize = applicationSettings.Value.MaxFileUploadSize;
private readonly string _maxGracePeriod = applicationSettings.Value.MaxGracePeriod;
Expand Down Expand Up @@ -82,7 +83,7 @@ private async Task<OneOf<Task, Error>> UpdateMaxFileTransferSize(ResourceEntity
{
return Errors.MaxUploadSizeCannotBeZero;
}
if (maxFileTransferSize > _maxFileUploadSize)
if (hostEnvironment.IsProduction() && maxFileTransferSize > _maxFileUploadSize && !resource.ApprovedForDisabledVirusScan)
{
return Errors.MaxUploadSizeOverGlobal;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.Broker.Application/Errors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static class Errors
public static Error FileTransferNotPublished = new Error(10, "A file transfer can only be confirmed to be downloaded when it is published. See file transfer status.", HttpStatusCode.BadRequest);
public static Error MaxUploadSizeCannotBeNegative = new Error(11, "Max file transfer size cannot be negative", HttpStatusCode.BadRequest);
public static Error MaxUploadSizeCannotBeZero = new Error(12, "Max file transfer size cannot be zero", HttpStatusCode.BadRequest);
public static Error MaxUploadSizeOverGlobal = new Error(13, "Max file transfer size cannot be set higher than the global max file transfer size", HttpStatusCode.BadRequest);
public static Error MaxUploadSizeOverGlobal = new Error(13, "Max file transfer size cannot be set higher than the global max file transfer size of 2GB in production unless the resource has been pre-approved for disabled virus scan. Contact us @ Slack.", HttpStatusCode.BadRequest);
public static Error InvalidTimeToLiveFormat = new Error(14, "Invalid file transfer time to live format. Should follow ISO8601 standard for duration. Example: 'P30D' for 30 days.", HttpStatusCode.BadRequest);
public static Error TimeToLiveCannotExceed365Days = new Error(15, "Time to live cannot exceed 365 days", HttpStatusCode.BadRequest);
public static Error FileSizeTooBig = new Error(16, "File size exceeds maximum", HttpStatusCode.BadRequest);
Expand Down

0 comments on commit e2a4a4c

Please sign in to comment.