vyommani commented on code in PR #911:
URL: https://github.com/apache/ranger/pull/911#discussion_r3061893827
##########
agents-common/src/main/java/org/apache/ranger/plugin/util/RangerRESTUtils.java:
##########
@@ -143,12 +142,32 @@ public String getAppIdFromPluginId(String pluginId) {
return ret;
}
- static {
+ private static String getHostname() {
+ String hostname = null;
+
try {
- hostname = Hostname.getHostname();
- } catch (Exception e) {
- LOG.error("ERROR: Unable to find hostname for the agent ", e);
- hostname = "unknownHost";
+ hostname = System.getenv("HOSTNAME");
+ } catch (SecurityException excp) {
+ LOG.error("Error in getting environment HOSTNAME", excp);
}
+
+ if (StringUtils.isBlank(hostname)) {
+ try {
+ hostname = System.getenv("COMPUTERNAME");
+ } catch (SecurityException excp) {
+ LOG.error("Error in getting environment COMPUTERNAME", excp);
+ }
+
+ if (StringUtils.isBlank(hostname)) {
+ try {
+ hostname = InetAddress.getLocalHost().getHostName();
+ } catch (Exception e) {
+ LOG.error("ERROR: Unable to find hostname for the agent ",
e);
+ hostname = "unknownHost";
Review Comment:
Please move the "unknownHost" fallback outside the try-catch and add this
check at the end:
// Final safety net
if (StringUtils.isBlank(hostname)) {
hostname = "unknownHost";
}
Even though InetAddress.getLocalHost().getHostName() never returns null, it
can return an empty string in some edge cases (Docker, restrictive
SecurityManager, network issues, etc.). This ensures we never return a blank
hostname.
--
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]