From c60a59a398405a83df3b9012a071ad2ea6bf37e6 Mon Sep 17 00:00:00 2001 From: "lucas.martins.scclouds" Date: Tue, 26 Dec 2023 17:10:21 -0300 Subject: [PATCH 01/10] Fix validate endpoint url message --- .../config/ApiServiceConfiguration.java | 14 ++++++++++++++ .../cluster/KubernetesClusterManagerImpl.java | 15 +++------------ .../cloud/network/as/AutoScaleManagerImpl.java | 5 +---- .../network/lb/LoadBalancingRulesManagerImpl.java | 8 +++----- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java b/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java index a4aa860487f3..e258c4151868 100644 --- a/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java +++ b/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java @@ -18,6 +18,7 @@ import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; +import com.cloud.exception.InvalidParameterValueException; public class ApiServiceConfiguration implements Configurable { public static final ConfigKey ManagementServerAddresses = new ConfigKey<>(String.class, "host", "Advanced", "localhost", "The ip address of management server. This can also accept comma separated addresses.", true, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null); @@ -29,6 +30,19 @@ public class ApiServiceConfiguration implements Configurable { "true", "Are the source checks on API calls enabled (true) or not (false)? See api.allowed.source.cidr.list", true, ConfigKey.Scope.Global); public static final ConfigKey ApiAllowedSourceCidrList = new ConfigKey<>(String.class, "api.allowed.source.cidr.list", "Advanced", "0.0.0.0/0,::/0", "Comma separated list of IPv4/IPv6 CIDRs from which API calls can be performed. Can be set on Global and Account levels.", true, ConfigKey.Scope.Account, null, null, null, null, null, ConfigKey.Kind.CSV, null); + + + public static void validateEndpointUrl() { + String csUrl = getApiServletPathValue(); + if (csUrl == null || csUrl.contains("localhost")) { + throw new InvalidParameterValueException(String.format("Global setting %s cannot be null or localhost", ApiServletPath.key())); + } + } + + public static String getApiServletPathValue() { + return ApiServletPath.value(); + } + @Override public String getConfigComponentName() { return ApiServiceConfiguration.class.getSimpleName(); diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java index a12648c8e840..4f16c4809396 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java @@ -885,15 +885,6 @@ public KubernetesClusterResponse createKubernetesClusterResponse(long kubernetes return response; } - private void validateEndpointUrl() { - String csUrl = ApiServiceConfiguration.ApiServletPath.value(); - if (csUrl == null || csUrl.contains("localhost")) { - String error = String.format("Global setting %s has to be set to the Management Server's API end point", - ApiServiceConfiguration.ApiServletPath.key()); - throw new InvalidParameterValueException(error); - } - } - private DataCenter validateAndGetZoneForKubernetesCreateParameters(Long zoneId, Long networkId) { DataCenter zone = dataCenterDao.findById(zoneId); if (zone == null) { @@ -988,7 +979,7 @@ public boolean isCommandSupported(KubernetesCluster cluster, String cmdName) { } private void validateManagedKubernetesClusterCreateParameters(final CreateKubernetesClusterCmd cmd) throws CloudRuntimeException { - validateEndpointUrl(); + ApiServiceConfiguration.validateEndpointUrl(); final String name = cmd.getName(); final Long zoneId = cmd.getZoneId(); final Long kubernetesVersionId = cmd.getKubernetesVersionId(); @@ -1288,7 +1279,7 @@ private void validateKubernetesClusterScaleParameters(ScaleKubernetesClusterCmd KubernetesVersionManagerImpl.MINIMUN_AUTOSCALER_SUPPORTED_VERSION )); } - validateEndpointUrl(); + ApiServiceConfiguration.validateEndpointUrl(); if (minSize == null || maxSize == null) { throw new InvalidParameterValueException("Autoscaling requires minsize and maxsize to be passed"); @@ -1393,7 +1384,7 @@ protected boolean isAnyNodeOfferingEmpty(Map map) { private void validateKubernetesClusterUpgradeParameters(UpgradeKubernetesClusterCmd cmd) { // Validate parameters - validateEndpointUrl(); + ApiServiceConfiguration.validateEndpointUrl(); final Long kubernetesClusterId = cmd.getId(); final Long upgradeVersionId = cmd.getKubernetesVersionId(); diff --git a/server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java b/server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java index 83493ad702b7..959d5b7f96c6 100644 --- a/server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java +++ b/server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java @@ -512,7 +512,6 @@ public void checkAutoScaleUser(Long autoscaleUserId, long accountId) { String apiKey = user.getApiKey(); String secretKey = user.getSecretKey(); - String csUrl = ApiServiceConfiguration.ApiServletPath.value(); if (apiKey == null) { throw new InvalidParameterValueException("apiKey for user: " + user.getUsername() + " is empty. Please generate it"); @@ -522,9 +521,7 @@ public void checkAutoScaleUser(Long autoscaleUserId, long accountId) { throw new InvalidParameterValueException("secretKey for user: " + user.getUsername() + " is empty. Please generate it"); } - if (csUrl == null || csUrl.contains("localhost")) { - throw new InvalidParameterValueException(String.format("Global setting %s has to be set to the Management Server's API end point", ApiServiceConfiguration.ApiServletPath.key())); - } + ApiServiceConfiguration.validateEndpointUrl(); } @Override @ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMPROFILE_CREATE, eventDescription = "creating autoscale vm profile", create = true) diff --git a/server/src/main/java/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/main/java/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java index 5ceebf06dd88..942f11cd0acf 100644 --- a/server/src/main/java/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java +++ b/server/src/main/java/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java @@ -337,7 +337,6 @@ private LbAutoScaleVmGroup getLbAutoScaleVmGroup(AutoScaleVmGroupVO vmGroup, Aut String apiKey = null; String secretKey = null; - String csUrl = ApiServiceConfiguration.ApiServletPath.value(); Network.Provider provider = getLoadBalancerServiceProvider(lb); if (Network.Provider.Netscaler.equals(provider)) { Long autoscaleUserId = autoScaleVmProfile.getAutoScaleUserId(); @@ -358,13 +357,12 @@ private LbAutoScaleVmGroup getLbAutoScaleVmGroup(AutoScaleVmGroupVO vmGroup, Aut throw new InvalidParameterValueException("secretKey for user: " + user.getUsername() + " is empty. Please generate it"); } - if (csUrl == null || csUrl.contains("localhost")) { - throw new InvalidParameterValueException(String.format("Global setting %s has to be set to the Management Server's API end point", ApiServiceConfiguration.ApiServletPath.key())); - } + ApiServiceConfiguration.validateEndpointUrl(); } LbAutoScaleVmProfile lbAutoScaleVmProfile = - new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, csUrl, zoneId, domainId, serviceOfferingId, templateId, vmName, lbNetworkUuid); + new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, ApiServiceConfiguration.ApiServletPath.value(), zoneId, domainId, serviceOfferingId, templateId, + vmName, lbNetworkUuid); return new LbAutoScaleVmGroup(vmGroup, autoScalePolicies, lbAutoScaleVmProfile, currentState); } From 307b1c048b5986a1aa9f55d0e959881fe6cba1cb Mon Sep 17 00:00:00 2001 From: Lucas Martins Date: Fri, 19 Jan 2024 16:11:45 -0300 Subject: [PATCH 02/10] Fix message and log error --- .../apache/cloudstack/config/ApiServiceConfiguration.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java b/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java index e258c4151868..5d1c396bb7c7 100644 --- a/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java +++ b/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java @@ -19,8 +19,11 @@ import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; import com.cloud.exception.InvalidParameterValueException; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; public class ApiServiceConfiguration implements Configurable { + protected static Logger LOGGER = Logger.getLogger(ApiServiceConfiguration.class); public static final ConfigKey ManagementServerAddresses = new ConfigKey<>(String.class, "host", "Advanced", "localhost", "The ip address of management server. This can also accept comma separated addresses.", true, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null); public static final ConfigKey ApiServletPath = new ConfigKey("Advanced", String.class, "endpoint.url", "http://localhost:8080/client/api", "API end point. Can be used by CS components/services deployed remotely, for sending CS API requests", true); @@ -34,8 +37,9 @@ public class ApiServiceConfiguration implements Configurable { public static void validateEndpointUrl() { String csUrl = getApiServletPathValue(); - if (csUrl == null || csUrl.contains("localhost")) { - throw new InvalidParameterValueException(String.format("Global setting %s cannot be null or localhost", ApiServletPath.key())); + if (StringUtils.isBlank(csUrl) || csUrl.contains("localhost") || csUrl.contains("127.0.0.1")) { + LOGGER.error(String.format("Global setting %s cannot contain localhost or be blank. Current value: %s", ApiServletPath.key(), csUrl)); + throw new InvalidParameterValueException("Unable to complete this operation. Contact your cloud admin."); } } From b7af4644f5674d5aef946741face8f19d12ea39f Mon Sep 17 00:00:00 2001 From: "lucas.martins.scclouds" Date: Mon, 8 Jan 2024 18:10:11 -0300 Subject: [PATCH 03/10] Using new get --- .../cluster/actionworkers/KubernetesClusterActionWorker.java | 2 +- .../com/cloud/network/lb/LoadBalancingRulesManagerImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterActionWorker.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterActionWorker.java index 9be5f4c07768..7588fe6b7082 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterActionWorker.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterActionWorker.java @@ -681,7 +681,7 @@ protected boolean createCloudStackSecret(String[] keys) { try { String command = String.format("sudo %s/%s -u '%s' -k '%s' -s '%s'", - scriptPath, deploySecretsScriptFilename, ApiServiceConfiguration.ApiServletPath.value(), keys[0], keys[1]); + scriptPath, deploySecretsScriptFilename, ApiServiceConfiguration.getApiServletPathValue(), keys[0], keys[1]); Account account = accountDao.findById(kubernetesCluster.getAccountId()); if (account != null && account.getType() == Account.Type.PROJECT) { String projectId = projectService.findByProjectAccountId(account.getId()).getUuid(); diff --git a/server/src/main/java/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/main/java/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java index 942f11cd0acf..df60553bb8e5 100644 --- a/server/src/main/java/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java +++ b/server/src/main/java/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java @@ -361,7 +361,7 @@ private LbAutoScaleVmGroup getLbAutoScaleVmGroup(AutoScaleVmGroupVO vmGroup, Aut } LbAutoScaleVmProfile lbAutoScaleVmProfile = - new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, ApiServiceConfiguration.ApiServletPath.value(), zoneId, domainId, serviceOfferingId, templateId, + new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, ApiServiceConfiguration.getApiServletPathValue(), zoneId, domainId, serviceOfferingId, templateId, vmName, lbNetworkUuid); return new LbAutoScaleVmGroup(vmGroup, autoScalePolicies, lbAutoScaleVmProfile, currentState); } From be294f1c9bf90d2216038f15563af63777cdb72f Mon Sep 17 00:00:00 2001 From: Lucas Martins Date: Fri, 19 Jan 2024 16:08:03 -0300 Subject: [PATCH 04/10] Implement unit tests --- .../config/ApiServiceConfigurationTest.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 api/src/test/java/org/apache/cloudstack/config/ApiServiceConfigurationTest.java diff --git a/api/src/test/java/org/apache/cloudstack/config/ApiServiceConfigurationTest.java b/api/src/test/java/org/apache/cloudstack/config/ApiServiceConfigurationTest.java new file mode 100644 index 000000000000..dc308ed9d63c --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/config/ApiServiceConfigurationTest.java @@ -0,0 +1,78 @@ +package org.apache.cloudstack.config; + +import com.cloud.exception.InvalidParameterValueException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class ApiServiceConfigurationTest { + + private static final String LOCALHOST = "http://localhost"; + + private static final String ENDPOINT_URL = "https://acs.clouds.com/client/api"; + + private static final String WHITE_SPACE = " "; + + private static final String BLANK_STRING = ""; + + private static final String NULL_STRING = null; + + private static final String LOCALHOST_IP = "127.0.0.1"; + + @Test(expected = InvalidParameterValueException.class) + public void validateEndpointUrlTestIfEndpointUrlContainLocalhostShouldThrowInvalidParameterValueException() { + try (MockedStatic apiServiceConfigurationMockedStatic = Mockito.mockStatic(ApiServiceConfiguration.class)) { + apiServiceConfigurationMockedStatic.when(ApiServiceConfiguration::getApiServletPathValue).thenReturn(LOCALHOST); + apiServiceConfigurationMockedStatic.when(ApiServiceConfiguration::validateEndpointUrl).thenCallRealMethod(); + ApiServiceConfiguration.validateEndpointUrl(); + } + } + + @Test + public void validateEndpointUrlTestIfEndpointUrlContainLocalhostShouldNotThrowInvalidParameterValueException() { + try (MockedStatic apiServiceConfigurationMockedStatic = Mockito.mockStatic(ApiServiceConfiguration.class)) { + apiServiceConfigurationMockedStatic.when(ApiServiceConfiguration::getApiServletPathValue).thenReturn(ENDPOINT_URL); + apiServiceConfigurationMockedStatic.when(ApiServiceConfiguration::validateEndpointUrl).thenCallRealMethod(); + ApiServiceConfiguration.validateEndpointUrl(); + } + } + + @Test(expected = InvalidParameterValueException.class) + public void validateEndpointUrlTestIfEndpointUrlIsNullShouldThrowInvalidParameterValueException() { + try (MockedStatic apiServiceConfigurationMockedStatic = Mockito.mockStatic(ApiServiceConfiguration.class)) { + apiServiceConfigurationMockedStatic.when(ApiServiceConfiguration::getApiServletPathValue).thenReturn(NULL_STRING); + apiServiceConfigurationMockedStatic.when(ApiServiceConfiguration::validateEndpointUrl).thenCallRealMethod(); + ApiServiceConfiguration.validateEndpointUrl(); + } + } + + @Test(expected = InvalidParameterValueException.class) + public void validateEndpointUrlTestIfEndpointUrlIsBlankShouldThrowInvalidParameterValueException() { + try (MockedStatic apiServiceConfigurationMockedStatic = Mockito.mockStatic(ApiServiceConfiguration.class)) { + apiServiceConfigurationMockedStatic.when(ApiServiceConfiguration::getApiServletPathValue).thenReturn(BLANK_STRING); + apiServiceConfigurationMockedStatic.when(ApiServiceConfiguration::validateEndpointUrl).thenCallRealMethod(); + ApiServiceConfiguration.validateEndpointUrl(); + } + } + + @Test(expected = InvalidParameterValueException.class) + public void validateEndpointUrlTestIfEndpointUrlIsWhiteSpaceShouldThrowInvalidParameterValueException() { + try (MockedStatic apiServiceConfigurationMockedStatic = Mockito.mockStatic(ApiServiceConfiguration.class)) { + apiServiceConfigurationMockedStatic.when(ApiServiceConfiguration::getApiServletPathValue).thenReturn(WHITE_SPACE); + apiServiceConfigurationMockedStatic.when(ApiServiceConfiguration::validateEndpointUrl).thenCallRealMethod(); + ApiServiceConfiguration.validateEndpointUrl(); + } + } + + @Test(expected = InvalidParameterValueException.class) + public void validateEndpointUrlTestIfEndpointUrlContainLocalhostIpShouldThrowInvalidParameterValueException() { + try (MockedStatic apiServiceConfigurationMockedStatic = Mockito.mockStatic(ApiServiceConfiguration.class)) { + apiServiceConfigurationMockedStatic.when(ApiServiceConfiguration::getApiServletPathValue).thenReturn(LOCALHOST_IP); + apiServiceConfigurationMockedStatic.when(ApiServiceConfiguration::validateEndpointUrl).thenCallRealMethod(); + ApiServiceConfiguration.validateEndpointUrl(); + } + } +} \ No newline at end of file From 51d38da65b82f2f2f526e5566d9ff63bfbe4a22c Mon Sep 17 00:00:00 2001 From: Lucas Martins Date: Mon, 22 Jan 2024 14:30:17 -0300 Subject: [PATCH 05/10] Add license --- .../config/ApiServiceConfigurationTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/api/src/test/java/org/apache/cloudstack/config/ApiServiceConfigurationTest.java b/api/src/test/java/org/apache/cloudstack/config/ApiServiceConfigurationTest.java index dc308ed9d63c..d9ebe13ffa4c 100644 --- a/api/src/test/java/org/apache/cloudstack/config/ApiServiceConfigurationTest.java +++ b/api/src/test/java/org/apache/cloudstack/config/ApiServiceConfigurationTest.java @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + package org.apache.cloudstack.config; import com.cloud.exception.InvalidParameterValueException; From 711ee4f6361c50ca02f1639d80358ecc54aacb27 Mon Sep 17 00:00:00 2001 From: Lucas Martins Date: Tue, 30 Jan 2024 14:12:40 -0300 Subject: [PATCH 06/10] Add newline at end of file --- .../apache/cloudstack/config/ApiServiceConfigurationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/test/java/org/apache/cloudstack/config/ApiServiceConfigurationTest.java b/api/src/test/java/org/apache/cloudstack/config/ApiServiceConfigurationTest.java index d9ebe13ffa4c..4e96af3ead41 100644 --- a/api/src/test/java/org/apache/cloudstack/config/ApiServiceConfigurationTest.java +++ b/api/src/test/java/org/apache/cloudstack/config/ApiServiceConfigurationTest.java @@ -92,4 +92,4 @@ public void validateEndpointUrlTestIfEndpointUrlContainLocalhostIpShouldThrowInv ApiServiceConfiguration.validateEndpointUrl(); } } -} \ No newline at end of file +} From f21b00dae7ebc208298363fca40e916bc388da23 Mon Sep 17 00:00:00 2001 From: Lucas Martins Date: Tue, 6 Feb 2024 15:52:52 -0300 Subject: [PATCH 07/10] Optimize imports and add containsAny (Wei suggestions) --- .../org/apache/cloudstack/config/ApiServiceConfiguration.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java b/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java index 5d1c396bb7c7..4c54e02d01f1 100644 --- a/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java +++ b/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java @@ -16,9 +16,9 @@ // under the License. package org.apache.cloudstack.config; +import com.cloud.exception.InvalidParameterValueException; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; -import com.cloud.exception.InvalidParameterValueException; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; @@ -37,7 +37,7 @@ public class ApiServiceConfiguration implements Configurable { public static void validateEndpointUrl() { String csUrl = getApiServletPathValue(); - if (StringUtils.isBlank(csUrl) || csUrl.contains("localhost") || csUrl.contains("127.0.0.1")) { + if (StringUtils.isBlank(csUrl) || StringUtils.containsAny(csUrl, "localhost", "127.0.0.1")) { LOGGER.error(String.format("Global setting %s cannot contain localhost or be blank. Current value: %s", ApiServletPath.key(), csUrl)); throw new InvalidParameterValueException("Unable to complete this operation. Contact your cloud admin."); } From 035fbf4cbcec5a4613159883d838ab02f1685de9 Mon Sep 17 00:00:00 2001 From: Lucas Martins Date: Fri, 9 Feb 2024 17:22:22 -0300 Subject: [PATCH 08/10] Change to log4j2 --- .../apache/cloudstack/config/ApiServiceConfiguration.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java b/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java index 4c54e02d01f1..9041f10336c7 100644 --- a/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java +++ b/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java @@ -20,10 +20,11 @@ import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class ApiServiceConfiguration implements Configurable { - protected static Logger LOGGER = Logger.getLogger(ApiServiceConfiguration.class); + protected static Logger LOGGER = LogManager.getLogger(ApiServiceConfiguration.class); public static final ConfigKey ManagementServerAddresses = new ConfigKey<>(String.class, "host", "Advanced", "localhost", "The ip address of management server. This can also accept comma separated addresses.", true, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null); public static final ConfigKey ApiServletPath = new ConfigKey("Advanced", String.class, "endpoint.url", "http://localhost:8080/client/api", "API end point. Can be used by CS components/services deployed remotely, for sending CS API requests", true); From aaabe6669d74fd771d4e6d1c36ba53c923aa2767 Mon Sep 17 00:00:00 2001 From: Lucas Martins <56271185+lucas-a-martins@users.noreply.github.com> Date: Fri, 16 Feb 2024 14:52:03 -0300 Subject: [PATCH 09/10] Update api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java Co-authored-by: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com> --- .../org/apache/cloudstack/config/ApiServiceConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java b/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java index 9041f10336c7..c70521af2660 100644 --- a/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java +++ b/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java @@ -39,7 +39,7 @@ public class ApiServiceConfiguration implements Configurable { public static void validateEndpointUrl() { String csUrl = getApiServletPathValue(); if (StringUtils.isBlank(csUrl) || StringUtils.containsAny(csUrl, "localhost", "127.0.0.1")) { - LOGGER.error(String.format("Global setting %s cannot contain localhost or be blank. Current value: %s", ApiServletPath.key(), csUrl)); + LOGGER.error("Global setting [{}] cannot contain localhost or be blank. Current value: {}", ApiServletPath.key(), csUrl); throw new InvalidParameterValueException("Unable to complete this operation. Contact your cloud admin."); } } From c7d2568fb70858600eb3ba3d7a5c884a61ea66aa Mon Sep 17 00:00:00 2001 From: erikbocks Date: Mon, 1 Dec 2025 14:55:00 -0300 Subject: [PATCH 10/10] added ipv6 loopback address to invalid endpoints list --- .../org/apache/cloudstack/config/ApiServiceConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java b/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java index c70521af2660..113b97f43c8f 100644 --- a/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java +++ b/api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java @@ -38,7 +38,7 @@ public class ApiServiceConfiguration implements Configurable { public static void validateEndpointUrl() { String csUrl = getApiServletPathValue(); - if (StringUtils.isBlank(csUrl) || StringUtils.containsAny(csUrl, "localhost", "127.0.0.1")) { + if (StringUtils.isBlank(csUrl) || StringUtils.containsAny(csUrl, "localhost", "127.0.0.1", "[::1]")) { LOGGER.error("Global setting [{}] cannot contain localhost or be blank. Current value: {}", ApiServletPath.key(), csUrl); throw new InvalidParameterValueException("Unable to complete this operation. Contact your cloud admin."); }