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

fix: enhance subscription/provider endpoint with external Service data #867

Merged
merged 2 commits into from
Jul 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public IAsyncEnumerable<AgreementData> GetAppAgreement(Guid appId) =>

/// <inheritdoc />
public Task<AppProviderSubscriptionDetailData> GetSubscriptionDetailForProvider(Guid appId, Guid subscriptionId) =>
_offerService.GetAppSubscriptionDetailsForProviderAsync(appId, subscriptionId, OfferTypeId.APP, _settings.CompanyAdminRoles);
_offerService.GetAppSubscriptionDetailsForProviderAsync(appId, subscriptionId, OfferTypeId.APP, _settings.CompanyAdminRoles, new WalletConfigData(_settings.IssuerDid, _settings.BpnDidResolverUrl, _settings.DecentralIdentityManagementAuthUrl));

/// <inheritdoc />
public Task<SubscriberSubscriptionDetailData> GetSubscriptionDetailForSubscriber(Guid appId, Guid subscriptionId) =>
Expand Down
9 changes: 9 additions & 0 deletions src/marketplace/Apps.Service/BusinessLogic/AppsSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ public class AppsSettings
[Required]
[DistinctValues("x => x.DocumentTypeId")]
public IEnumerable<UploadDocumentConfig> UploadActiveAppDocumentTypeIds { get; set; } = null!;

[Required(AllowEmptyStrings = true)]
public string DecentralIdentityManagementAuthUrl { get; set; } = null!;

[Required(AllowEmptyStrings = true)]
public string IssuerDid { get; set; } = null!;

[Required(AllowEmptyStrings = true)]
public string BpnDidResolverUrl { get; set; } = null!;
}

/// <summary>
Expand Down
26 changes: 26 additions & 0 deletions src/marketplace/Offers.Library/Models/WalletConfigData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

namespace Org.Eclipse.TractusX.Portal.Backend.Offers.Library.Models;

