You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/05/23 10:34:35 UTC

[GitHub] [dolphinscheduler] SbloodyS commented on a diff in pull request #10185: [Fix-10181] Fix the logic of judging that the tenant does not exist

SbloodyS commented on code in PR #10185:
URL: https://github.com/apache/dolphinscheduler/pull/10185#discussion_r879298460


##########
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java:
##########
@@ -156,65 +148,75 @@ public static double cpuUsage() {
         return Double.parseDouble(df.format(cpuUsage));
     }
 
-    public static List<String> getUserList() {
+    /**
+     * Determine if the tenantCode exists in the system
+     * @return boolean
+     **/
+    public static boolean isExistTenantCode(String tenantCode){
+
         try {
             if (SystemUtils.IS_OS_MAC) {
-                return getUserListFromMac();
+                return existTenantCodeInMac(tenantCode);
             } else if (SystemUtils.IS_OS_WINDOWS) {
-                return getUserListFromWindows();
+                return existTenantCodeInWindows(tenantCode);
             } else {
-                return getUserListFromLinux();
+                return existTenantCodeInLinux(tenantCode);
             }
         } catch (Exception e) {
             logger.error(e.getMessage(), e);
         }
 
-        return Collections.emptyList();
+        return false;
+
     }
 
     /**
-     * get user list from linux
+     * whether the user exists in linux
      *
-     * @return user list
+     * @return boolean
      */
-    private static List<String> getUserListFromLinux() throws IOException {
-        List<String> userList = new ArrayList<>();
-
-        try (BufferedReader bufferedReader = new BufferedReader(
-                new InputStreamReader(new FileInputStream("/etc/passwd")))) {
-            String line;
-
-            while ((line = bufferedReader.readLine()) != null) {
-                if (line.contains(":")) {
-                    String[] userInfo = line.split(":");
-                    userList.add(userInfo[0]);
-                }
+    private static boolean existTenantCodeInLinux(String tenantCode) throws IOException {
+        try{
+            String result = exeCmd("id "+ tenantCode);

Review Comment:
   This command ```id ${tennantCode}``` may not be compatiable with users environment. It may throw ```permission denied``` exception when the user ```dolphinscheduler``` did not have execute permissions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org