Commit 663159ac authored by neelesh thakur's avatar neelesh thakur
Browse files

rebase

parent d60f14e0
Pipeline #10279 passed with stages
in 12 minutes and 25 seconds
......@@ -23,6 +23,7 @@ import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.partition.model.PartitionInfo;
import org.opengroup.osdu.partition.model.Property;
import org.opengroup.osdu.partition.provider.aws.util.SSMHelper;
import org.opengroup.osdu.partition.provider.interfaces.IPartitionService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -49,7 +50,7 @@ public class PartitionServiceImpl implements IPartitionService {
}
try {
for (Map.Entry<String, Object> entry : partitionInfo.getProperties().entrySet()) {
for (Map.Entry<String, Property> entry : partitionInfo.getProperties().entrySet()) {
ssmHelper.createOrUpdateSecret(partitionId, entry.getKey(), entry.getValue());
}
......@@ -108,7 +109,7 @@ public class PartitionServiceImpl implements IPartitionService {
@Override
public PartitionInfo getPartition(String partitionId) {
Map<String,Object> secrets = ssmHelper.getPartitionSecrets(partitionId);
Map<String,Property> secrets = ssmHelper.getPartitionSecrets(partitionId);
//throw error if partition doesn't exist
......
......@@ -36,9 +36,18 @@ import com.amazonaws.services.simplesystemsmanagement.model.PutParameterResult;
import com.amazonaws.services.simplesystemsmanagement.model.Parameter;
import org.opengroup.osdu.core.aws.iam.IAMConfig;
import org.opengroup.osdu.partition.model.Property;
import org.opengroup.osdu.partition.provider.aws.AwsServiceConfig;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public final class SSMHelper {
......@@ -78,16 +87,16 @@ public final class SSMHelper {
String nextToken = null;
do {
GetParametersByPathRequest request = new GetParametersByPathRequest()
.withPath(ssmPath)
.withRecursive(true)
.withRecursive(true)
.withNextToken(nextToken)
.withWithDecryption(true);
GetParametersByPathResult result = ssmManager.getParametersByPath(request);
nextToken = result.getNextToken();
if (result.getParameters().size() > 0)
params.addAll(result.getParameters());
}
......@@ -107,19 +116,19 @@ public final class SSMHelper {
public boolean partitionExists(String partitionName) {
String ssmPath = getSsmPathForPartitition(partitionName);
String ssmPath = getSsmPathForPartitition(partitionName);
String nextToken = null;
do {
GetParametersByPathRequest request = new GetParametersByPathRequest()
.withPath(ssmPath)
.withRecursive(true)
.withNextToken(nextToken);
.withRecursive(true)
.withNextToken(nextToken);
GetParametersByPathResult result = ssmManager.getParametersByPath(request);
nextToken = result.getNextToken();
if (result.getParameters().size() > 0)
return true;
}
......@@ -128,19 +137,19 @@ public final class SSMHelper {
return false;
}
public Map<String, Object> getPartitionSecrets(String partitionName) {
public Map<String, Property> getPartitionSecrets(String partitionName) {
List<Parameter> partitionSsmParameters = getSsmParamsForPartition(partitionName);
String ssmPath = getSsmPathForPartitition(partitionName);
Map<String,Object> kvMap = new HashMap<>();
Map<String, Property> kvMap = new HashMap<>();
for (Parameter parameter : partitionSsmParameters) {
String shortName = parameter.getName().substring(ssmPath.length());
kvMap.put(shortName, parameter.getValue());
kvMap.put(shortName, Property.builder().value(parameter.getValue()).build());
}
return kvMap;
......@@ -152,12 +161,12 @@ public final class SSMHelper {
PutParameterRequest request = new PutParameterRequest()
.withName(ssmPath)
.withType(ParameterType.SecureString)
.withType(ParameterType.SecureString)
.withValue(String.valueOf(secretValue));
PutParameterResult result = ssmManager.putParameter(request);
//secret creation throws an exception if there's an error so we wont hit here
return true;
......@@ -165,8 +174,8 @@ public final class SSMHelper {
public boolean deletePartitionSecrets(String partitionName) {
List<String> ssmParamPaths = getSsmParamsPathsForPartition(partitionName);
List<String> ssmParamPaths = getSsmParamsPathsForPartition(partitionName);
int expectedNumOfDeletedParams = ssmParamPaths.size();
int totalDeletedParams = 0;
......@@ -178,7 +187,7 @@ public final class SSMHelper {
List<String> paramsToDelete = ssmParamPaths.subList(0, subListCount);
ssmParamPaths = ssmParamPaths.subList(subListCount, ssmParamPaths.size());
DeleteParametersRequest request = new DeleteParametersRequest()
DeleteParametersRequest request = new DeleteParametersRequest()
.withNames(paramsToDelete);
DeleteParametersResult result = ssmManager.deleteParameters(request);
......@@ -186,10 +195,10 @@ public final class SSMHelper {
totalDeletedParams += result.getDeletedParameters().size();
}
return totalDeletedParams == expectedNumOfDeletedParams;
}
private String getTenantPrefix() {
......
......@@ -24,6 +24,7 @@ import org.mockito.Spy;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.partition.model.PartitionInfo;
import org.opengroup.osdu.partition.model.Property;
import org.opengroup.osdu.partition.provider.aws.util.SSMHelper;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
......@@ -48,20 +49,20 @@ public class PartitionServiceImplTest {
@Mock
private SSMHelper ssmHelper;
@InjectMocks
private PartitionServiceImpl partService;
private PartitionInfo partitionInfo = new PartitionInfo();
private Map<String,Object> partitionSecretMap = new HashMap<>();
private Map<String, Property> partitionSecretMap = new HashMap<>();
@Before
public void setup() {
partitionSecretMap.put("id", "my-tenant");
partitionSecretMap.put("storageAccount", "storage-account");
partitionSecretMap.put("complianceRuleSet", "compliance-rule-set");
partitionSecretMap.put("id", Property.builder().value("my-tenant").build());
partitionSecretMap.put("storageAccount", Property.builder().value("storage-account").build());
partitionSecretMap.put("complianceRuleSet", Property.builder().value("compliance-rule-set").build());
partitionInfo.setProperties(partitionSecretMap);
}
......@@ -73,7 +74,7 @@ public class PartitionServiceImplTest {
try {
partService.createPartition(this.partitionInfo.getProperties().get("id").toString(), this.partitionInfo);
//we should never hit this code because create partition should end in an error
assertTrue("Expected partService.createPartition to throw an exception, but passed",false);
assertTrue("Expected partService.createPartition to throw an exception, but passed", false);
} catch (AppException e) {
assertTrue(e.getError().getCode() == 409);
assertTrue(e.getError().getReason().equalsIgnoreCase("partition exist"));
......@@ -102,8 +103,8 @@ public class PartitionServiceImplTest {
String Key2 = "my-tenant-groups";
String Key3 = "my-tenant-complianceRuleSet";
HashMap<String,Object> propertiesMap = new HashMap<>();
propertiesMap.put("id", this.partitionInfo.getProperties().get("id").toString());
HashMap<String, Property> propertiesMap = new HashMap<>();
propertiesMap.put("id", Property.builder().value("my-tenant").build());
propertiesMap.put(Key1, null);
propertiesMap.put(Key2, null);
propertiesMap.put(Key3, null);
......@@ -120,11 +121,12 @@ public class PartitionServiceImplTest {
@Test
public void should_throwNotFoundException_when_partitionDoesntExist() {
when(this.ssmHelper.getPartitionSecrets("my-tenant")).thenReturn(new HashMap<>());
try {
partService.getPartition(this.partitionInfo.getProperties().get("id").toString());
partService.getPartition("my-tenant");
//we should never hit this code because get partition should end in an error
assertTrue("Expected partService.getPartition to throw an exception, but passed",false);
assertTrue("Expected partService.getPartition to throw an exception, but passed", false);
} catch (AppException e) {
assertTrue(e.getError().getCode() == 404);
assertTrue(e.getError().getReason().equalsIgnoreCase("partition not found"));
......@@ -144,12 +146,12 @@ public class PartitionServiceImplTest {
@Test
public void should_throwException_when_deletingNonExistentPartition() {
try {
this.partService.deletePartition("some-invalid-partition");
//we should never hit this code because delete partition should end in an error
assertTrue("Expected partService.deletePartition to throw an exception, but passed",false);
assertTrue("Expected partService.deletePartition to throw an exception, but passed", false);
} catch (AppException ae) {
assertTrue(ae.getError().getCode() == 404);
assertEquals("some-invalid-partition partition not found", ae.getError().getMessage());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment