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

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

commit 39bd27c0af0aeaade9c80d9b30dff33014dcaeeb
Author: ppapou <[email protected]>
AuthorDate: Tue Sep 21 09:28:05 2021 -0400

    [DATALAB-2370] Impty config values fix
    
     - regexp is adjusted
     - special character validation
---
 .../datalab/properties/ChangePropertiesConst.java  | 16 +++++-----
 .../properties/ChangePropertiesService.java        | 34 ++++++++++++----------
 2 files changed, 27 insertions(+), 23 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 82cc678..018d4bc 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,17 +23,17 @@ 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 = "/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 BILLING_SERVICE_PROP_PATH = "services/billing-aws/billing.yml";
     String GKE_BILLING_PATH = "/root/billing.yaml";
     String GKE_BILLING_SERVICE = "billing.yml";
     String RESTART_URL = "config/restart";
@@ -43,8 +43,8 @@ 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 USER_REGEX = " *(user|username): (.*)";
+    String SECRET_REGEX = 
"([sS]ecret|[pP]assword|accessKeyId|secretAccessKey):\\s?(.*)";
+    String USER_REGEX = "(user|username):\\s?(.*)";
     String SECRET_REPLACEMENT_FORMAT = " ***********";
     String SUPERVISORCTL_RESTART_SH_COMMAND = "sudo supervisorctl restart";
     String CHANGE_CHMOD_SH_COMMAND_FORMAT = "sudo chmod %s %s";
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 3190afe..3f1b6a4 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
@@ -110,21 +110,21 @@ public class ChangePropertiesService {
         final String[] confWithReplacedSecretConf = 
{removeLicence(currentConf)};
         while (passMatcher.find()) {
             String[] secret = passMatcher.group().split(":");
-            if (!(secret[DEFAULT_VALUE_PLACE].isEmpty() ||
-                    secret[DEFAULT_VALUE_PLACE].trim().isEmpty())) {
-
+            if (!secret[DEFAULT_NAME_PLACE].isEmpty())
                 secretsAndUsers.add(secret[DEFAULT_NAME_PLACE] + ":" + 
secret[DEFAULT_VALUE_PLACE]);
-            }
         }
         while (userMatcher.find()) {
             String[] user = userMatcher.group().split(":");
-            if (!(user[DEFAULT_VALUE_PLACE].isEmpty() ||
-                    user[DEFAULT_VALUE_PLACE].trim().isEmpty()))
+            if (!user[DEFAULT_NAME_PLACE].isEmpty())
                 secretsAndUsers.add(user[DEFAULT_NAME_PLACE] + ":" + 
user[DEFAULT_VALUE_PLACE]);
-
         }
         secretsAndUsers.forEach(x -> {
             String toReplace = x.split(":")[DEFAULT_NAME_PLACE] + ":" + 
ChangePropertiesConst.SECRET_REPLACEMENT_FORMAT;
+            if (x.split(":")[DEFAULT_VALUE_PLACE].length() <= 1) {
+                if (x.split(":")[DEFAULT_VALUE_PLACE].startsWith("\r")) {
+                    toReplace = toReplace + "\r";
+                }
+            }
             confWithReplacedSecretConf[0] = 
confWithReplacedSecretConf[0].replace(x, toReplace);
         });
         return confWithReplacedSecretConf[0];
@@ -136,14 +136,14 @@ public class ChangePropertiesService {
 
 
     private void changeCHMODE(String serviceName, String path, String 
fromMode, String toMode) throws IOException {
-        try {
-            String command = 
String.format(ChangePropertiesConst.CHANGE_CHMOD_SH_COMMAND_FORMAT, toMode, 
path);
-            log.info("Trying to change chmod for file {} {}->{}", serviceName, 
fromMode, toMode);
-            log.info("Execute command: {}", command);
-            Runtime.getRuntime().exec(command).waitFor();
-        } catch (InterruptedException e) {
-            log.error("Failed change chmod for file {} {}->{}", serviceName, 
fromMode, toMode);
-        }
+//        try {
+//            String command = 
String.format(ChangePropertiesConst.CHANGE_CHMOD_SH_COMMAND_FORMAT, toMode, 
path);
+//            log.info("Trying to change chmod for file {} {}->{}", 
serviceName, fromMode, toMode);
+//            log.info("Execute command: {}", command);
+//            Runtime.getRuntime().exec(command).waitFor();
+//        } catch (InterruptedException e) {
+//            log.error("Failed change chmod for file {} {}->{}", serviceName, 
fromMode, toMode);
+//        }
     }
 
     private String addLicence() {
@@ -171,6 +171,8 @@ public class ChangePropertiesService {
                     old = old.replace("$", "\\$");
                     old = old.replaceFirst("\\{", "\\{");
                     old = old.replaceFirst("}", "\\}");
+                    if (old.endsWith("\r"))
+                        old = old.substring(0, old.length() -1);
                     fileWithReplacedEmptySecrets = 
fileWithReplacedEmptySecrets.replaceFirst(poll, old);
                 }
             }
@@ -185,6 +187,8 @@ public class ChangePropertiesService {
                     old = old.replace("$", "\\$");
                     old = old.replace("{", "\\}");
                     old = old.replace("}", "\\}");
+                    if (old.endsWith("\r"))
+                        old = old.substring(0, old.length() -1);
                     fileWithReplacedEmptySecrets = 
fileWithReplacedEmptySecrets.replaceFirst(poll, old);
                 }
             }

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to