Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code clean-up #200

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Test/Altinn.Broker.Tests/FileControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

using Microsoft.AspNetCore.Mvc.Testing;

using Xunit;

namespace Altinn.Broker.Tests;
public class FileControllerTests : IClassFixture<WebApplicationFactory<Program>>
{
Expand Down
1 change: 0 additions & 1 deletion Test/Altinn.Broker.Tests/GlobalUsings.cs

This file was deleted.

7 changes: 4 additions & 3 deletions src/Altinn.Broker.Integrations/Azure/AzureResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ namespace Altinn.Broker.Integrations.Azure;
public class AzureResourceManager : IResourceManager
{
private readonly AzureResourceManagerOptions _resourceManagerOptions;
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IHostEnvironment _hostingEnvironment;
private readonly ArmClient _armClient;
private readonly IServiceOwnerRepository _serviceOwnerRepository;
private readonly ILogger<AzureResourceManager> _logger;
public string GetResourceGroupName(ServiceOwnerEntity serviceOwnerEntity) => $"serviceowner-{_resourceManagerOptions.Environment}-{serviceOwnerEntity.Id.Replace(":", "-")}-rg";
public string GetStorageAccountName(ServiceOwnerEntity serviceOwnerEntity) => $"ai{_resourceManagerOptions.Environment.ToLowerInvariant()}{serviceOwnerEntity.Id.Replace(":", "")}sa";

public AzureResourceManager(IOptions<AzureResourceManagerOptions> resourceManagerOptions, IHostingEnvironment hostingEnvironment, IServiceOwnerRepository serviceOwnerRepository, ILogger<AzureResourceManager> logger)
public AzureResourceManager(IOptions<AzureResourceManagerOptions> resourceManagerOptions, IHostEnvironment hostingEnvironment, IServiceOwnerRepository serviceOwnerRepository, ILogger<AzureResourceManager> logger)
{
_resourceManagerOptions = resourceManagerOptions.Value;
_hostingEnvironment = hostingEnvironment;
Expand Down Expand Up @@ -105,6 +105,7 @@ public async Task<DeploymentStatus> GetDeploymentStatus(ServiceOwnerEntity servi

public async Task<string> GetStorageConnectionString(ServiceOwnerEntity serviceOwnerEntity)
{
_logger.LogInformation($"Retrieving connection string for {serviceOwnerEntity.Name}");
var resourceGroupName = GetResourceGroupName(serviceOwnerEntity);
var storageAccountName = GetStorageAccountName(serviceOwnerEntity);
var subscription = await _armClient.GetDefaultSubscriptionAsync();
Expand All @@ -131,6 +132,6 @@ public async Task<string> GetStorageConnectionString(ServiceOwnerEntity serviceO
sasBuilder.SetPermissions(BlobSasPermissions.Read | BlobSasPermissions.Create | BlobSasPermissions.List | BlobSasPermissions.Write);
string sasToken = sasBuilder.ToSasQueryParameters(credential).ToString();

return $"{serviceClient.Uri}{sasBuilder.BlobContainerName}?{sasToken}";
return $"BlobEndpoint={serviceClient.Uri}{sasBuilder.BlobContainerName}?{sasToken}";
}
}
6 changes: 5 additions & 1 deletion src/Altinn.Broker/Controllers/FileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ public async Task<ActionResult<List<Guid>>> GetFiles([FromQuery] FileStatus? sta
[Route("{fileId}/download")]
public async Task<ActionResult<Stream>> DownloadFile(Guid fileId)
{
var caller = AuthenticationSimulator.GetCallerFromTestToken(HttpContext) ?? "politiet";
var caller = AuthenticationSimulator.GetCallerFromTestToken(HttpContext);
if (string.IsNullOrWhiteSpace(caller))
{
return Unauthorized();
}
var serviceOwner = await _serviceOwnerRepository.GetServiceOwner(caller);
if (serviceOwner is not null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.Broker/Controllers/HealthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task<ActionResult> HealthCheckAsync()
var resourceGroupCount = resourceGroupCollection.Count();
if (resourceGroupCount < 1)
{
return BadRequest("Resource groups not found under subscription with id : {_azureResourceManagerOptions.SubscriptionId}. Are the service principal environment variables set?");
return BadRequest($"Resource groups not found under subscription with id: {subscription.Id}. Are the service principal environment variables set?");
}
await resourceGroupCollection.GetAsync($"altinn-{_azureResourceManagerOptions.Environment}-broker-rg");

Expand Down
20 changes: 13 additions & 7 deletions src/Altinn.Broker/Mappers/FileStatusOverviewExtMapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Altinn.Broker.Core.Domain;
using System.ComponentModel;

using Altinn.Broker.Core.Domain;
using Altinn.Broker.Core.Domain.Enums;
using Altinn.Broker.Core.Models;
using Altinn.Broker.Enums;
Expand All @@ -20,7 +22,7 @@ public static FileOverviewExt MapToExternalModel(FileEntity file)
FileStatusChanged = file.FileStatusChanged,
FileStatusText = MapToFileStatusText(file.FileStatus),
PropertyList = file.PropertyList,
Recipients = MapToRecipients(file.ActorEvents, file.Sender, file.ServiceOwnerId),
Recipients = MapToRecipients(file.ActorEvents, file.Sender),
SendersFileReference = file.SendersFileReference
};
}
Expand All @@ -36,7 +38,8 @@ public static FileStatusExt MapToExternalEnum(FileStatus domainEnum)
FileStatus.Cancelled => FileStatusExt.Cancelled,
FileStatus.AllConfirmedDownloaded => FileStatusExt.AllConfirmedDownloaded,
FileStatus.Deleted => FileStatusExt.Deleted,
FileStatus.Failed => FileStatusExt.Failed
FileStatus.Failed => FileStatusExt.Failed,
_ => throw new InvalidEnumArgumentException()
};
}

Expand All @@ -51,7 +54,8 @@ public static string MapToFileStatusText(FileStatus domainEnum)
FileStatus.Cancelled => "File cancelled",
FileStatus.AllConfirmedDownloaded => "All downloaded",
FileStatus.Deleted => "File has been deleted",
FileStatus.Failed => "Upload failed"
FileStatus.Failed => "Upload failed",
_ => throw new InvalidEnumArgumentException()
};
}

Expand All @@ -62,7 +66,7 @@ public static string MapToFileStatusText(FileStatus domainEnum)
FileStatusText = MapToFileStatusText(entity.Status)
}).ToList();

public static List<RecipientFileStatusDetailsExt> MapToRecipients(List<ActorFileStatusEntity> actorEvents, string sender, string applicationId)
public static List<RecipientFileStatusDetailsExt> MapToRecipients(List<ActorFileStatusEntity> actorEvents, string sender)
{
var recipientEvents = actorEvents.Where(actorEvent => actorEvent.Actor.ActorExternalId != sender);
var lastStatusForEveryRecipient = recipientEvents
Expand All @@ -85,7 +89,8 @@ private static RecipientFileStatusExt MapToExternalRecipientStatus(ActorFileStat
{
ActorFileStatus.Initialized => RecipientFileStatusExt.Initialized,
ActorFileStatus.DownloadStarted => RecipientFileStatusExt.DownloadStarted,
ActorFileStatus.DownloadConfirmed => RecipientFileStatusExt.DownloadConfirmed
ActorFileStatus.DownloadConfirmed => RecipientFileStatusExt.DownloadConfirmed,
_ => throw new InvalidEnumArgumentException()
};
}

Expand All @@ -95,7 +100,8 @@ private static string MapToRecipientStatusText(ActorFileStatus actorFileStatus)
{
ActorFileStatus.Initialized => "Initialized",
ActorFileStatus.DownloadStarted => "Recipient has attempted to download file",
ActorFileStatus.DownloadConfirmed => "Recipient has downloaded file"
ActorFileStatus.DownloadConfirmed => "Recipient has downloaded file",
_ => throw new InvalidEnumArgumentException()
};

}
Expand Down