Skip to content

Commit

Permalink
feat(openUrl): Add Endpoints for public apis foreach service (#161)
Browse files Browse the repository at this point in the history
* add GET endpoint to all services /api/info to receive the api endpoints filtered for the companyRole
* test(openApi): add unit tests for GetPublicUrls
Refs: CPLP-2958
---------
Co-authored-by: Norbert Truchsess <[email protected]>
Reviewed-By: Norbert Truchsess <[email protected]>
  • Loading branch information
Phil91 authored Aug 11, 2023
1 parent f4f7cdd commit 39c81fc
Show file tree
Hide file tree
Showing 55 changed files with 1,757 additions and 249 deletions.
30 changes: 30 additions & 0 deletions src/Portal.Backend.sln
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Framework.Models.Tests", ".
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Framework.ProcessIdentity", "framework\Framework.ProcessIdentity\Framework.ProcessIdentity.csproj", "{4CA307AB-A0F8-4AA5-A09D-91F47DA3054A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Framework.PublicInfos", "framework\Framework.PublicInfos\Framework.PublicInfos.csproj", "{47E089E3-E875-4045-9E58-C1223BE899E9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Framework.PublicInfos.Tests", "..\tests\framework\Framework.PublicInfos.Tests\Framework.PublicInfos.Tests.csproj", "{9D574E57-75A6-4965-AF23-ACE0BB9CD0B3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1284,6 +1288,30 @@ Global
{4CA307AB-A0F8-4AA5-A09D-91F47DA3054A}.Release|x64.Build.0 = Release|Any CPU
{4CA307AB-A0F8-4AA5-A09D-91F47DA3054A}.Release|x86.ActiveCfg = Release|Any CPU
{4CA307AB-A0F8-4AA5-A09D-91F47DA3054A}.Release|x86.Build.0 = Release|Any CPU
{47E089E3-E875-4045-9E58-C1223BE899E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{47E089E3-E875-4045-9E58-C1223BE899E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{47E089E3-E875-4045-9E58-C1223BE899E9}.Debug|x64.ActiveCfg = Debug|Any CPU
{47E089E3-E875-4045-9E58-C1223BE899E9}.Debug|x64.Build.0 = Debug|Any CPU
{47E089E3-E875-4045-9E58-C1223BE899E9}.Debug|x86.ActiveCfg = Debug|Any CPU
{47E089E3-E875-4045-9E58-C1223BE899E9}.Debug|x86.Build.0 = Debug|Any CPU
{47E089E3-E875-4045-9E58-C1223BE899E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{47E089E3-E875-4045-9E58-C1223BE899E9}.Release|Any CPU.Build.0 = Release|Any CPU
{47E089E3-E875-4045-9E58-C1223BE899E9}.Release|x64.ActiveCfg = Release|Any CPU
{47E089E3-E875-4045-9E58-C1223BE899E9}.Release|x64.Build.0 = Release|Any CPU
{47E089E3-E875-4045-9E58-C1223BE899E9}.Release|x86.ActiveCfg = Release|Any CPU
{47E089E3-E875-4045-9E58-C1223BE899E9}.Release|x86.Build.0 = Release|Any CPU
{9D574E57-75A6-4965-AF23-ACE0BB9CD0B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D574E57-75A6-4965-AF23-ACE0BB9CD0B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D574E57-75A6-4965-AF23-ACE0BB9CD0B3}.Debug|x64.ActiveCfg = Debug|Any CPU
{9D574E57-75A6-4965-AF23-ACE0BB9CD0B3}.Debug|x64.Build.0 = Debug|Any CPU
{9D574E57-75A6-4965-AF23-ACE0BB9CD0B3}.Debug|x86.ActiveCfg = Debug|Any CPU
{9D574E57-75A6-4965-AF23-ACE0BB9CD0B3}.Debug|x86.Build.0 = Debug|Any CPU
{9D574E57-75A6-4965-AF23-ACE0BB9CD0B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D574E57-75A6-4965-AF23-ACE0BB9CD0B3}.Release|Any CPU.Build.0 = Release|Any CPU
{9D574E57-75A6-4965-AF23-ACE0BB9CD0B3}.Release|x64.ActiveCfg = Release|Any CPU
{9D574E57-75A6-4965-AF23-ACE0BB9CD0B3}.Release|x64.Build.0 = Release|Any CPU
{9D574E57-75A6-4965-AF23-ACE0BB9CD0B3}.Release|x86.ActiveCfg = Release|Any CPU
{9D574E57-75A6-4965-AF23-ACE0BB9CD0B3}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1381,5 +1409,7 @@ Global
{031237BF-7B2A-4B37-9E37-4D4C575FDD22} = {23500169-FC01-4D2B-A997-E7FAE2169FC0}
{CB9FFDD9-7F41-44DA-BFA8-C157A96D51F6} = {23500169-FC01-4D2B-A997-E7FAE2169FC0}
{4CA307AB-A0F8-4AA5-A09D-91F47DA3054A} = {23500169-FC01-4D2B-A997-E7FAE2169FC0}
{47E089E3-E875-4045-9E58-C1223BE899E9} = {23500169-FC01-4D2B-A997-E7FAE2169FC0}
{9D574E57-75A6-4965-AF23-ACE0BB9CD0B3} = {323C198D-A8C6-4EB0-8B79-72624275E35F}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Library;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models;
using Org.Eclipse.TractusX.Portal.Backend.Framework.PublicInfos;
using Org.Eclipse.TractusX.Portal.Backend.Keycloak.Authentication;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
using Org.Eclipse.TractusX.Portal.Backend.SdFactory.Library.Models;

namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Controllers;
Expand Down Expand Up @@ -84,6 +86,7 @@ public ConnectorsController(IConnectorsBusinessLogic connectorsBusinessLogic)
[Authorize(Roles = "view_connectors")]
[Authorize(Policy = PolicyTypes.ValidCompany)]
[ProducesResponseType(typeof(Pagination.Response<ConnectorData>), StatusCodes.Status200OK)]
[PublicUrl(CompanyRoleId.APP_PROVIDER, CompanyRoleId.SERVICE_PROVIDER)]
public Task<Pagination.Response<ManagedConnectorData>> GetManagedConnectorsForCurrentUserAsync([FromQuery] int page = 0, [FromQuery] int size = 15) =>
_businessLogic.GetManagedConnectorForCompany(page, size);

Expand Down Expand Up @@ -145,6 +148,7 @@ public async Task<CreatedAtRouteResult> CreateConnectorAsync([FromForm] Connecto
[ProducesResponseType(typeof(Guid), StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status503ServiceUnavailable)]
[PublicUrl(CompanyRoleId.APP_PROVIDER, CompanyRoleId.SERVICE_PROVIDER)]
public async Task<CreatedAtRouteResult> CreateManagedConnectorAsync([FromForm] ManagedConnectorInputModel connectorInputModel, CancellationToken cancellationToken)
{
var connectorId = await _businessLogic.CreateManagedConnectorAsync(connectorInputModel, cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -182,6 +186,7 @@ public async Task<IActionResult> DeleteConnectorAsync([FromRoute] Guid connector
[Route("discovery")]
[Authorize(Roles = "view_connectors")]
[ProducesResponseType(typeof(IAsyncEnumerable<ConnectorEndPointData>), StatusCodes.Status200OK)]
[PublicUrl(CompanyRoleId.APP_PROVIDER, CompanyRoleId.SERVICE_PROVIDER, CompanyRoleId.ACTIVE_PARTICIPANT)]
public IAsyncEnumerable<ConnectorEndPointData> GetCompanyConnectorEndPointAsync([FromBody] IEnumerable<string> bpns) =>
_businessLogic.GetCompanyConnectorEndPointAsync(bpns);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Library;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models;
using Org.Eclipse.TractusX.Portal.Backend.Framework.PublicInfos;
using Org.Eclipse.TractusX.Portal.Backend.Keycloak.Authentication;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;

namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Controllers;

Expand Down Expand Up @@ -85,6 +87,7 @@ public async Task<ActionResult> GetDocumentContentFileAsync([FromRoute] Guid doc
[Authorize(Roles = "view_documents")]
[ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
[PublicUrl(CompanyRoleId.SERVICE_PROVIDER, CompanyRoleId.APP_PROVIDER)]
public async Task<ActionResult> GetSelfDescriptionDocumentsAsync([FromRoute] Guid documentId)
{
var (fileName, content, mediaType) = await _businessLogic.GetSelfDescriptionDocumentAsync(documentId).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic;
using Org.Eclipse.TractusX.Portal.Backend.Framework.PublicInfos;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;

namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Controllers;

Expand Down Expand Up @@ -53,6 +55,7 @@ public PartnerNetworkController(IPartnerNetworkBusinessLogic logic)
[Authorize(Roles = "view_membership")]
[Route("memberCompanies")]
[ProducesResponseType(StatusCodes.Status200OK)]
[PublicUrl(CompanyRoleId.ACTIVE_PARTICIPANT, CompanyRoleId.SERVICE_PROVIDER, CompanyRoleId.APP_PROVIDER)]
public IAsyncEnumerable<string?> GetAllMemberCompaniesBPNAsync() =>
_logic.GetAllMemberCompaniesBPNAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Library;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models;
using Org.Eclipse.TractusX.Portal.Backend.Framework.PublicInfos;
using Org.Eclipse.TractusX.Portal.Backend.Keycloak.Authentication;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;

namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Controllers;

Expand Down Expand Up @@ -65,6 +67,7 @@ public SubscriptionConfigurationController(ISubscriptionConfigurationBusinessLog
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status409Conflict)]
[PublicUrl(CompanyRoleId.SERVICE_PROVIDER, CompanyRoleId.APP_PROVIDER)]
public Task<ProviderDetailReturnData> GetServiceProviderCompanyDetail() =>
this.WithCompanyId(companyId => _businessLogic.GetProviderCompanyDetailsAsync(companyId));

Expand Down Expand Up @@ -107,6 +110,7 @@ public async Task<NoContentResult> SetProviderCompanyDetail([FromBody] ProviderD
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
[PublicUrl(CompanyRoleId.SERVICE_PROVIDER, CompanyRoleId.APP_PROVIDER)]
public IAsyncEnumerable<ProcessStepData> GetProcessStepsForSubscription([FromRoute] Guid offerSubscriptionId) =>
_businessLogic.GetProcessStepsForSubscription(offerSubscriptionId);

Expand Down Expand Up @@ -188,6 +192,7 @@ public async Task<NoContentResult> RetriggerCreateTechnicalUser([FromRoute] Guid
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
[PublicUrl(CompanyRoleId.SERVICE_PROVIDER, CompanyRoleId.APP_PROVIDER)]
public async Task<NoContentResult> RetriggerProviderCallback([FromRoute] Guid offerSubscriptionId)
{
await _businessLogic.RetriggerProviderCallback(offerSubscriptionId).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/********************************************************************************
* Copyright (c) 2021, 2023 BMW Group AG
* Copyright (c) 2021, 2023 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
********************************************************************************/

using Microsoft.Extensions.DependencyInjection;

namespace Org.Eclipse.TractusX.Portal.Backend.Framework.PublicInfos.DependencyInjection;

public static class PublicInfosServiceCollectionExtensions
{
public static IServiceCollection AddPublicInfos(this IServiceCollection services)
{
services
.AddTransient<IPublicInformationBusinessLogic, PublicInformationBusinessLogic>();

return services;
}
}
44 changes: 44 additions & 0 deletions src/framework/Framework.PublicInfos/Framework.PublicInfos.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!--
- Copyright (c) 2021, 2023 BMW Group AG
- Copyright (c) 2021, 2023 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
-->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Org.Eclipse.TractusX.Portal.Backend.Framework.PublicInfos</AssemblyName>
<RootNamespace>Org.Eclipse.TractusX.Portal.Backend.Framework.PublicInfos</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\keycloak\Keycloak.Authentication\Keycloak.Authentication.csproj" />
<ProjectReference Include="..\..\keycloak\Keycloak.ErrorHandling\Keycloak.ErrorHandling.csproj" />
<ProjectReference Include="..\..\keycloak\Keycloak.Factory\Keycloak.Factory.csproj" />
<ProjectReference Include="..\Framework.Cors\Framework.Cors.csproj" />
<ProjectReference Include="..\Framework.DateTimeProvider\Framework.DateTimeProvider.csproj" />
<ProjectReference Include="..\Framework.ErrorHandling.Web\Framework.ErrorHandling.Web.csproj" />
<ProjectReference Include="..\Framework.Swagger\Framework.Swagger.csproj" />
<ProjectReference Include="..\Framework.Authorization\Framework.Authorization.csproj" />
<ProjectReference Include="..\Framework.Linq\Framework.Linq.csproj" />
<ProjectReference Include="..\Framework.Logging\Framework.Logging.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="6.1.0" />
<PackageReference Include="Serilog.Enrichers.CorrelationId" Version="3.0.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/********************************************************************************
* Copyright (c) 2021, 2023 BMW Group AG
* Copyright (c) 2021, 2023 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.Framework.PublicInfos;

public interface IPublicInformationBusinessLogic
{
Task<IEnumerable<UrlInformation>> GetPublicUrls();
}
56 changes: 56 additions & 0 deletions src/framework/Framework.PublicInfos/OpenInformationController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/********************************************************************************
* Copyright (c) 2021, 2023 BMW Group AG
* Copyright (c) 2021, 2023 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
********************************************************************************/

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models;
using Org.Eclipse.TractusX.Portal.Backend.Keycloak.Authentication;

namespace Org.Eclipse.TractusX.Portal.Backend.Framework.PublicInfos;

[ApiController]
[Route("api/info")]
public class OpenInformationController : ControllerBase
{
private readonly IPublicInformationBusinessLogic _publicInformationBusinessLogic;

/// <summary>
/// Creates a new instance of <see cref="OpenInformationController"/>
/// </summary>
/// <param name="publicInformationBusinessLogic">The business logic</param>
public OpenInformationController(IPublicInformationBusinessLogic publicInformationBusinessLogic)
{
_publicInformationBusinessLogic = publicInformationBusinessLogic;
}

/// <summary>
/// Gets all open information based on the
/// </summary>
/// <remarks>
/// Example: GET: api/info
/// </remarks>
/// <response code="200">Successfully executed the invitation.</response>
[HttpGet]
[Authorize(Policy = PolicyTypes.ValidCompany)]
[ProducesResponseType(typeof(IEnumerable<UrlInformation>), StatusCodes.Status200OK)]
public Task<IEnumerable<UrlInformation>> GetOpenUrls() =>
_publicInformationBusinessLogic.GetPublicUrls();
}
Loading

0 comments on commit 39c81fc

Please sign in to comment.