public record WalletConfigData(
string IssuerDid,
string BpnDidResolverUrl,
string DecentralIdentityManagementAuthUrl
);
3 changes: 2 additions & 1 deletion src/marketplace/Offers.Library/Service/IOfferService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,9 @@ Task CreateOrUpdateOfferSubscriptionAgreementConsentAsync(Guid subscriptionId,
/// <param name="subscriptionId">Id of the subscription</param>
/// <param name="offerTypeId">Offer type</param>
/// <param name="contactUserRoles">The roles of the users that will be listed as contact</param>
/// <param name="walletData">The information for the external service data</param>
/// <returns>Returns the details of the subscription</returns>
Task<AppProviderSubscriptionDetailData> GetAppSubscriptionDetailsForProviderAsync(Guid offerId, Guid subscriptionId, OfferTypeId offerTypeId, IEnumerable<UserRoleConfig> contactUserRoles);
Task<AppProviderSubscriptionDetailData> GetAppSubscriptionDetailsForProviderAsync(Guid offerId, Guid subscriptionId, OfferTypeId offerTypeId, IEnumerable<UserRoleConfig> contactUserRoles, WalletConfigData walletData);

/// <summary>
/// Unsubscribe the Offer subscription by subscriptionId
Expand Down
23 changes: 21 additions & 2 deletions src/marketplace/Offers.Library/Service/OfferService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -824,11 +824,30 @@ public Task<ProviderSubscriptionDetailData> GetSubscriptionDetailsForProviderAsy
GetOfferSubscriptionDetailsInternal(offerId, subscriptionId, offerTypeId, contactUserRoles, OfferCompanyRole.Provider, _portalRepositories.GetInstance<IOfferSubscriptionsRepository>().GetSubscriptionDetailsForProviderAsync);

/// <inheritdoc />
public async Task<AppProviderSubscriptionDetailData> GetAppSubscriptionDetailsForProviderAsync(Guid offerId, Guid subscriptionId, OfferTypeId offerTypeId, IEnumerable<UserRoleConfig> contactUserRoles)
public async Task<AppProviderSubscriptionDetailData> GetAppSubscriptionDetailsForProviderAsync(Guid offerId, Guid subscriptionId, OfferTypeId offerTypeId, IEnumerable<UserRoleConfig> contactUserRoles, WalletConfigData walletData)
{
var data = await GetOfferSubscriptionDetailsInternal(offerId, subscriptionId, offerTypeId, contactUserRoles, OfferCompanyRole.Provider, _portalRepositories.GetInstance<IOfferSubscriptionsRepository>().GetAppSubscriptionDetailsForProviderAsync)
.ConfigureAwait(ConfigureAwaitOptions.None);
return new AppProviderSubscriptionDetailData(data.Id, data.OfferSubscriptionStatus, data.Name, data.Customer, data.Bpn, data.Contact, data.TechnicalUserData, data.TenantUrl, data.AppInstanceId, data.ProcessSteps.GetProcessStepTypeId(data.Id, _logger));

return new AppProviderSubscriptionDetailData(
data.Id,
data.OfferSubscriptionStatus,
data.Name,
data.Customer,
data.Bpn,
data.Contact,
data.TechnicalUserData,
data.ConnectorData,
data.TenantUrl,
data.AppInstanceId,
data.ProcessSteps.GetProcessStepTypeId(data.Id, _logger),
new SubscriptionExternalServiceData(
walletData.IssuerDid,
data.ExternalServiceData?.ParticipantId,
data.ExternalServiceData == null || data.ExternalServiceData.TrustedIssuer.EndsWith(":holder-iatp") ? data.ExternalServiceData?.TrustedIssuer : $"{data.ExternalServiceData.TrustedIssuer}:holder-iatp",
walletData.BpnDidResolverUrl,
walletData.DecentralIdentityManagementAuthUrl,
data.ExternalServiceData?.DecentralIdentityManagementServiceUrl));
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,20 @@ public record AppProviderSubscriptionDetailData(
string? Bpn,
IEnumerable<string> Contact,
IEnumerable<SubscriptionTechnicalUserData> TechnicalUserData,
IEnumerable<SubscriptionAssignedConnectorData> ConnectorData,
string? TenantUrl,
string AppInstanceId,
ProcessStepTypeId? ProcessStepTypeId
ProcessStepTypeId? ProcessStepTypeId,
SubscriptionExternalServiceData ExternalService
);

public record SubscriptionExternalServiceData(
[property: JsonPropertyName("trusted_issuer")] string TrustedIssuer,
[property: JsonPropertyName("participant_id")] string? ParticipantId,
[property: JsonPropertyName("iatp_id")] string? IatpId,
[property: JsonPropertyName("did_resolver")] string DidResolver,
[property: JsonPropertyName("decentralIdentityManagementAuthUrl")] string DecentralIdentityManagementAuthUrl,
[property: JsonPropertyName("decentralIdentityManagementServiceUrl")] string? DecentralIdentityManagementServiceUrl
);

/// <summary>
Expand Down Expand Up @@ -126,5 +137,13 @@ public record AppProviderSubscriptionDetail(
IEnumerable<SubscriptionTechnicalUserData> TechnicalUserData,
string? TenantUrl,
string AppInstanceId,
IEnumerable<(ProcessStepTypeId ProcessStepTypeId, ProcessStepStatusId ProcessStepStatusId)> ProcessSteps
IEnumerable<(ProcessStepTypeId ProcessStepTypeId, ProcessStepStatusId ProcessStepStatusId)> ProcessSteps,
IEnumerable<SubscriptionAssignedConnectorData> ConnectorData,
ExternalServiceData? ExternalServiceData
);

public record ExternalServiceData(
[property: JsonPropertyName("trusted_issuer")] string TrustedIssuer,
[property: JsonPropertyName("participant_id")] string? ParticipantId,
[property: JsonPropertyName("decentralIdentityManagementServiceUrl")] string DecentralIdentityManagementServiceUrl
);
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ public OfferSubscription AttachAndModifyOfferSubscription(Guid offerSubscription
.Select(ps => new ValueTuple<ProcessStepTypeId, ProcessStepStatusId>(
ps.ProcessStepTypeId,
ps.ProcessStepStatusId))
.Distinct())
.Distinct(),
x.Subscription.ConnectorAssignedOfferSubscriptions.Select(c => new SubscriptionAssignedConnectorData(c.ConnectorId, c.Connector!.Name, c.Connector.ConnectorUrl)),
x.Company.CompanyWalletData == null ? null : new ExternalServiceData(x.Company.CompanyWalletData!.Did, x.Company.BusinessPartnerNumber, x.Company.CompanyWalletData.AuthenticationServiceUrl))
: null))
.SingleOrDefaultAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public async Task GetSubscriptionDetailForProvider_ReturnsExpected()
new UserRoleConfig("ClientTest", new[] {"Test"})
}
};
A.CallTo(() => _offerService.GetAppSubscriptionDetailsForProviderAsync(A<Guid>._, A<Guid>._, A<OfferTypeId>._, A<IEnumerable<UserRoleConfig>>._))
A.CallTo(() => _offerService.GetAppSubscriptionDetailsForProviderAsync(A<Guid>._, A<Guid>._, A<OfferTypeId>._, A<IEnumerable<UserRoleConfig>>._, A<WalletConfigData>._))
.Returns(data);
var sut = new AppsBusinessLogic(null!, null!, _offerService, null!, Options.Create(settings), _identityService, _logger);

Expand All @@ -516,7 +516,7 @@ public async Task GetSubscriptionDetailForProvider_ReturnsExpected()

