From bb737a2e31644fcad9ba4b8e19a7617852a6d76b Mon Sep 17 00:00:00 2001 From: Jiangtao Li Date: Wed, 10 Mar 2021 10:00:44 -0800 Subject: [PATCH] alts: remove confusing constant name in InternalCheckGcpEnvironment.java (#7954) --- .../grpc/alts/InternalCheckGcpEnvironment.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/alts/src/main/java/io/grpc/alts/InternalCheckGcpEnvironment.java b/alts/src/main/java/io/grpc/alts/InternalCheckGcpEnvironment.java index dc6b776e11..aae4a45d53 100644 --- a/alts/src/main/java/io/grpc/alts/InternalCheckGcpEnvironment.java +++ b/alts/src/main/java/io/grpc/alts/InternalCheckGcpEnvironment.java @@ -30,25 +30,22 @@ import java.util.logging.Level; import java.util.logging.Logger; /** - * Class for checking if the system is running on Google Cloud Platform (GCP). - * This is intended for usage internal to the gRPC team. If you *really* think you need - * to use this, contact the gRPC team first. + * Class for checking if the system is running on Google Cloud Platform (GCP). This is intended for + * usage internal to the gRPC team. If you *really* think you need to use this, contact the gRPC + * team first. */ @Internal public final class InternalCheckGcpEnvironment { private static final Logger logger = Logger.getLogger(InternalCheckGcpEnvironment.class.getName()); - private static final String DMI_PRODUCT_NAME = "/sys/class/dmi/id/product_name"; private static final String WINDOWS_COMMAND = "powershell.exe"; private static Boolean cachedResult = null; // Construct me not! private InternalCheckGcpEnvironment() {} - /** - * Returns {@code true} if currently running on Google Cloud Platform (GCP). - */ + /** Returns {@code true} if currently running on Google Cloud Platform (GCP). */ public static synchronized boolean isOnGcp() { if (cachedResult == null) { cachedResult = isRunningOnGcp(); @@ -73,13 +70,14 @@ public final class InternalCheckGcpEnvironment { } return false; } - + private static boolean isRunningOnGcp() { String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); try { if (osName.startsWith("linux")) { // Checks GCE residency on Linux platform. - return checkProductNameOnLinux(Files.newBufferedReader(Paths.get(DMI_PRODUCT_NAME), UTF_8)); + return checkProductNameOnLinux( + Files.newBufferedReader(Paths.get("/sys/class/dmi/id/product_name"), UTF_8)); } else if (osName.startsWith("windows")) { // Checks GCE residency on Windows platform. Process p =