You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datalab.apache.org by yk...@apache.org on 2021/07/12 05:40:20 UTC

[incubator-datalab] branch develop updated: [DATALAB] -- [BE-ConfigPage]fixed bug with repeated changed in config while writing yaml.

This is an automated email from the ASF dual-hosted git repository.

ykinash pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-datalab.git


The following commit(s) were added to refs/heads/develop by this push:
     new 5c88605  [DATALAB] -- [BE-ConfigPage]fixed bug with repeated changed in config while writing yaml.
5c88605 is described below

commit 5c886054db1af07f7ad9efc3f4d4bfb753369eca
Author: KinashYurii <ur...@gmail.com>
AuthorDate: Mon Jul 12 08:39:35 2021 +0300

    [DATALAB] -- [BE-ConfigPage]fixed bug with repeated changed in config while writing yaml.
---
 .../datalab/properties/ChangePropertiesConst.java  | 14 ++++-----
 .../properties/ChangePropertiesService.java        | 35 ++++++++++++----------
 2 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ChangePropertiesConst.java b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ChangePropertiesConst.java
index ea71207..36ec8bd 100644
--- a/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ChangePropertiesConst.java
+++ b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ChangePropertiesConst.java
@@ -23,15 +23,15 @@ public interface ChangePropertiesConst {
     String GKE_SELF_SERVICE_PATH = "/root/self-service.yaml";
     String GKE_SELF_SERVICE = "self-service.yaml";
     String SELF_SERVICE = "self-service.yml";
-    String SELF_SERVICE_PROP_PATH = "/opt/datalab/conf/self-service.yml";
-    //            String SELF_SERVICE_PROP_PATH = "services/self-service/self-service.yml";
+        String SELF_SERVICE_PROP_PATH = "/opt/datalab/conf/self-service.yml";
+//    String SELF_SERVICE_PROP_PATH = "services/self-service/self-service.yml";
     String PROVISIONING_SERVICE = "provisioning.yml";
-    String PROVISIONING_SERVICE_PROP_PATH = "/opt/datalab/conf/provisioning.yml";
-//            String PROVISIONING_SERVICE_PROP_PATH = "services/provisioning-service/provisioning.yml";
+        String PROVISIONING_SERVICE_PROP_PATH = "/opt/datalab/conf/provisioning.yml";
+//    String PROVISIONING_SERVICE_PROP_PATH = "services/provisioning-service/provisioning.yml";
 
     String BILLING_SERVICE = "billing.yml";
-    String BILLING_SERVICE_PROP_PATH = "/opt/datalab/conf/billing.yml";
-    //        String BILLING_SERVICE_PROP_PATH = "services/billing-gcp/billing.yml";
+        String BILLING_SERVICE_PROP_PATH = "/opt/datalab/conf/billing.yml";
+//    String BILLING_SERVICE_PROP_PATH = "services/billing-gcp/billing.yml";
     //      String BILLING_SERVICE_PROP_PATH = "services/billing-azure/billing.yml";
 //    String BILLING_SERVICE_PROP_PATH = "services/billing-aws/billing.yml";
     String GKE_BILLING_PATH = "/root/billing.yaml";
@@ -43,7 +43,7 @@ public interface ChangePropertiesConst {
     String SELF_SERVICE_SUPERVISORCTL_RUN_NAME = " ui ";
     String PROVISIONING_SERVICE_SUPERVISORCTL_RUN_NAME = " provserv ";
     String BILLING_SERVICE_SUPERVISORCTL_RUN_NAME = " billing ";
-    String SECRET_REGEX = "((.*)[sS]ecret(.*)|(p|P)assword): (.*)";
+    String SECRET_REGEX = "((.*)([sS]ecret(.*)|[pP]assword)): (.*)";
     String USER_REGEX = " *(user|username): (.*)";
     String SECRET_REPLACEMENT_FORMAT = " ***********";
     String SUPERVISORCTL_RESTART_SH_COMMAND = "sudo supervisorctl restart";
diff --git a/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ChangePropertiesService.java b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ChangePropertiesService.java
index 15aaa35..4e488c4 100644
--- a/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ChangePropertiesService.java
+++ b/services/datalab-webapp-common/src/main/java/com/epam/datalab/properties/ChangePropertiesService.java
@@ -28,9 +28,7 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.nio.charset.Charset;
-import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -106,23 +104,30 @@ public class ChangePropertiesService {
     private String hideSecretsAndRemoveLicence(String currentConf) {
         Matcher passMatcher = Pattern.compile(ChangePropertiesConst.SECRET_REGEX).matcher(currentConf);
         Matcher userMatcher = Pattern.compile(ChangePropertiesConst.USER_REGEX).matcher(currentConf);
-        List<String> secretsAndUsers = new ArrayList<>();
-        String confWithReplacedSecretConf = removeLicence(currentConf);
+        Map<String, String> secretsAndUsers = new HashMap<>();
+        final String[] confWithReplacedSecretConf = {removeLicence(currentConf)};
         while (passMatcher.find()) {
-            String secret = passMatcher.group().split(":")[ChangePropertiesConst.DEFAULT_VALUE_PLACE];
-            if (!(secret.isEmpty() || secret.trim().isEmpty()))
-                secretsAndUsers.add(secret);
+            String[] secret = passMatcher.group().split(":");
+            if (!(secret[ChangePropertiesConst.DEFAULT_VALUE_PLACE].isEmpty() ||
+                    secret[ChangePropertiesConst.DEFAULT_VALUE_PLACE].trim().isEmpty())) {
+
+                secretsAndUsers.put(secret[ChangePropertiesConst.DEFAULT_NAME_PLACE],
+                        secret[ChangePropertiesConst.DEFAULT_VALUE_PLACE]);
+            }
         }
         while (userMatcher.find()) {
-            String user = userMatcher.group().split(":")[ChangePropertiesConst.DEFAULT_VALUE_PLACE];
-            if (!(user.isEmpty() || user.trim().isEmpty()))
-                secretsAndUsers.add(user);
-        }
-        for (String secretOrUser : secretsAndUsers) {
-            String regex = "(" + secretOrUser + "\\b)";
-            confWithReplacedSecretConf = confWithReplacedSecretConf.replaceAll(regex, ChangePropertiesConst.SECRET_REPLACEMENT_FORMAT);
+            String[] user = userMatcher.group().split(":");
+            if (!(user[ChangePropertiesConst.DEFAULT_VALUE_PLACE].isEmpty() ||
+                    user[ChangePropertiesConst.DEFAULT_VALUE_PLACE].trim().isEmpty()))
+                secretsAndUsers.put(user[ChangePropertiesConst.DEFAULT_NAME_PLACE],
+                        user[ChangePropertiesConst.DEFAULT_VALUE_PLACE]);
         }
-        return confWithReplacedSecretConf;
+        secretsAndUsers.forEach((key, value) -> {
+            String replacement = key + ":" + value;
+            String toReplace = key + ":" + ChangePropertiesConst.SECRET_REPLACEMENT_FORMAT;
+            confWithReplacedSecretConf[0] = confWithReplacedSecretConf[0].replace(replacement, toReplace);
+        });
+        return confWithReplacedSecretConf[0];
     }
 
     private String removeLicence(String conf) {

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datalab.apache.org
For additional commands, e-mail: commits-help@datalab.apache.org