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


##########
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);
+            if (!StringUtils.isEmpty(result)){
+                return result.contains("uid=");

Review Comment:
   Hi, do you have any suggestions here? Because the user information in ldap 
will not exist in the /etc/passwd file



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to