Skip to content

Commit c60a59a

Browse files
lucas.martins.sccloudserikbocks
authored andcommitted
Fix validate endpoint url message
1 parent b99a030 commit c60a59a

4 files changed

Lines changed: 21 additions & 21 deletions

File tree

api/src/main/java/org/apache/cloudstack/config/ApiServiceConfiguration.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.cloudstack.framework.config.ConfigKey;
2020
import org.apache.cloudstack.framework.config.Configurable;
21+
import com.cloud.exception.InvalidParameterValueException;
2122

2223
public class ApiServiceConfiguration implements Configurable {
2324
public static final ConfigKey<String> 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 {
2930
"true", "Are the source checks on API calls enabled (true) or not (false)? See api.allowed.source.cidr.list", true, ConfigKey.Scope.Global);
3031
public static final ConfigKey<String> ApiAllowedSourceCidrList = new ConfigKey<>(String.class, "api.allowed.source.cidr.list", "Advanced",
3132
"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);
33+
34+
35+
public static void validateEndpointUrl() {
36+
String csUrl = getApiServletPathValue();
37+
if (csUrl == null || csUrl.contains("localhost")) {
38+
throw new InvalidParameterValueException(String.format("Global setting %s cannot be null or localhost", ApiServletPath.key()));
39+
}
40+
}
41+
42+
public static String getApiServletPathValue() {
43+
return ApiServletPath.value();
44+
}
45+
3246
@Override
3347
public String getConfigComponentName() {
3448
return ApiServiceConfiguration.class.getSimpleName();

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -885,15 +885,6 @@ public KubernetesClusterResponse createKubernetesClusterResponse(long kubernetes
885885
return response;
886886
}
887887

888-
private void validateEndpointUrl() {
889-
String csUrl = ApiServiceConfiguration.ApiServletPath.value();
890-
if (csUrl == null || csUrl.contains("localhost")) {
891-
String error = String.format("Global setting %s has to be set to the Management Server's API end point",
892-
ApiServiceConfiguration.ApiServletPath.key());
893-
throw new InvalidParameterValueException(error);
894-
}
895-
}
896-
897888
private DataCenter validateAndGetZoneForKubernetesCreateParameters(Long zoneId, Long networkId) {
898889
DataCenter zone = dataCenterDao.findById(zoneId);
899890
if (zone == null) {
@@ -988,7 +979,7 @@ public boolean isCommandSupported(KubernetesCluster cluster, String cmdName) {
988979
}
989980

990981
private void validateManagedKubernetesClusterCreateParameters(final CreateKubernetesClusterCmd cmd) throws CloudRuntimeException {
991-
validateEndpointUrl();
982+
ApiServiceConfiguration.validateEndpointUrl();
992983
final String name = cmd.getName();
993984
final Long zoneId = cmd.getZoneId();
994985
final Long kubernetesVersionId = cmd.getKubernetesVersionId();
@@ -1288,7 +1279,7 @@ private void validateKubernetesClusterScaleParameters(ScaleKubernetesClusterCmd
12881279
KubernetesVersionManagerImpl.MINIMUN_AUTOSCALER_SUPPORTED_VERSION ));
12891280
}
12901281

1291-
validateEndpointUrl();
1282+
ApiServiceConfiguration.validateEndpointUrl();
12921283

12931284
if (minSize == null || maxSize == null) {
12941285
throw new InvalidParameterValueException("Autoscaling requires minsize and maxsize to be passed");
@@ -1393,7 +1384,7 @@ protected boolean isAnyNodeOfferingEmpty(Map<String, Long> map) {
13931384

13941385
private void validateKubernetesClusterUpgradeParameters(UpgradeKubernetesClusterCmd cmd) {
13951386
// Validate parameters
1396-
validateEndpointUrl();
1387+
ApiServiceConfiguration.validateEndpointUrl();
13971388

13981389
final Long kubernetesClusterId = cmd.getId();
13991390
final Long upgradeVersionId = cmd.getKubernetesVersionId();

server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@ public void checkAutoScaleUser(Long autoscaleUserId, long accountId) {
512512

513513
String apiKey = user.getApiKey();
514514
String secretKey = user.getSecretKey();
515-
String csUrl = ApiServiceConfiguration.ApiServletPath.value();
516515

517516
if (apiKey == null) {
518517
throw new InvalidParameterValueException("apiKey for user: " + user.getUsername() + " is empty. Please generate it");
@@ -522,9 +521,7 @@ public void checkAutoScaleUser(Long autoscaleUserId, long accountId) {
522521
throw new InvalidParameterValueException("secretKey for user: " + user.getUsername() + " is empty. Please generate it");
523522
}
524523

525-
if (csUrl == null || csUrl.contains("localhost")) {
526-
throw new InvalidParameterValueException(String.format("Global setting %s has to be set to the Management Server's API end point", ApiServiceConfiguration.ApiServletPath.key()));
527-
}
524+
ApiServiceConfiguration.validateEndpointUrl();
528525
}
529526
@Override
530527
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMPROFILE_CREATE, eventDescription = "creating autoscale vm profile", create = true)

server/src/main/java/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ private LbAutoScaleVmGroup getLbAutoScaleVmGroup(AutoScaleVmGroupVO vmGroup, Aut
337337

338338
String apiKey = null;
339339
String secretKey = null;
340-
String csUrl = ApiServiceConfiguration.ApiServletPath.value();
341340
Network.Provider provider = getLoadBalancerServiceProvider(lb);
342341
if (Network.Provider.Netscaler.equals(provider)) {
343342
Long autoscaleUserId = autoScaleVmProfile.getAutoScaleUserId();
@@ -358,13 +357,12 @@ private LbAutoScaleVmGroup getLbAutoScaleVmGroup(AutoScaleVmGroupVO vmGroup, Aut
358357
throw new InvalidParameterValueException("secretKey for user: " + user.getUsername() + " is empty. Please generate it");
359358
}
360359

361-
if (csUrl == null || csUrl.contains("localhost")) {
362-
throw new InvalidParameterValueException(String.format("Global setting %s has to be set to the Management Server's API end point", ApiServiceConfiguration.ApiServletPath.key()));
363-
}
360+
ApiServiceConfiguration.validateEndpointUrl();
364361
}
365362

366363
LbAutoScaleVmProfile lbAutoScaleVmProfile =
367-
new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, csUrl, zoneId, domainId, serviceOfferingId, templateId, vmName, lbNetworkUuid);
364+
new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, ApiServiceConfiguration.ApiServletPath.value(), zoneId, domainId, serviceOfferingId, templateId,
365+
vmName, lbNetworkUuid);
368366
return new LbAutoScaleVmGroup(vmGroup, autoScalePolicies, lbAutoScaleVmProfile, currentState);
369367
}
370368

0 commit comments

Comments
 (0)