Skip to content

Commit

Permalink
Merge pull request #103 from catenax-ng/support_edc_5.x
Browse files Browse the repository at this point in the history
Support edc 5.x
  • Loading branch information
adkumar1 authored Jul 7, 2023
2 parents 79d4312 + 6d6a928 commit 5f3f17d
Show file tree
Hide file tree
Showing 17 changed files with 164 additions and 133 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [Unreleased]
- NA

## [1.3.3] - 2023-07-06

### Changed
- Support EDC SSI

## [1.3.2] - 2023-06-30

### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ This service will help service provider to set up DFT/SDE with EDC and EDC as se
### Software Version

```shell
Application version: 1.3.2
Helm release version: 1.3.2
Application version: 1.3.3
Helm release version: 1.3.3
```

### Container images
Expand Down
4 changes: 2 additions & 2 deletions charts/orchestrator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ sources:
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.3.2
version: 1.3.3

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.3.2"
appVersion: "1.3.3"

dependencies:
- condition: postgresql.enabled
Expand Down
2 changes: 1 addition & 1 deletion charts/orchestrator/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# autosetup

![Version: 1.3.2](https://img.shields.io/badge/Version-1.3.2-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.3.2](https://img.shields.io/badge/AppVersion-1.3.2-informational?style=flat-square)
![Version: 1.3.3](https://img.shields.io/badge/Version-1.3.3-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.3.3](https://img.shields.io/badge/AppVersion-1.3.3-informational?style=flat-square)

This service will help service provider to set up DFT/SDE with EDC and EDC as service in service provider environment.

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>org.eclipse.tractusx</groupId>
<artifactId>auto-setup</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
<name>auto-setup</name>
<description>auto-setup</description>
<properties>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

import java.util.Map;

import org.eclipse.tractusx.autosetup.constant.DAPsConfigurationProperty;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.tractusx.autosetup.utility.PasswordGenerator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import lombok.RequiredArgsConstructor;
Expand All @@ -32,8 +33,14 @@
@RequiredArgsConstructor
public class ConnectorCommonUtilityManager {


private final DAPsConfigurationProperty dAPsConfigurationProperty;
@Value("${edc.miwUrl:default}")
private String edcMiwUrl;

@Value("${sde.keycloak-tokenUrl:default}")
private String sdeKeycloakTokenUrl;

@Value("${edc.ssi.authorityId:}")
private String authorityId;

public Map<String, String> prepareConnectorInput(String packageName, Map<String, String> inputData) {

Expand All @@ -43,10 +50,6 @@ public Map<String, String> prepareConnectorInput(String packageName, Map<String,

String controlplaneurl = dnsNameURLProtocol + "://" + dnsName;

inputData.put("dapsurl", dAPsConfigurationProperty.getUrl());
inputData.put("dapsjsksurl", dAPsConfigurationProperty.getJskUrl());
inputData.put("dapstokenurl", dAPsConfigurationProperty.getTokenUrl());

inputData.put("dataPlanePublicUrl",
dnsNameURLProtocol + "://" + packageName + "-edcdataplane-edc-dataplane:8185/api/public");

Expand All @@ -65,7 +68,15 @@ public Map<String, String> prepareConnectorInput(String packageName, Map<String,

String dftAddress = dnsNameURLProtocol + "://" + dnsName + "/backend/api";
inputData.put("dftAddress", dftAddress);


inputData.put("keycloakAuthTokenURL", sdeKeycloakTokenUrl);
inputData.put("edcMiwUrl", edcMiwUrl);

if (StringUtils.isBlank(authorityId))
inputData.put("authorityId", inputData.get("bpnNumber"));
else
inputData.put("authorityId", authorityId);

inputData.put("postgresPassword", "admin@123");
inputData.put("username", "admin");
inputData.put("appdbpass", "admin@123");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,11 @@ public void dtRegistryRegistrationInEDC(Customer customerDetails, SelectedTools
}

} catch (Exception e) {
log.error(customerDetails.getOrganizationName()
String errorMsg = customerDetails.getOrganizationName()
+ ":It looks EDC connector is not up for DT asset creation, Oops! We have an exception - "
+ e.getMessage());
throw new ServiceException(customerDetails.getOrganizationName()
+ ":It looks EDC connector is not up for DT asset creation, Oops! We have an exception - "
+ e.getMessage());
+ e.getMessage();
log.error(errorMsg);
throw new ServiceException(errorMsg);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,23 @@
import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import java.util.UUID;

import org.eclipse.tractusx.autosetup.constant.TriggerStatusEnum;
import org.eclipse.tractusx.autosetup.entity.AutoSetupTriggerDetails;
import org.eclipse.tractusx.autosetup.entity.AutoSetupTriggerEntry;
import org.eclipse.tractusx.autosetup.exception.ServiceException;
import org.eclipse.tractusx.autosetup.model.Customer;
import org.eclipse.tractusx.autosetup.model.SelectedTools;
import org.eclipse.tractusx.autosetup.portal.model.ClientInfo;
import org.eclipse.tractusx.autosetup.portal.model.ServiceInstanceResultRequest;
import org.eclipse.tractusx.autosetup.portal.model.ServiceInstanceResultResponse;
import org.eclipse.tractusx.autosetup.portal.model.TechnicalUserInfo;
import org.eclipse.tractusx.autosetup.portal.proxy.PortalIntegrationProxy;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.retry.support.RetrySynchronizationManager;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
Expand All @@ -45,6 +55,8 @@ public class PortalIntegrationManager {

private final PortalIntegrationProxy portalIntegrationProxy;

private final AutoSetupTriggerManager autoSetupTriggerManager;

@Value("${portal.url}")
private URI portalUrl;

Expand All @@ -57,40 +69,67 @@ public class PortalIntegrationManager {
@Value("${portal.keycloak.tokenURI}")
private URI tokenURI;

@SneakyThrows
public Map<String, String> postServiceInstanceResultAndGetTenantSpecs(Map<String, String> inputData) {
@Retryable(retryFor = {
ServiceException.class }, maxAttemptsExpression = "${retry.maxAttempts}", backoff = @Backoff(delayExpression = "${retry.backOffDelay}"))
public Map<String, String> postServiceInstanceResultAndGetTenantSpecs(Customer customerDetails, SelectedTools tool,
Map<String, String> inputData, AutoSetupTriggerEntry triger) {

AutoSetupTriggerDetails autoSetupTriggerDetails = AutoSetupTriggerDetails.builder()
.id(UUID.randomUUID().toString()).step("PostServiceInstanceResultAndGetTenantSpecs").build();
ServiceInstanceResultResponse serviceInstanceResultResponse = null;
try {

String dftFrontendURL = inputData.get("dftFrontEndUrl");
String subscriptionId = inputData.get("subscriptionId");
String dnsName = inputData.get("dnsName");
String dnsNameURLProtocol = inputData.get("dnsNameURLProtocol");
String subscriptionId = inputData.get("subscriptionId");

Map<String, String> output = new HashMap<>();
Map<String, String> header = new HashMap<>();
header.put("Authorization", "Bearer " + getKeycloakToken());
String applicationURL = dnsNameURLProtocol + "://" + dnsName;
inputData.put("applicationURL", applicationURL);

ServiceInstanceResultRequest serviceInstanceResultRequest = ServiceInstanceResultRequest.builder()
.requestId(subscriptionId).offerUrl(dftFrontendURL).build();
Map<String, String> header = new HashMap<>();
header.put("Authorization", "Bearer " + getKeycloakToken());

ServiceInstanceResultResponse serviceInstanceResultResponse = portalIntegrationProxy
.postServiceInstanceResultAndGetTenantSpecs(portalUrl, header, serviceInstanceResultRequest);
ServiceInstanceResultRequest serviceInstanceResultRequest = ServiceInstanceResultRequest.builder()
.requestId(subscriptionId).offerUrl(applicationURL).build();

if (serviceInstanceResultResponse != null) {
serviceInstanceResultResponse = portalIntegrationProxy.postServiceInstanceResultAndGetTenantSpecs(portalUrl,
header, serviceInstanceResultRequest);

TechnicalUserInfo technicalUserInfo = serviceInstanceResultResponse.getTechnicalUserInfo();
if (technicalUserInfo != null) {
output.put("digital-twins.authentication.clientId", technicalUserInfo.getTechnicalClientId());
output.put("digital-twins.authentication.clientSecret", technicalUserInfo.getTechnicalUserSecret());
if (serviceInstanceResultResponse != null) {

TechnicalUserInfo technicalUserInfo = serviceInstanceResultResponse.getTechnicalUserInfo();
if (technicalUserInfo != null) {
inputData.put("keycloakAuthenticationClientId", technicalUserInfo.getTechnicalClientId());
inputData.put("keycloakAuthenticationClientSecret", technicalUserInfo.getTechnicalUserSecret());
}

ClientInfo clientInfo = serviceInstanceResultResponse.getClientInfo();
if (clientInfo != null) {
inputData.put("keycloakResourceClient", clientInfo.getClientId());
}
} else {
log.error("Error in request process with portal");
}
} catch (Exception ex) {

ClientInfo clientInfo = serviceInstanceResultResponse.getClientInfo();
log.error("PortalIntegrationManager failed retry attempt: : {}",
RetrySynchronizationManager.getContext().getRetryCount() + 1);

if (clientInfo != null) {
output.put("dftbackendkeycloakclientid", clientInfo.getClientId());
output.put("dftfrontendkeycloakclientid", clientInfo.getClientId());
if (serviceInstanceResultResponse != null) {
String msg = "PortalIntegrationManager failed with details:" + serviceInstanceResultResponse.toJsonString();
log.error(msg);
autoSetupTriggerDetails.setRemark(msg);
}
} else {
log.error("Error in request process with portal");
else
autoSetupTriggerDetails.setRemark(ex.getMessage());

autoSetupTriggerDetails.setStatus(TriggerStatusEnum.FAILED.name());

throw new ServiceException("PortalIntegrationManager Oops! We have an exception - " + ex.getMessage());
} finally {
autoSetupTriggerManager.saveTriggerDetails(autoSetupTriggerDetails, triger);
}
return output;
return inputData;
}

@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,11 @@ public class SDEManager {
private final KubeAppsPackageManagement appManagement;
private final AutoSetupTriggerManager autoSetupTriggerManager;

private final PortalIntegrationManager portalIntegrationManager;

@Value("${manual.update}")
private boolean manualUpdate;

@Value("${managed.dt-registry:true}")
private boolean managedDtRegistry;

private final SDEConfigurationProperty sDEConfigurationProperty;

private Map<String, String> portalDetails = null;

@Retryable(retryFor = {
ServiceException.class }, maxAttemptsExpression = "${retry.maxAttempts}", backoff = @Backoff(delayExpression = "${retry.backOffDelay}"))
public Map<String, String> managePackage(Customer customerDetails, AppActions action, SelectedTools tool,
Expand All @@ -87,6 +80,13 @@ public Map<String, String> managePackage(Customer customerDetails, AppActions ac
inputData.put("sdeFrontEndUrl", sdefrontend);
inputData.put("database", "sde");

inputData.put("digital-twins.authentication.clientId", inputData.get("keycloakAuthenticationClientId"));
inputData.put("digital-twins.authentication.clientSecret",
inputData.get("keycloakAuthenticationClientSecret"));

inputData.put("dftbackendkeycloakclientid", inputData.get("keycloakResourceClient"));
inputData.put("dftfrontendkeycloakclientid", inputData.get("keycloakResourceClient"));

if (managedDtRegistry) {
inputData.put("sde.digital-twins.hostname", inputData.get("dtregistryUrl"));
} else {
Expand All @@ -109,14 +109,6 @@ public Map<String, String> managePackage(Customer customerDetails, AppActions ac
inputData.put("sde.discovery.authentication.url", sDEConfigurationProperty.getDiscoveryAuthenticationUrl());
inputData.put("sde.discovery.clientId", sDEConfigurationProperty.getDiscoveryClientId());
inputData.put("sde.discovery.clientSecret", sDEConfigurationProperty.getDiscoveryClientSecret());

if (!manualUpdate && portalDetails == null) {
portalDetails = portalIntegrationManager.postServiceInstanceResultAndGetTenantSpecs(inputData);
inputData.putAll(portalDetails);
log.info("Autosetup recieved new clientId/secret from portal");
} else {
log.warn("Hope already Autosetup recieved new clientId/secret from portal previous request");
}

String packageName = tool.getLabel();

Expand All @@ -133,10 +125,7 @@ public Map<String, String> managePackage(Customer customerDetails, AppActions ac
RetrySynchronizationManager.getContext().getRetryCount() + 1);

autoSetupTriggerDetails.setStatus(TriggerStatusEnum.FAILED.name());
if (portalDetails == null)
autoSetupTriggerDetails.setRemark(ex.getMessage());
else
autoSetupTriggerDetails.setRemark(ex.getMessage() + ", portal-details:" + portalDetails.toString());
autoSetupTriggerDetails.setRemark(ex.getMessage());

throw new ServiceException("SDEManager Oops! We have an exception - " + ex.getMessage());
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
@RequiredArgsConstructor
public class VaultManager {

private static final String CLIENT_SECRET = "client-secret";
private static final String V1_SECRET_DATA = "/v1/secret/data/";
public static final String ENCRYPTIONKEYS = "encryptionkeys";
public static final String CONTENT = "content";
Expand Down Expand Up @@ -93,6 +94,10 @@ public Map<String, String> uploadKeyandValues(Customer customerDetails, Selected
tenantVaultSecret = new HashMap<>();
tenantVaultSecret.put(CONTENT, inputData.get("selfsigncertificateprivatekey"));
uploadSecrete(tenantNameNamespace, CERTIFICATE_PRIVATE_KEY, tenantVaultSecret);

tenantVaultSecret = new HashMap<>();
tenantVaultSecret.put(CONTENT, inputData.get("keycloakAuthenticationClientSecret"));
uploadSecrete(tenantNameNamespace, CLIENT_SECRET, tenantVaultSecret);

String encryptionkeysalias = openSSLClientManager.executeCommand("openssl rand -base64 16");
tenantVaultSecret = new HashMap<>();
Expand All @@ -105,6 +110,7 @@ public Map<String, String> uploadKeyandValues(Customer customerDetails, Selected
inputData.put("vaulturl", valutURL);
inputData.put("vaulttoken", vaulttoken);
inputData.put("vaulttimeout", vaulttimeout);
inputData.put(CLIENT_SECRET, CLIENT_SECRET);
inputData.put(ENCRYPTIONKEYS, ENCRYPTIONKEYS);
inputData.put("certificate-data-plane-private-key", CERTIFICATE_PRIVATE_KEY);
inputData.put("certificate-data-plane-public-key", CERTIFICATE_PRIVATE_KEY);
Expand Down Expand Up @@ -156,6 +162,8 @@ public void deleteAllSecret(SelectedTools tool, Map<String, String> inputData, A
deleteSecret(tenantNameNamespace, DAPS_CERT);
deleteSecret(tenantNameNamespace, CERTIFICATE_PRIVATE_KEY);
deleteSecret(tenantNameNamespace, ENCRYPTIONKEYS);
deleteSecret(tenantNameNamespace, CLIENT_SECRET);

log.info(LogUtil.encode(orgName) + "-" + LogUtil.encode(packageName) + "-Vault deleted");

} catch (Exception ex) {
Expand Down
Loading

0 comments on commit 5f3f17d

Please sign in to comment.