diff --git a/src/Altinn.App.Core/Infrastructure/Clients/Storage/InstanceClient.cs b/src/Altinn.App.Core/Infrastructure/Clients/Storage/InstanceClient.cs
index 085c83933..26d493c13 100644
--- a/src/Altinn.App.Core/Infrastructure/Clients/Storage/InstanceClient.cs
+++ b/src/Altinn.App.Core/Infrastructure/Clients/Storage/InstanceClient.cs
@@ -12,6 +12,7 @@
using Altinn.App.Core.Models;
using Altinn.Platform.Storage.Interface.Models;
using Microsoft.AspNetCore.WebUtilities;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
@@ -25,62 +26,75 @@ namespace Altinn.App.Core.Infrastructure.Clients.Storage;
public class InstanceClient : IInstanceClient
{
private readonly ILogger _logger;
- private readonly IUserTokenProvider _userTokenProvider;
private readonly HttpClient _client;
private readonly Telemetry? _telemetry;
+ private readonly IAuthenticationTokenResolver _authenticationTokenResolver;
+ private readonly AuthenticationMethod _defaultAuthenticationMethod = StorageAuthenticationMethod.CurrentUser();
///
/// Initializes a new instance of the class.
///
/// the platform settings
- /// the logger
- /// Get user token from httpContext
/// A HttpClient that can be used to perform HTTP requests against the platform.
- /// Telemetry for traces and metrics.
+ /// The service provider
public InstanceClient(
IOptions platformSettings,
- ILogger logger,
- IUserTokenProvider userTokenProvider,
HttpClient httpClient,
- Telemetry? telemetry = null
+ IServiceProvider serviceProvider
)
{
- _logger = logger;
- _userTokenProvider = userTokenProvider;
+ _authenticationTokenResolver = serviceProvider.GetRequiredService();
+ _logger = serviceProvider.GetRequiredService>();
+ _telemetry = serviceProvider.GetService();
+
httpClient.BaseAddress = new Uri(platformSettings.Value.ApiStorageEndpoint);
httpClient.DefaultRequestHeaders.Add(General.SubscriptionKeyHeaderName, platformSettings.Value.SubscriptionKey);
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
_client = httpClient;
- _telemetry = telemetry;
}
///
- public async Task GetInstance(string app, string org, int instanceOwnerPartyId, Guid instanceId)
+ public async Task GetInstance(
+ string app,
+ string org,
+ int instanceOwnerPartyId,
+ Guid instanceId,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ )
{
using var activity = _telemetry?.StartGetInstanceByGuidActivity(instanceId);
string instanceIdentifier = $"{instanceOwnerPartyId}/{instanceId}";
-
string apiUrl = $"instances/{instanceIdentifier}";
- string token = _userTokenProvider.GetUserToken();
+
+ JwtToken token = await _authenticationTokenResolver.GetAccessToken(
+ authenticationMethod ?? _defaultAuthenticationMethod,
+ cancellationToken: cancellationToken
+ );
HttpResponseMessage response = await _client.GetAsync(token, apiUrl);
+
if (response.StatusCode == HttpStatusCode.OK)
{
- string instanceData = await response.Content.ReadAsStringAsync();
+ string instanceData = await response.Content.ReadAsStringAsync(cancellationToken);
// ! TODO: this null-forgiving operator should be fixed/removed for the next major release
Instance instance = JsonConvert.DeserializeObject(instanceData)!;
return instance;
}
else
{
- _logger.LogError($"Unable to fetch instance with instance id {instanceId}");
+ _logger.LogError("Unable to fetch instance with instance id {InstanceId}", instanceId);
throw await PlatformHttpException.CreateAsync(response);
}
}
///
- public async Task GetInstance(Instance instance)
+ public async Task GetInstance(
+ Instance instance,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ )
{
Guid instanceGuid = Guid.Parse(instance.Id.Split("/")[1]);
using var activity = _telemetry?.StartGetInstanceByInstanceActivity(instanceGuid);
@@ -88,16 +102,24 @@ public async Task GetInstance(Instance instance)
string org = instance.Org;
int instanceOwnerPartyId = int.Parse(instance.InstanceOwner.PartyId, CultureInfo.InvariantCulture);
- return await GetInstance(app, org, instanceOwnerPartyId, instanceGuid);
+ return await GetInstance(app, org, instanceOwnerPartyId, instanceGuid, cancellationToken: cancellationToken);
}
///
- public async Task> GetInstances(Dictionary queryParams)
+ public async Task> GetInstances(
+ Dictionary queryParams,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ )
{
using var activity = _telemetry?.StartGetInstancesActivity();
var apiUrl = QueryHelpers.AddQueryString("instances", queryParams);
- string token = _userTokenProvider.GetUserToken();
+ JwtToken token = await _authenticationTokenResolver.GetAccessToken(
+ authenticationMethod ?? _defaultAuthenticationMethod,
+ cancellationToken: cancellationToken
+ );
+
QueryResponse queryResponse = await QueryInstances(token, apiUrl);
if (queryResponse.Count == 0)
@@ -135,35 +157,48 @@ private async Task> QueryInstances(string token, string
}
///
- public async Task UpdateProcess(Instance instance)
+ public async Task UpdateProcess(
+ Instance instance,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ )
{
using var activity = _telemetry?.StartUpdateProcessActivity(instance);
ProcessState processState = instance.Process;
-
string apiUrl = $"instances/{instance.Id}/process";
- string token = _userTokenProvider.GetUserToken();
+
+ JwtToken token = await _authenticationTokenResolver.GetAccessToken(
+ authenticationMethod ?? _defaultAuthenticationMethod,
+ cancellationToken: cancellationToken
+ );
string processStateString = JsonConvert.SerializeObject(processState);
- _logger.LogInformation($"update process state: {processStateString}");
+ _logger.LogInformation("update process state: {ProcessStateString}", processStateString);
StringContent httpContent = new(processStateString, Encoding.UTF8, "application/json");
HttpResponseMessage response = await _client.PutAsync(token, apiUrl, httpContent);
+
if (response.StatusCode == HttpStatusCode.OK)
{
- string instanceData = await response.Content.ReadAsStringAsync();
+ string instanceData = await response.Content.ReadAsStringAsync(cancellationToken);
// ! TODO: this null-forgiving operator should be fixed/removed for the next major release
Instance updatedInstance = JsonConvert.DeserializeObject(instanceData)!;
return updatedInstance;
}
else
{
- _logger.LogError($"Unable to update instance process with instance id {instance.Id}");
+ _logger.LogError("Unable to update instance process with instance id {InstanceId}", instance.Id);
throw await PlatformHttpException.CreateAsync(response);
}
}
///
- public async Task UpdateProcessAndEvents(Instance instance, List events)
+ public async Task UpdateProcessAndEvents(
+ Instance instance,
+ List events,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ )
{
using var activity = _telemetry?.StartUpdateProcessActivity(instance, events.Count);
ProcessState processState = instance.Process;
@@ -172,35 +207,50 @@ public async Task UpdateProcessAndEvents(Instance instance, List(instanceData)
- ?? throw new Exception("Could not deserialize instance");
+ ?? throw new JsonException("Could not deserialize instance");
return updatedInstance;
}
else
{
- _logger.LogError($"Unable to update instance process with instance id {instance.Id}");
+ _logger.LogError("Unable to update instance process with instance id {InstanceId}", instance.Id);
throw await PlatformHttpException.CreateAsync(response);
}
}
///
- public async Task CreateInstance(string org, string app, Instance instanceTemplate)
+ public async Task CreateInstance(
+ string org,
+ string app,
+ Instance instanceTemplate,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ )
{
using var activity = _telemetry?.StartCreateInstanceActivity();
string apiUrl = $"instances?appId={org}/{app}";
- string token = _userTokenProvider.GetUserToken();
+
+ JwtToken token = await _authenticationTokenResolver.GetAccessToken(
+ authenticationMethod ?? _defaultAuthenticationMethod,
+ cancellationToken: cancellationToken
+ );
StringContent content = new(JsonConvert.SerializeObject(instanceTemplate), Encoding.UTF8, "application/json");
HttpResponseMessage response = await _client.PostAsync(token, apiUrl, content);
@@ -209,30 +259,41 @@ public async Task CreateInstance(string org, string app, Instance inst
{
// ! TODO: this null-forgiving operator should be fixed/removed for the next major release
Instance createdInstance = JsonConvert.DeserializeObject(
- await response.Content.ReadAsStringAsync()
+ await response.Content.ReadAsStringAsync(cancellationToken)
)!;
_telemetry?.InstanceCreated(createdInstance);
return createdInstance;
}
_logger.LogError(
- $"Unable to create instance {response.StatusCode} - {await response.Content.ReadAsStringAsync()}"
+ "Unable to create instance {StatusCode} - {Response}",
+ response.StatusCode,
+ await response.Content.ReadAsStringAsync(cancellationToken)
);
throw await PlatformHttpException.CreateAsync(response);
}
///
- public async Task AddCompleteConfirmation(int instanceOwnerPartyId, Guid instanceGuid)
+ public async Task AddCompleteConfirmation(
+ int instanceOwnerPartyId,
+ Guid instanceGuid,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ )
{
using var activity = _telemetry?.StartCompleteConfirmationActivity(instanceGuid, instanceOwnerPartyId);
string apiUrl = $"instances/{instanceOwnerPartyId}/{instanceGuid}/complete";
- string token = _userTokenProvider.GetUserToken();
+
+ JwtToken token = await _authenticationTokenResolver.GetAccessToken(
+ authenticationMethod ?? _defaultAuthenticationMethod,
+ cancellationToken: cancellationToken
+ );
HttpResponseMessage response = await _client.PostAsync(token, apiUrl, new StringContent(string.Empty));
if (response.StatusCode == HttpStatusCode.OK)
{
- string instanceData = await response.Content.ReadAsStringAsync();
+ string instanceData = await response.Content.ReadAsStringAsync(cancellationToken);
// ! TODO: this null-forgiving operator should be fixed/removed for the next major release
Instance instance = JsonConvert.DeserializeObject(instanceData)!;
_telemetry?.InstanceCompleted(instance);
@@ -243,24 +304,37 @@ public async Task AddCompleteConfirmation(int instanceOwnerPartyId, Gu
}
///
- public async Task UpdateReadStatus(int instanceOwnerPartyId, Guid instanceGuid, string readStatus)
+ public async Task UpdateReadStatus(
+ int instanceOwnerPartyId,
+ Guid instanceGuid,
+ string readStatus,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ )
{
using var activity = _telemetry?.StartUpdateReadStatusActivity(instanceGuid, instanceOwnerPartyId);
string apiUrl = $"instances/{instanceOwnerPartyId}/{instanceGuid}/readstatus?status={readStatus}";
- string token = _userTokenProvider.GetUserToken();
+
+ JwtToken token = await _authenticationTokenResolver.GetAccessToken(
+ authenticationMethod ?? _defaultAuthenticationMethod,
+ cancellationToken: cancellationToken
+ );
HttpResponseMessage response = await _client.PutAsync(token, apiUrl, new StringContent(string.Empty));
if (response.StatusCode == HttpStatusCode.OK)
{
- string instanceData = await response.Content.ReadAsStringAsync();
+ string instanceData = await response.Content.ReadAsStringAsync(cancellationToken);
// ! TODO: this null-forgiving operator should be fixed/removed for the next major release
Instance instance = JsonConvert.DeserializeObject(instanceData)!;
return instance;
}
_logger.LogError(
- $"Could not update read status for instance {instanceOwnerPartyId}/{instanceGuid}. Request failed with status code {response.StatusCode}"
+ "Could not update read status for instance {InstanceOwnerPartyId}/{InstanceGuid}. Request failed with status code {StatusCode}",
+ instanceOwnerPartyId,
+ instanceGuid,
+ response.StatusCode
);
#nullable disable
return null;
@@ -268,11 +342,21 @@ public async Task UpdateReadStatus(int instanceOwnerPartyId, Guid inst
}
///
- public async Task UpdateSubstatus(int instanceOwnerPartyId, Guid instanceGuid, Substatus substatus)
+ public async Task UpdateSubstatus(
+ int instanceOwnerPartyId,
+ Guid instanceGuid,
+ Substatus substatus,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ )
{
using var activity = _telemetry?.StartUpdateSubStatusActivity(instanceGuid, instanceOwnerPartyId);
string apiUrl = $"instances/{instanceOwnerPartyId}/{instanceGuid}/substatus";
- string token = _userTokenProvider.GetUserToken();
+
+ JwtToken token = await _authenticationTokenResolver.GetAccessToken(
+ authenticationMethod ?? _defaultAuthenticationMethod,
+ cancellationToken: cancellationToken
+ );
HttpResponseMessage response = await _client.PutAsync(
token,
@@ -282,7 +366,7 @@ public async Task UpdateSubstatus(int instanceOwnerPartyId, Guid insta
if (response.StatusCode == HttpStatusCode.OK)
{
- string instanceData = await response.Content.ReadAsStringAsync();
+ string instanceData = await response.Content.ReadAsStringAsync(cancellationToken);
// ! TODO: this null-forgiving operator should be fixed/removed for the next major release
Instance instance = JsonConvert.DeserializeObject(instanceData)!;
return instance;
@@ -295,12 +379,18 @@ public async Task UpdateSubstatus(int instanceOwnerPartyId, Guid insta
public async Task UpdatePresentationTexts(
int instanceOwnerPartyId,
Guid instanceGuid,
- PresentationTexts presentationTexts
+ PresentationTexts presentationTexts,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
)
{
using var activity = _telemetry?.StartUpdatePresentationTextActivity(instanceGuid, instanceOwnerPartyId);
string apiUrl = $"instances/{instanceOwnerPartyId}/{instanceGuid}/presentationtexts";
- string token = _userTokenProvider.GetUserToken();
+
+ JwtToken token = await _authenticationTokenResolver.GetAccessToken(
+ authenticationMethod ?? _defaultAuthenticationMethod,
+ cancellationToken: cancellationToken
+ );
HttpResponseMessage response = await _client.PutAsync(
token,
@@ -310,7 +400,7 @@ PresentationTexts presentationTexts
if (response.StatusCode == HttpStatusCode.OK)
{
- string instanceData = await response.Content.ReadAsStringAsync();
+ string instanceData = await response.Content.ReadAsStringAsync(cancellationToken);
// ! TODO: this null-forgiving operator should be fixed/removed for the next major release
Instance instance = JsonConvert.DeserializeObject(instanceData)!;
return instance;
@@ -320,11 +410,21 @@ PresentationTexts presentationTexts
}
///
- public async Task UpdateDataValues(int instanceOwnerPartyId, Guid instanceGuid, DataValues dataValues)
+ public async Task UpdateDataValues(
+ int instanceOwnerPartyId,
+ Guid instanceGuid,
+ DataValues dataValues,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ )
{
using var activity = _telemetry?.StartUpdateDataValuesActivity(instanceGuid, instanceOwnerPartyId);
string apiUrl = $"instances/{instanceOwnerPartyId}/{instanceGuid}/datavalues";
- string token = _userTokenProvider.GetUserToken();
+
+ JwtToken token = await _authenticationTokenResolver.GetAccessToken(
+ authenticationMethod ?? _defaultAuthenticationMethod,
+ cancellationToken: cancellationToken
+ );
HttpResponseMessage response = await _client.PutAsync(
token,
@@ -334,7 +434,7 @@ public async Task UpdateDataValues(int instanceOwnerPartyId, Guid inst
if (response.StatusCode == HttpStatusCode.OK)
{
- string instanceData = await response.Content.ReadAsStringAsync();
+ string instanceData = await response.Content.ReadAsStringAsync(cancellationToken);
// ! TODO: this null-forgiving operator should be fixed/removed for the next major release
Instance instance = JsonConvert.DeserializeObject(instanceData)!;
return instance;
@@ -344,17 +444,27 @@ public async Task UpdateDataValues(int instanceOwnerPartyId, Guid inst
}
///
- public async Task DeleteInstance(int instanceOwnerPartyId, Guid instanceGuid, bool hard)
+ public async Task DeleteInstance(
+ int instanceOwnerPartyId,
+ Guid instanceGuid,
+ bool hard,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ )
{
using var activity = _telemetry?.StartDeleteInstanceActivity(instanceGuid, instanceOwnerPartyId);
string apiUrl = $"instances/{instanceOwnerPartyId}/{instanceGuid}?hard={hard}";
- string token = _userTokenProvider.GetUserToken();
+
+ JwtToken token = await _authenticationTokenResolver.GetAccessToken(
+ authenticationMethod ?? _defaultAuthenticationMethod,
+ cancellationToken: cancellationToken
+ );
HttpResponseMessage response = await _client.DeleteAsync(token, apiUrl);
if (response.StatusCode == HttpStatusCode.OK)
{
- string instanceData = await response.Content.ReadAsStringAsync();
+ string instanceData = await response.Content.ReadAsStringAsync(cancellationToken);
// ! TODO: this null-forgiving operator should be fixed/removed for the next major release
Instance instance = JsonConvert.DeserializeObject(instanceData)!;
_telemetry?.InstanceDeleted(instance);
diff --git a/src/Altinn.App.Core/Internal/Instances/IInstanceClient.cs b/src/Altinn.App.Core/Internal/Instances/IInstanceClient.cs
index 9c1fecc0f..4f9487e10 100644
--- a/src/Altinn.App.Core/Internal/Instances/IInstanceClient.cs
+++ b/src/Altinn.App.Core/Internal/Instances/IInstanceClient.cs
@@ -1,3 +1,4 @@
+using Altinn.App.Core.Features;
using Altinn.App.Core.Models;
using Altinn.Platform.Storage.Interface.Models;
using Microsoft.Extensions.Primitives;
@@ -12,27 +13,51 @@ public interface IInstanceClient
///
/// Gets the instance
///
- Task GetInstance(string app, string org, int instanceOwnerPartyId, Guid instanceId);
+ Task GetInstance(
+ string app,
+ string org,
+ int instanceOwnerPartyId,
+ Guid instanceId,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ );
///
/// Gets the instance anew. Instance must have set appId, instanceOwner.PartyId and Id.
///
- Task GetInstance(Instance instance);
+ Task GetInstance(
+ Instance instance,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ );
///
/// Gets a list of instances based on a dictionary of provided query parameters.
///
- Task> GetInstances(Dictionary queryParams);
+ Task> GetInstances(
+ Dictionary queryParams,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ );
///
/// Updates the process model of the instance and returns the updated instance.
///
- Task UpdateProcess(Instance instance);
+ Task UpdateProcess(
+ Instance instance,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ );
///
/// Updates the process model of the instance and the instance events and returns the updated instance.
///
- Task UpdateProcessAndEvents(Instance instance, List events);
+ Task UpdateProcessAndEvents(
+ Instance instance,
+ List events,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ );
///
/// Creates an instance of an application with no data.
@@ -40,8 +65,16 @@ public interface IInstanceClient
/// Unique identifier of the organisation responsible for the app.
/// Application identifier which is unique within an organisation.
/// the instance template to create (must have instanceOwner with partyId, personNumber or organisationNumber set)
+ /// An optional specification of the authentication method to use for requests
+ /// An optional cancellation token
/// The created instance
- Task CreateInstance(string org, string app, Instance instanceTemplate);
+ Task CreateInstance(
+ string org,
+ string app,
+ Instance instanceTemplate,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ );
///
/// Add complete confirmation.
@@ -53,8 +86,15 @@ public interface IInstanceClient
///
/// The party id of the instance owner.
/// The id of the instance to confirm as complete.
+ /// An optional specification of the authentication method to use for requests
+ /// An optional cancellation token
/// Returns the updated instance.
- Task AddCompleteConfirmation(int instanceOwnerPartyId, Guid instanceGuid);
+ Task AddCompleteConfirmation(
+ int instanceOwnerPartyId,
+ Guid instanceGuid,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ );
///
/// Update read status.
@@ -62,8 +102,16 @@ public interface IInstanceClient
/// The party id of the instance owner.
/// The id of the instance to confirm as complete.
/// The new instance read status.
+ /// An optional specification of the authentication method to use for requests
+ /// An optional cancellation token
/// Returns the updated instance.
- Task UpdateReadStatus(int instanceOwnerPartyId, Guid instanceGuid, string readStatus);
+ Task UpdateReadStatus(
+ int instanceOwnerPartyId,
+ Guid instanceGuid,
+ string readStatus,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ );
///
/// Update substatus.
@@ -71,8 +119,16 @@ public interface IInstanceClient
/// The party id of the instance owner.
/// The id of the instance to be updated.
/// The new substatus.
+ /// An optional specification of the authentication method to use for requests
+ /// An optional cancellation token
/// Returns the updated instance.
- Task UpdateSubstatus(int instanceOwnerPartyId, Guid instanceGuid, Substatus substatus);
+ Task UpdateSubstatus(
+ int instanceOwnerPartyId,
+ Guid instanceGuid,
+ Substatus substatus,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ );
///
/// Update presentation texts.
@@ -83,11 +139,15 @@ public interface IInstanceClient
/// The party id of the instance owner.
/// The id of the instance to update presentation texts for.
/// The presentation texts
+ /// An optional specification of the authentication method to use for requests
+ /// An optional cancellation token
/// Returns the updated instance.
Task UpdatePresentationTexts(
int instanceOwnerPartyId,
Guid instanceGuid,
- PresentationTexts presentationTexts
+ PresentationTexts presentationTexts,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
);
///
@@ -99,8 +159,16 @@ PresentationTexts presentationTexts
/// The party id of the instance owner.
/// The id of the instance to update data values for.
/// The data values
+ /// An optional specification of the authentication method to use for requests
+ /// An optional cancellation token
/// Returns the updated instance.
- Task UpdateDataValues(int instanceOwnerPartyId, Guid instanceGuid, DataValues dataValues);
+ Task UpdateDataValues(
+ int instanceOwnerPartyId,
+ Guid instanceGuid,
+ DataValues dataValues,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ );
///
/// Update data data values.
@@ -110,11 +178,24 @@ PresentationTexts presentationTexts
///
/// The instance
/// The data value (null unsets the value)
+ /// An optional specification of the authentication method to use for requests
+ /// An optional cancellation token
/// Returns the updated instance.
- async Task UpdateDataValues(Instance instance, Dictionary dataValues)
+ async Task UpdateDataValues(
+ Instance instance,
+ Dictionary dataValues,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ )
{
var id = new InstanceIdentifier(instance);
- return await UpdateDataValues(id.InstanceOwnerPartyId, id.InstanceGuid, new DataValues { Values = dataValues });
+ return await UpdateDataValues(
+ id.InstanceOwnerPartyId,
+ id.InstanceGuid,
+ new DataValues { Values = dataValues },
+ authenticationMethod,
+ cancellationToken
+ );
}
///
@@ -126,10 +207,23 @@ async Task UpdateDataValues(Instance instance, DictionaryThe instance
/// The key of the DataValues collection to be updated.
/// The data value (null unsets the value)
+ /// An optional specification of the authentication method to use for requests
+ /// An optional cancellation token
/// Returns the updated instance.
- async Task UpdateDataValue(Instance instance, string key, string? value)
+ async Task UpdateDataValue(
+ Instance instance,
+ string key,
+ string? value,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ )
{
- return await UpdateDataValues(instance, new Dictionary { { key, value } });
+ return await UpdateDataValues(
+ instance,
+ new Dictionary { { key, value } },
+ authenticationMethod,
+ cancellationToken
+ );
}
///
@@ -138,6 +232,14 @@ async Task UpdateDataValue(Instance instance, string key, string? valu
/// The party id of the instance owner.
/// The id of the instance to delete.
/// Boolean to indicate if instance should be hard deleted.
+ /// An optional specification of the authentication method to use for requests
+ /// An optional cancellation token
/// Returns the deleted instance.
- Task DeleteInstance(int instanceOwnerPartyId, Guid instanceGuid, bool hard);
+ Task DeleteInstance(
+ int instanceOwnerPartyId,
+ Guid instanceGuid,
+ bool hard,
+ StorageAuthenticationMethod? authenticationMethod = null,
+ CancellationToken cancellationToken = default
+ );
}
diff --git a/test/Altinn.App.Api.Tests/Controllers/FileScanControllerTests.cs b/test/Altinn.App.Api.Tests/Controllers/FileScanControllerTests.cs
index a0ae2f1ec..c9094eca6 100644
--- a/test/Altinn.App.Api.Tests/Controllers/FileScanControllerTests.cs
+++ b/test/Altinn.App.Api.Tests/Controllers/FileScanControllerTests.cs
@@ -1,4 +1,5 @@
using Altinn.App.Api.Controllers;
+using Altinn.App.Core.Features;
using Altinn.App.Core.Internal.Instances;
using Altinn.Platform.Storage.Interface.Models;
using FluentAssertions;
@@ -68,7 +69,16 @@ Guid instanceId
var instanceClientMock = new Mock();
instanceClientMock
- .Setup(e => e.GetInstance(app, org, instanceOwnerPartyId, instanceId))
+ .Setup(e =>
+ e.GetInstance(
+ app,
+ org,
+ instanceOwnerPartyId,
+ instanceId,
+ It.IsAny(),
+ It.IsAny()
+ )
+ )
.Returns(Task.FromResult(instance));
return instanceClientMock;
diff --git a/test/Altinn.App.Api.Tests/Controllers/InstancesController_ActiveInstancesTests.cs b/test/Altinn.App.Api.Tests/Controllers/InstancesController_ActiveInstancesTests.cs
index b9ccb89ce..fa7a47239 100644
--- a/test/Altinn.App.Api.Tests/Controllers/InstancesController_ActiveInstancesTests.cs
+++ b/test/Altinn.App.Api.Tests/Controllers/InstancesController_ActiveInstancesTests.cs
@@ -1,5 +1,6 @@
using Altinn.App.Api.Controllers;
using Altinn.App.Api.Models;
+using Altinn.App.Core.Features;
using Altinn.App.Core.Internal.Instances;
using Altinn.App.Core.Internal.Profile;
using Altinn.App.Core.Internal.Registers;
@@ -28,7 +29,13 @@ public async Task EmptySearchResult_ReturnsOkResult()
fixture
.Mock()
- .Setup(c => c.GetInstances(It.IsAny>()))
+ .Setup(c =>
+ c.GetInstances(
+ It.IsAny>(),
+ It.IsAny(),
+ It.IsAny()
+ )
+ )
.ReturnsAsync(instances);
// Act
@@ -42,7 +49,13 @@ public async Task EmptySearchResult_ReturnsOkResult()
fixture
.Mock()
- .Verify(c => c.GetInstances(It.Is>(query => query.ContainsKey("appId"))));
+ .Verify(c =>
+ c.GetInstances(
+ It.Is>(query => query.ContainsKey("appId")),
+ It.IsAny(),
+ It.IsAny()
+ )
+ );
fixture.VerifyNoOtherCalls();
}
@@ -80,7 +93,13 @@ public async Task UnknownUser_ReturnsEmptyString()
fixture
.Mock()
- .Setup(c => c.GetInstances(It.IsAny>()))
+ .Setup(c =>
+ c.GetInstances(
+ It.IsAny>(),
+ It.IsAny(),
+ It.IsAny()
+ )
+ )
.ReturnsAsync(instances);
// _profile.Setup(p=>p.GetUserProfile(12345)).ReturnsAsync(default(UserProfile)!);
@@ -95,7 +114,13 @@ public async Task UnknownUser_ReturnsEmptyString()
fixture
.Mock()
- .Verify(c => c.GetInstances(It.Is>(query => query.ContainsKey("appId"))));
+ .Verify(c =>
+ c.GetInstances(
+ It.Is>(query => query.ContainsKey("appId")),
+ It.IsAny(),
+ It.IsAny()
+ )
+ );
fixture.Mock().Verify(p => p.GetUserProfile(12345));
fixture.VerifyNoOtherCalls();
}
@@ -133,7 +158,13 @@ public async Task UserProfilePartyIsNull_ReturnsEmptyString()
fixture
.Mock()
- .Setup(c => c.GetInstances(It.IsAny>()))
+ .Setup(c =>
+ c.GetInstances(
+ It.IsAny>(),
+ It.IsAny(),
+ It.IsAny()
+ )
+ )
.ReturnsAsync(instances);
fixture.Mock().Setup(p => p.GetUserProfile(12345)).ReturnsAsync(new UserProfile());
@@ -148,7 +179,13 @@ public async Task UserProfilePartyIsNull_ReturnsEmptyString()
fixture
.Mock()
- .Verify(c => c.GetInstances(It.Is>(query => query.ContainsKey("appId"))));
+ .Verify(c =>
+ c.GetInstances(
+ It.Is>(query => query.ContainsKey("appId")),
+ It.IsAny(),
+ It.IsAny()
+ )
+ );
fixture.Mock().Verify(p => p.GetUserProfile(12345));
fixture.VerifyNoOtherCalls();
}
@@ -184,7 +221,13 @@ public async Task KnownUser_ReturnsUserName()
fixture
.Mock()
- .Setup(c => c.GetInstances(It.IsAny>()))
+ .Setup(c =>
+ c.GetInstances(
+ It.IsAny>(),
+ It.IsAny(),
+ It.IsAny()
+ )
+ )
.ReturnsAsync(instances);
fixture
.Mock()
@@ -202,7 +245,13 @@ public async Task KnownUser_ReturnsUserName()
fixture
.Mock()
- .Verify(c => c.GetInstances(It.Is>(query => query.ContainsKey("appId"))));
+ .Verify(c =>
+ c.GetInstances(
+ It.Is>(query => query.ContainsKey("appId")),
+ It.IsAny(),
+ It.IsAny()
+ )
+ );
fixture.Mock().Verify(p => p.GetUserProfile(12345));
fixture.VerifyNoOtherCalls();
}
@@ -239,7 +288,13 @@ public async Task LastChangedBy9digits_LooksForOrg()
fixture
.Mock()
- .Setup(c => c.GetInstances(It.IsAny>()))
+ .Setup(c =>
+ c.GetInstances(
+ It.IsAny>(),
+ It.IsAny(),
+ It.IsAny()
+ )
+ )
.ReturnsAsync(instances);
fixture
.Mock()
@@ -257,7 +312,13 @@ public async Task LastChangedBy9digits_LooksForOrg()
fixture
.Mock()
- .Verify(c => c.GetInstances(It.Is>(query => query.ContainsKey("appId"))));
+ .Verify(c =>
+ c.GetInstances(
+ It.Is>(query => query.ContainsKey("appId")),
+ It.IsAny(),
+ It.IsAny()
+ )
+ );
fixture.Mock().Verify(er => er.GetOrganization("123456789"));
fixture.VerifyNoOtherCalls();
}
@@ -293,7 +354,13 @@ public async Task LastChangedBy9digits_FindsOrg()
fixture
.Mock()
- .Setup(c => c.GetInstances(It.IsAny>()))
+ .Setup(c =>
+ c.GetInstances(
+ It.IsAny>(),
+ It.IsAny(),
+ It.IsAny()
+ )
+ )
.ReturnsAsync(instances);
fixture
.Mock()
@@ -311,7 +378,13 @@ public async Task LastChangedBy9digits_FindsOrg()
fixture
.Mock()
- .Verify(c => c.GetInstances(It.Is>(query => query.ContainsKey("appId"))));
+ .Verify(c =>
+ c.GetInstances(
+ It.Is>(query => query.ContainsKey("appId")),
+ It.IsAny(),
+ It.IsAny()
+ )
+ );
fixture.Mock().Verify(er => er.GetOrganization("123456789"));
fixture.VerifyNoOtherCalls();
}
diff --git a/test/Altinn.App.Api.Tests/Controllers/InstancesController_CopyInstanceTests.cs b/test/Altinn.App.Api.Tests/Controllers/InstancesController_CopyInstanceTests.cs
index 68f2a991b..097d9879b 100644
--- a/test/Altinn.App.Api.Tests/Controllers/InstancesController_CopyInstanceTests.cs
+++ b/test/Altinn.App.Api.Tests/Controllers/InstancesController_CopyInstanceTests.cs
@@ -155,7 +155,16 @@ public async Task CopyInstance_InstanceNotArchived_ReturnsBadRequest()
.ReturnsAsync(CreateXacmlResponse("Permit"));
fixture
.Mock()
- .Setup(i => i.GetInstance(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()))
+ .Setup(i =>
+ i.GetInstance(
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny()
+ )
+ )
.ReturnsAsync(instance);
// Act
@@ -203,7 +212,16 @@ public async Task CopyInstance_InstanceDoesNotExists_ReturnsBadRequest()
.ReturnsAsync(CreateXacmlResponse("Permit"));
fixture
.Mock()
- .Setup(i => i.GetInstance(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()))
+ .Setup(i =>
+ i.GetInstance(
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny()
+ )
+ )
.ThrowsAsync(platformHttpException);
// Act
@@ -251,7 +269,16 @@ public async Task CopyInstance_PlatformReturnsError_ThrowsException()
.ReturnsAsync(CreateXacmlResponse("Permit"));
fixture
.Mock()
- .Setup(i => i.GetInstance(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()))
+ .Setup(i =>
+ i.GetInstance(
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny()
+ )
+ )
.ThrowsAsync(platformHttpException);
// Act
@@ -298,7 +325,16 @@ public async Task CopyInstance_InstantiationValidationFails_ReturnsForbidden()
.ReturnsAsync(CreateXacmlResponse("Permit"));
fixture
.Mock()
- .Setup(i => i.GetInstance(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()))
+ .Setup(i =>
+ i.GetInstance(
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny()
+ )
+ )
.ReturnsAsync(instance);
fixture
.Mock()
@@ -363,13 +399,39 @@ public async Task CopyInstance_EverythingIsFine_ReturnsRedirect()
.ReturnsAsync(CreateXacmlResponse("Permit"));
fixture
.Mock()
- .Setup(i => i.GetInstance(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()))
+ .Setup(i =>
+ i.GetInstance(
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny()
+ )
+ )
.ReturnsAsync(instance);
fixture
.Mock()
- .Setup(i => i.CreateInstance(It.IsAny(), It.IsAny(), It.IsAny()))
+ .Setup(i =>
+ i.CreateInstance(
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny()
+ )
+ )
+ .ReturnsAsync(instance);
+ fixture
+ .Mock()
+ .Setup(i =>
+ i.GetInstance(
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny()
+ )
+ )
.ReturnsAsync(instance);
- fixture.Mock().Setup(i => i.GetInstance(It.IsAny())).ReturnsAsync(instance);
fixture
.Mock()
.Setup(v => v.Validate(It.IsAny()))
@@ -494,13 +556,39 @@ public async Task CopyInstance_WithBinaryData_CopiesBothFormAndBinaryData()
.ReturnsAsync(CreateXacmlResponse("Permit"));
fixture
.Mock()
- .Setup(i => i.GetInstance(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()))
+ .Setup(i =>
+ i.GetInstance(
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny