From 84b4c586a462127206aadb43bf57338166f75817 Mon Sep 17 00:00:00 2001 From: Keith Lustria Date: Fri, 5 Jan 2024 14:41:01 -0800 Subject: [PATCH] Derive value of opc path for the IMDS url --- .../oci/sdk/runtime/OciAvailabilityDefault.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/integrations/oci/sdk/runtime/src/main/java/io/helidon/integrations/oci/sdk/runtime/OciAvailabilityDefault.java b/integrations/oci/sdk/runtime/src/main/java/io/helidon/integrations/oci/sdk/runtime/OciAvailabilityDefault.java index 7e17d244e91..ef5ca7493c3 100644 --- a/integrations/oci/sdk/runtime/src/main/java/io/helidon/integrations/oci/sdk/runtime/OciAvailabilityDefault.java +++ b/integrations/oci/sdk/runtime/src/main/java/io/helidon/integrations/oci/sdk/runtime/OciAvailabilityDefault.java @@ -28,6 +28,8 @@ import com.oracle.bmc.Region; import jakarta.inject.Singleton; +import static com.oracle.bmc.auth.AbstractFederationClientAuthenticationDetailsProviderBuilder.METADATA_SERVICE_BASE_URL; + /** * This (overridable) implementation will check the {@link OciConfig} for {@code IMDS} availability. And if it is found to be * available, will also perform a secondary check on {@link Region#getRegionFromImds()} to ensure it returns a non-null value. @@ -35,6 +37,7 @@ @Singleton @Weight(ServiceInfoBasics.DEFAULT_INJECT_WEIGHT) class OciAvailabilityDefault implements OciAvailability { + static String OPC_PATH = getOpcPath(); @Override public boolean isRunningOnOci(OciConfig ociConfig) { @@ -46,7 +49,7 @@ static boolean runningOnOci(OciConfig ociConfig) { return false; } - return (Region.getRegionFromImds("http://" + ociConfig.imdsHostName() + "/opc/v2/") != null); + return (Region.getRegionFromImds("http://" + ociConfig.imdsHostName() + OPC_PATH) != null); } static boolean canReach(String address, @@ -71,4 +74,15 @@ static boolean canReach(String address, } } + static String getOpcPath() { + String input = METADATA_SERVICE_BASE_URL; + int index = -1; + for (int nth = 3; nth > 0; nth--) { + index = input.indexOf("/", index + 1); + if (index == -1) { + return null; + } + } + return METADATA_SERVICE_BASE_URL.substring(index); + } }