// Assert
result.Should().Be(data);
A.CallTo(() => _offerService.GetAppSubscriptionDetailsForProviderAsync(appId, subscriptionId, OfferTypeId.APP, A<IEnumerable<UserRoleConfig>>._))
A.CallTo(() => _offerService.GetAppSubscriptionDetailsForProviderAsync(appId, subscriptionId, OfferTypeId.APP, A<IEnumerable<UserRoleConfig>>._, A<WalletConfigData>._))
.MustHaveHappenedOnceExactly();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@
}
],
"OfferSubscriptionAddress": "https://test.de",
"OfferDetailAddress": "https://detail.de"
"OfferDetailAddress": "https://detail.de",
"DecentralIdentityManagementAuthUrl": "https://test.org/auth",
"IssuerDid": "did:web:example.org:test123",
"BpnDidResolverUrl": "https://test.org/bpn-did"
},
"Provisioning": {
"CentralRealm": "CX-Central",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2218,11 +2218,12 @@ public async Task GetAppSubscriptionDetailForProvider_WithNotMatchingUserRoles_T
var offerId = Guid.NewGuid();
var subscriptionId = Guid.NewGuid();
var companyAdminRoles = _fixture.CreateMany<UserRoleConfig>().ToImmutableArray();
var walletData = _fixture.Create<WalletConfigData>();

SetupGetSubscriptionDetailForProvider();

// Act
async Task Act() => await _sut.GetAppSubscriptionDetailsForProviderAsync(offerId, subscriptionId, OfferTypeId.APP, companyAdminRoles);
async Task Act() => await _sut.GetAppSubscriptionDetailsForProviderAsync(offerId, subscriptionId, OfferTypeId.APP, companyAdminRoles, walletData);

// Assert
var ex = await Assert.ThrowsAsync<ConfigurationException>(Act);
Expand All @@ -2243,13 +2244,14 @@ public async Task GetAppSubscriptionDetailForProvider_WithNotExistingOffer_Throw
{
new UserRoleConfig("ClientTest", new[] {"Test"})
};
var walletData = _fixture.Create<WalletConfigData>();
SetupGetSubscriptionDetailForProvider();

A.CallTo(() => _offerSubscriptionsRepository.GetAppSubscriptionDetailsForProviderAsync(A<Guid>._, A<Guid>._, A<Guid>._, A<OfferTypeId>._, A<IEnumerable<Guid>>._))
.Returns<(bool, bool, AppProviderSubscriptionDetail?)>(default);

// Act
async Task Act() => await _sut.GetAppSubscriptionDetailsForProviderAsync(appId, subscriptionId, OfferTypeId.APP, companyAdminRoles);
async Task Act() => await _sut.GetAppSubscriptionDetailsForProviderAsync(appId, subscriptionId, OfferTypeId.APP, companyAdminRoles, walletData);

// Assert
var ex = await Assert.ThrowsAsync<NotFoundException>(Act);
Expand All @@ -2270,13 +2272,14 @@ public async Task GetAppSubscriptionDetailForProvider_WithUserNotInProvidingComp
{
new UserRoleConfig("ClientTest", new[] {"Test"})
};
var walletData = _fixture.Create<WalletConfigData>();
SetupGetSubscriptionDetailForProvider();

A.CallTo(() => _offerSubscriptionsRepository.GetAppSubscriptionDetailsForProviderAsync(A<Guid>._, A<Guid>._, A<Guid>._, A<OfferTypeId>._, A<IEnumerable<Guid>>._))
.Returns((true, false, _fixture.Create<AppProviderSubscriptionDetail>()));

// Act
async Task Act() => await _sut.GetAppSubscriptionDetailsForProviderAsync(appId, subscriptionId, OfferTypeId.APP, companyAdminRoles);
async Task Act() => await _sut.GetAppSubscriptionDetailsForProviderAsync(appId, subscriptionId, OfferTypeId.APP, companyAdminRoles, walletData);

// Assert
var ex = await Assert.ThrowsAsync<ForbiddenException>(Act);
Expand All @@ -2297,6 +2300,7 @@ public async Task GetAppSubscriptionDetailForProvider_WithValidData_ReturnsExpec
{
new UserRoleConfig("ClientTest", new[] {"Test"})
};
var walletData = _fixture.Create<WalletConfigData>();
SetupGetSubscriptionDetailForProvider();

var data = _fixture.Create<AppProviderSubscriptionDetail>();
Expand All @@ -2305,7 +2309,7 @@ public async Task GetAppSubscriptionDetailForProvider_WithValidData_ReturnsExpec
.Returns((true, true, data));

// Act
var result = await _sut.GetAppSubscriptionDetailsForProviderAsync(appId, subscriptionId, OfferTypeId.APP, companyAdminRoles);
var result = await _sut.GetAppSubscriptionDetailsForProviderAsync(appId, subscriptionId, OfferTypeId.APP, companyAdminRoles, walletData);

// Assert
result.Id.Should().Be(data.Id);
Expand Down
Loading