Skip to content
Snippets Groups Projects
Commit 794e0fe3 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4906 copy es crt in service call

parent 87c7c345
Branches
Tags
No related merge requests found
...@@ -36,8 +36,9 @@ public class OzgCloudElasticsearchService { ...@@ -36,8 +36,9 @@ public class OzgCloudElasticsearchService {
LOG.debug("Copy elasticseaerch ssl certificate secret: {}" , properties.getServer().getCertificateSecretName()); LOG.debug("Copy elasticseaerch ssl certificate secret: {}" , properties.getServer().getCertificateSecretName());
var secretResource = kubernetesService.getSecretResource(properties.getServer().getNamespace(), properties.getServer().getCertificateSecretName()); var secretResource = kubernetesService.getSecretResource(properties.getServer().getNamespace(), properties.getServer().getCertificateSecretName());
LOG.info("{}: Create certificate secret", namespace); LOG.info("Create certificate secret in namespace {} after copying", namespace);
createCredentialSecret(secretResource,namespace);
createAdapter(secretResource).create(secretHelper.buildCertificateSecret(namespace, getSecretData(secretResource.get())));
} catch (ElasticsearchException e) { } catch (ElasticsearchException e) {
throw new RuntimeException("can not copy/create elasticsearch ssl certificate"); throw new RuntimeException("can not copy/create elasticsearch ssl certificate");
} }
...@@ -66,11 +67,12 @@ public class OzgCloudElasticsearchService { ...@@ -66,11 +67,12 @@ public class OzgCloudElasticsearchService {
} }
private void createCredentialSecret(Resource<Secret> resource, String namespace) { private void createCredentialSecret(Resource<Secret> resource, String namespace) {
LOG.debug("getSecretCredentialsName to create: {}" , properties.getSecretCredentialsName());
createAdapter(resource).create(secretHelper.buildCredentialSecret(namespace, properties.getSecretCredentialsName())); createAdapter(resource).create(secretHelper.buildCredentialSecret(namespace, properties.getSecretCredentialsName()));
} }
public void createIndexIfMissing(String name) throws Exception { public void createIndexIfMissing(String name) throws Exception {
copyElasticCertificate(name); //copyElasticCertificate(name);
LOG.debug("{}: Check elasticsearch index...", name); LOG.debug("{}: Check elasticsearch index...", name);
if (!remoteService.existsIndex(name)) { if (!remoteService.existsIndex(name)) {
remoteService.createIndex(name); remoteService.createIndex(name);
...@@ -91,7 +93,7 @@ public class OzgCloudElasticsearchService { ...@@ -91,7 +93,7 @@ public class OzgCloudElasticsearchService {
} }
public void createSecurityUserIfMissing(String namespace, String password) throws Exception { public void createSecurityUserIfMissing(String namespace, String password) throws Exception {
copyElasticCertificate(namespace); //copyElasticCertificate(namespace);
remoteService.createOrUpdateSecurityUser(buildPutUserRequestData(namespace, password)); remoteService.createOrUpdateSecurityUser(buildPutUserRequestData(namespace, password));
} }
...@@ -100,17 +102,17 @@ public class OzgCloudElasticsearchService { ...@@ -100,17 +102,17 @@ public class OzgCloudElasticsearchService {
} }
public void deleteSecurityUserIfExists(String userName) throws Exception { public void deleteSecurityUserIfExists(String userName) throws Exception {
copyElasticCertificate(userName); //copyElasticCertificate(userName);
remoteService.deleteSecurityUser(userName); remoteService.deleteSecurityUser(userName);
} }
public void deleteSecurityRoleIfExists(String roleName) throws Exception { public void deleteSecurityRoleIfExists(String roleName) throws Exception {
copyElasticCertificate(roleName); //copyElasticCertificate(roleName);
remoteService.deleteSecurityRole(roleName); remoteService.deleteSecurityRole(roleName);
} }
public void deleteIndexIfExists(String indexName) throws Exception { public void deleteIndexIfExists(String indexName) throws Exception {
copyElasticCertificate(indexName); //copyElasticCertificate(indexName);
LOG.debug("{}: Check delete elasticsearch index ...", indexName); LOG.debug("{}: Check delete elasticsearch index ...", indexName);
if (remoteService.existsIndex(indexName)) { if (remoteService.existsIndex(indexName)) {
remoteService.deleteIndex(indexName); remoteService.deleteIndex(indexName);
......
...@@ -113,7 +113,7 @@ class OzgCloudElasticsearchServiceTest { ...@@ -113,7 +113,7 @@ class OzgCloudElasticsearchServiceTest {
} }
} }
} }
/*
@DisplayName("Create index if missing") @DisplayName("Create index if missing")
@Nested @Nested
class TestCreateIndexIfMissing { class TestCreateIndexIfMissing {
...@@ -164,6 +164,7 @@ class OzgCloudElasticsearchServiceTest { ...@@ -164,6 +164,7 @@ class OzgCloudElasticsearchServiceTest {
doReturn(putRoleRequest).when(service).buildPutRoleRequestData(any()); doReturn(putRoleRequest).when(service).buildPutRoleRequestData(any());
when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource); when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource);
when(secretResource.get()).thenReturn(SecretTestFactory.create());
when(properties.getServer()).thenReturn(serverProperties); when(properties.getServer()).thenReturn(serverProperties);
service.createSecurityRoleIfMissing(NAMESPACE); service.createSecurityRoleIfMissing(NAMESPACE);
...@@ -279,6 +280,7 @@ class OzgCloudElasticsearchServiceTest { ...@@ -279,6 +280,7 @@ class OzgCloudElasticsearchServiceTest {
} }
} }
@DisplayName("Delete security user if exists") @DisplayName("Delete security user if exists")
@Nested @Nested
class TestDeleteSecurityUserIfExists { class TestDeleteSecurityUserIfExists {
...@@ -311,6 +313,7 @@ class OzgCloudElasticsearchServiceTest { ...@@ -311,6 +313,7 @@ class OzgCloudElasticsearchServiceTest {
class TestDeleteSecurityRoleIfExists { class TestDeleteSecurityRoleIfExists {
@SneakyThrows @SneakyThrows
@Test @Test
void shouldDeleteSecurityRoleIfExists() { void shouldDeleteSecurityRoleIfExists() {
when(properties.getServer()).thenReturn(serverProperties); when(properties.getServer()).thenReturn(serverProperties);
...@@ -467,5 +470,5 @@ class OzgCloudElasticsearchServiceTest { ...@@ -467,5 +470,5 @@ class OzgCloudElasticsearchServiceTest {
verify(resourceAdapter).create(CREDENTIAL_SECRET); verify(resourceAdapter).create(CREDENTIAL_SECRET);
} }
} }
} } */
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment