Skip to content

Commit

Permalink
Merge pull request #131 from catenax-ng/R1.5.5
Browse files Browse the repository at this point in the history
feat: Handle mini user duplication
  • Loading branch information
adkumar1 authored Nov 2, 2023
2 parents bc9a95b + b016e39 commit 2861d5e
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 26 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- The customer already gets an email from Portal and the third-Party-provider after the successful deployment that the SDE-Service is ready to use. If the connector End2End test is unsuccessful (this might be based on the cloud communication issue), the customer will be informed about the failing connectivity. This behavior might need to be clarified for the customer. We will change this behavior in the next release.


## [1.5.3] - 2023-10-30
## [1.5.5] - 2023-11-02

### Changed
- Refactor DT registry local use

- Handle Minio user duplication

## [1.5.4] - 2023-11-01

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.5.3
Helm release version: 1.5.3
Application version: 1.5.5
Helm release version: 1.5.5
```

# 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.5.4
version: 1.5.5

# 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.5.4"
appVersion: "1.5.5"

dependencies:
- condition: postgresql.enabled
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</parent>
<groupId>org.eclipse.tractusx</groupId>
<artifactId>managed-service-orchestrator</artifactId>
<version>1.5.3</version>
<version>1.5.5</version>
<name>managed-service-orchestrator</name>
<description>managed-service-orchestrator</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.springframework.retry.support.RetrySynchronizationManager;
import org.springframework.stereotype.Service;

import io.minio.admin.UserInfo;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -65,29 +66,19 @@ public Map<String, String> createStorageMedia(Customer customerDetails, Selected
.id(UUID.randomUUID().toString()).step("STORAGE_MEDIA").build();
try {
String tenantNameNamespace = triger.getAutosetupTenantName();
String generateRandomPassword = PasswordGenerator.generateRandomPassword(50);
minioHandler.makeBucket(tenantNameNamespace);

// deleting policy before creation if exist
deletePolicy(tenantNameNamespace);
minioHandler.addCannedPolicy(tenantNameNamespace, valueReplacerUtility
.valueReplacer("/request-template/s3-policy-template.json", Map.of("bucket", tenantNameNamespace)));

log.info(tenantNameNamespace + " bucket policy created successfully");
checkAndCreatePolicy(tenantNameNamespace);

// deleting user before creation if exist
String email = customerDetails.getEmail();
deleteUser(email);
minioHandler.addUser(email, generateRandomPassword, tenantNameNamespace);
minioHandler.assignPolicyToUser(email, tenantNameNamespace);
log.info(email + " user created successfully and assigned require policy as well");
String accessKey= checkAndCreateUserGetSecret(inputData, tenantNameNamespace, customerDetails);

minioHandler.assignPolicyToUser(accessKey, tenantNameNamespace);
log.info(accessKey + " assigned '"+tenantNameNamespace+"' policy");

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

inputData.put("storage.media.bucket", tenantNameNamespace);
inputData.put("storage.media.endpoint", endpoint);
inputData.put("storage.media.accessKey", email);
inputData.put("storage.media.secretKey", generateRandomPassword);


} catch (Exception ex) {

Expand All @@ -104,6 +95,48 @@ public Map<String, String> createStorageMedia(Customer customerDetails, Selected
return inputData;
}

@SneakyThrows
private String checkAndCreateUserGetSecret(Map<String, String> inputData, String tenantNameNamespace,
Customer customerDetails) {
UserInfo userInfo = null;
String email= customerDetails.getEmail();

try {
userInfo = minioHandler.getUserInfo(email);
} catch (Exception e) {
log.info("Exception to get minio user " + e.getMessage());
}

if (userInfo == null) {
String generateRandomPassword = PasswordGenerator.generateRandomPassword(50);
minioHandler.addUser(email, generateRandomPassword, tenantNameNamespace);
log.info(email + " user does not exist so created user");
inputData.put("storage.media.accessKey", email);
inputData.put("storage.media.secretKey", generateRandomPassword);
return email;
} else {
String generateAccessKey = PasswordGenerator.generateRandomPassword(20);
String generateRandomPassword = PasswordGenerator.generateRandomPassword(50);
inputData.put("storage.media.accessKey", generateAccessKey);
inputData.put("storage.media.secretKey", generateRandomPassword);
minioHandler.addUser(generateAccessKey, generateRandomPassword, tenantNameNamespace);
log.info(email + " user already exist with email so creating new access key");
return generateAccessKey;
}

}

@SneakyThrows
private void checkAndCreatePolicy(String tenantNameNamespace) {
// deleting policy before creation if exist
deletePolicy(tenantNameNamespace);

minioHandler.addCannedPolicy(tenantNameNamespace, valueReplacerUtility
.valueReplacer("/request-template/s3-policy-template.json", Map.of("bucket", tenantNameNamespace)));
log.info(tenantNameNamespace + " bucket policy created successfully");
}


public void deleteStorageMedia(String tenantName, String userEmail) {
deleteBucket(tenantName);
deleteUser(userEmail);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public void assignPolicyToUser(String userAccessKey, String policyName) {
}

@SneakyThrows
public void getUserInfo(String userAccessKey) {
minioAdminClient.getUserInfo(userAccessKey);
public UserInfo getUserInfo(String userAccessKey) {
return minioAdminClient.getUserInfo(userAccessKey);
}

@SneakyThrows
Expand Down

0 comments on commit 2861d5e

Please sign in to comment.