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

OZG-6177 set ETR_NAMESPACE from env

parent 17292fdb
No related branches found
No related tags found
No related merge requests found
......@@ -22,18 +22,12 @@
* unter der Lizenz sind dem Lizenztext zu entnehmen.
*/
package de.ozgcloud.operator.elstertransfer.user;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Constants {
public static final String CONFIG_MAP_NAME = "etr-user-config";
public static final String USERS_KEY = "users.yaml";
public static final String ELSTER_TRANSFER_USER_LOGIN_KEY = "login";
public static final String ELSTER_TRANSFER_USER_PASSWORD_KEY = "password";
@Value("${etr.namespace}")
public static String ETR_NAMESPACE;
public static final String USER_ROLE = "USER";
public static final String ETR_DEPLOYMENT_NAME = "elster-transfer";
public static final String MUK_USER_SECRET_NAME = "muk-user-secret";
......
......@@ -30,6 +30,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.Yaml;
......@@ -49,12 +50,15 @@ public class OzgCloudElsterTransferUserService {
private final OzgCloudElsterTransferUserRemoteService remoteService;
@Value("${etr.namespace}")
private String etrNamespace;
public void updateConfigMapAndRestartDeploymentAndCreateSecret(String namespace) {
LOG.info("Updating/Creating Configmap");
if (!userExists(namespace, Constants.ETR_NAMESPACE, Constants.CONFIG_MAP_NAME)) {
String userPassword = updateConfigMapAndGenerateUserPassword(namespace, Constants.ETR_NAMESPACE, Constants.CONFIG_MAP_NAME);
if (!userExists(namespace, etrNamespace, Constants.CONFIG_MAP_NAME)) {
String userPassword = updateConfigMapAndGenerateUserPassword(namespace, etrNamespace, Constants.CONFIG_MAP_NAME);
LOG.info("Restarting Deployment");
restartDeployment(Constants.ETR_NAMESPACE, Constants.ETR_DEPLOYMENT_NAME);
restartDeployment(etrNamespace, Constants.ETR_DEPLOYMENT_NAME);
LOG.info("Creating Secret");
createOrUpdateSecret(namespace, userPassword, Constants.MUK_USER_SECRET_NAME);
......@@ -63,13 +67,13 @@ public class OzgCloudElsterTransferUserService {
public void delete(OzgCloudElsterTransferUser user) {
String namespace = user.getMetadata().getNamespace();
if (!userExists(namespace, Constants.ETR_NAMESPACE, Constants.ELSTER_TRANSFER_USER_LOGIN_KEY)) {
if (!userExists(namespace, etrNamespace, Constants.ELSTER_TRANSFER_USER_LOGIN_KEY)) {
LOG.info("User not exists");
return;
}
LOG.info("{} do cleanup...", user.getMetadata());
deleteUser(user.getMetadata().getNamespace(), Constants.ELSTER_TRANSFER_USER_LOGIN_KEY);
restartDeployment(Constants.ETR_NAMESPACE, Constants.ETR_DEPLOYMENT_NAME);
restartDeployment(etrNamespace, Constants.ETR_DEPLOYMENT_NAME);
}
String updateConfigMapAndGenerateUserPassword(String namespace, String configmapNamespace, String configMapName) {
......@@ -120,7 +124,7 @@ public class OzgCloudElsterTransferUserService {
}
void deleteUser(String userLogin, String configMapName) {
ConfigMap configMap = getConfigMap(Constants.ETR_NAMESPACE, configMapName);
ConfigMap configMap = getConfigMap(etrNamespace, configMapName);
OzgCloudElsterTransferConfigMapUserList usersList = getUsersFromConfigMap(configMap);
usersList.removeDeleted(userLogin);
......
......@@ -21,8 +21,5 @@ management:
web:
exposure:
include: "*"
etr:
namespace: elster-transfer
\ No newline at end of file
namespace: "elster-transfer"
\ No newline at end of file
......@@ -94,7 +94,7 @@ class OzgCloudElsterTransferUserRemoteServiceTest {
private static final String configMapName = Constants.CONFIG_MAP_NAME;
private static final String deploymentName = Constants.ETR_DEPLOYMENT_NAME;
private static final String secretName = Constants.MUK_USER_SECRET_NAME;
private static final String configmapNamespace = Constants.ETR_NAMESPACE;
private static final String configmapNamespace = "elster-transfer";
@DisplayName("test ConfigMap")
@Nested
......
......@@ -62,7 +62,7 @@ class OzgCloudElsterTransferUserServiceTest {
private static final String configMapName = Constants.CONFIG_MAP_NAME;
private static final String deploymentName = Constants.ETR_DEPLOYMENT_NAME;
private static final String secretName = Constants.MUK_USER_SECRET_NAME;
private static final String configMapNamespace = Constants.ETR_NAMESPACE;
private static final String configMapNamespace = "elster-transfer";
private static final String usersKey = Constants.USERS_KEY;
/*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment