ranger icon indicating copy to clipboard operation
ranger copied to clipboard

RANGER-4125: Simplifies the dependency of `gethostname4j` for the ranger client

Open yikf opened this issue 2 years ago • 2 comments

Currently, ranger-plugin-commons module relies on gethostname4j, jna and jna-platform to get the native hostname, which is for AuthzAuditEvent only.

gethostname4j, jna and jna-platform is too onerous, it doesn't seem worthwhile to maintain the three jars to get the hostname, and gethostname4j, jna and jna-platform relies on the native lib, which prevents users from doing shade.

yikf avatar Mar 07 '23 12:03 yikf

Could you please take a look if you find a moments, thanks @kumaab

yikf avatar Mar 07 '23 12:03 yikf

@mneethiraj @kumaab could you guys give some background on why should use gethostname4j?

Based on https://stackoverflow.com/questions/7348711/recommended-way-to-get-hostname-in-java

I suppose it could be replaced with org.apache.commons.lang3.SystemUtils#getHostName

   /**
     * Gets the host name from an environment variable
     * (COMPUTERNAME on Windows, HOSTNAME elsewhere).
     *
     * <p>
     * If you want to know what the network stack says is the host name, you should use {@code InetAddress.getLocalHost().getHostName()}.
     * </p>
     *
     * @return the host name. Will be {@code null} if the environment variable is not defined.
     * @since 3.6
     */
    public static String getHostName() {
        return IS_OS_WINDOWS ? System.getenv("COMPUTERNAME") : System.getenv("HOSTNAME");
    }

pan3793 avatar Jul 12 '23 08:07 pan3793