Pull request #535: RED-3925: Implemented logic to get deploymentKey
Merge in RED/persistence-service from RED-3925 to master * commit '6b639b00782cbbc8f6e42634310e440664fc1014': RED-3925: Implemented logic to get deploymentKey
This commit is contained in:
commit
8dbee13dfd
@ -5,15 +5,20 @@ import java.util.List;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.common.JSONPrimitive;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.multitenancy.Tenant;
|
||||
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
public interface TenantsResource {
|
||||
|
||||
String TENANT_ID_PARAM = "tenantId";
|
||||
String TENANT_ID_PATH_PARAM = "/{" + TENANT_ID_PARAM + "}";
|
||||
|
||||
@PostMapping(value = "/tenants", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
void createTenant(@RequestBody Tenant tenant);
|
||||
|
||||
@ -21,4 +26,6 @@ public interface TenantsResource {
|
||||
@GetMapping(value = "/tenants", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
List<Tenant> getTenants();
|
||||
|
||||
@GetMapping(value = "/deploymentKey" + TENANT_ID_PATH_PARAM, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
JSONPrimitive<String> getDeploymentKey(@PathVariable(TENANT_ID_PARAM) String tenantId);
|
||||
}
|
||||
|
||||
@ -2,10 +2,13 @@ package com.iqser.red.service.peristence.v1.server.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.iqser.red.service.peristence.v1.server.service.DeploymentKeyService;
|
||||
import com.iqser.red.service.peristence.v1.server.service.TenantManagementService;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.common.JSONPrimitive;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.multitenancy.Tenant;
|
||||
import com.iqser.red.service.persistence.service.v1.api.resources.TenantsResource;
|
||||
|
||||
@ -16,6 +19,9 @@ import lombok.RequiredArgsConstructor;
|
||||
public class TenantsController implements TenantsResource {
|
||||
|
||||
private final TenantManagementService tenantManagementService;
|
||||
private final DeploymentKeyService deploymentKeyService;
|
||||
|
||||
|
||||
|
||||
|
||||
public void createTenant(@RequestBody Tenant tenant) {
|
||||
@ -29,4 +35,10 @@ public class TenantsController implements TenantsResource {
|
||||
return tenantManagementService.getTenants();
|
||||
}
|
||||
|
||||
|
||||
public JSONPrimitive<String> getDeploymentKey(@PathVariable(TENANT_ID_PARAM) String tenantId){
|
||||
|
||||
return JSONPrimitive.of(deploymentKeyService.getDeploymentKey(tenantId));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package com.iqser.red.service.peristence.v1.server.service;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.google.common.hash.HashFunction;
|
||||
import com.google.common.hash.Hashing;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeploymentKeyService {
|
||||
|
||||
private final TenantManagementService tenantManagementService;
|
||||
|
||||
private final HashFunction hashFunction = Hashing.farmHashFingerprint64();
|
||||
|
||||
@Value("${redaction.kubernetes.id:someValue}")
|
||||
private String redactionKubernetesId;
|
||||
|
||||
private String hardcodedKey = "89274365-160c-49f2-ab8b-ad83fc43c2e1";
|
||||
|
||||
|
||||
public String getDeploymentKey(String tenantId) {
|
||||
|
||||
var tenant = tenantManagementService.getTenant(tenantId);
|
||||
|
||||
var stringBuilder = new StringBuilder();
|
||||
stringBuilder.append(tenant.getGuid()).append(redactionKubernetesId).append(hardcodedKey);
|
||||
|
||||
var deploymentKey = hashFunction.hashString(stringBuilder.toString(), StandardCharsets.UTF_8);
|
||||
|
||||
return deploymentKey.toString().toUpperCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
}
|
||||
@ -15,6 +15,7 @@ import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.multitenancy.entity.TenantEntity;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.EncryptionDecryptionService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.mulitenancy.repository.TenantRepository;
|
||||
@ -78,6 +79,12 @@ public class TenantManagementService {
|
||||
}
|
||||
|
||||
|
||||
public Tenant getTenant(String tenantId) {
|
||||
|
||||
return tenantRepository.findById(tenantId).map(this::convert).orElseThrow(() -> new NotFoundException("Tenant does not exist"));
|
||||
}
|
||||
|
||||
|
||||
private Tenant convert(TenantEntity entity) {
|
||||
|
||||
return Tenant.builder()
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
package com.iqser.red.service.peristence.v1.server.integration.tests;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.iqser.red.service.peristence.v1.server.integration.client.TenantsClient;
|
||||
import com.iqser.red.service.peristence.v1.server.integration.utils.AbstractPersistenceServerServiceTest;
|
||||
|
||||
public class DeploymentKeyTest extends AbstractPersistenceServerServiceTest {
|
||||
|
||||
@Autowired
|
||||
private TenantsClient tenantsClient;
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetDeploymentKey() {
|
||||
|
||||
String deploymentKey = tenantsClient.getDeploymentKey("redaction").getValue();
|
||||
assertThat(deploymentKey.length()).isEqualTo(16);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user