lugela commented on code in PR #10185:
URL: https://github.com/apache/dolphinscheduler/pull/10185#discussion_r879312566
##########
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.
At present, it is verified that the id ${tennantCode} has permission to
execute under any user, and does not need sudo
--
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]