Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable configuring service-catalog version #2930

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ public class Constants {
public static final String USER_NAME = "username";
public static final String PASSWORD = "password";
public static final String SERVICE_CATALOG_EXECUTOR_THREADS = "executor_threads";

public static final String SERVICE_CATALOG_PUBLISH_ENDPOINT = "api/am/service-catalog/v1/services/import?overwrite" +
"=true";
public static final String SERVICE_CATALOG_GET_SERVICES_ENDPOINT = "api/am/service-catalog/v1/services";
public static final String SERVICE_CATALOG_API_VERSION_PROPERTY = "service-catalog.api.version";
public static final String SERVICE_CATALOG_DEFAULT_API_VERSION = "v1";
public static final String SERVICE_CATALOG_ENDPOINT_PREFIX = "api/am/service-catalog/";
public static final String SERVICE_CATALOG_PUBLISH_ENDPOINT = "/services/import?overwrite=true";
public static final String SERVICE_CATALOG_GET_SERVICES_ENDPOINT = "/services";

// creating the payload.zip related constants
public static final String SERVICE_CATALOG = "ServiceCatalog";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.wso2.micro.application.deployer.CarbonApplication;
import org.wso2.micro.core.util.CarbonException;
import org.wso2.micro.core.util.StringUtils;
import org.wso2.micro.integrator.core.util.MicroIntegratorBaseUtils;
import org.wso2.micro.integrator.initializer.deployment.application.deployer.CappDeployer;
import org.wso2.securevault.SecretResolver;
import org.wso2.securevault.SecretResolverFactory;
Expand Down Expand Up @@ -83,6 +82,15 @@ public class ServiceCatalogUtils {
private static String resolvedUrl;
private static String lineSeparator;
private static Map<String, Object> parsedConfigs;
private static final String API_VERSION;

static {
String apiVersion = System.getProperty(SERVICE_CATALOG_API_VERSION_PROPERTY);
if (apiVersion == null) {
apiVersion = SERVICE_CATALOG_DEFAULT_API_VERSION;
}
API_VERSION = apiVersion;
}

/**
* Update the service url by injecting env variables.
Expand Down Expand Up @@ -241,11 +249,10 @@ public static Map<String, String> getAllServices(Map<String, String> apimConfigs
(apimConfigs.get(USER_NAME) + ":" + apimConfigs.get(PASSWORD)).getBytes());

// create get all services url
if (APIMHost.endsWith("/")) {
APIMHost = APIMHost + SERVICE_CATALOG_GET_SERVICES_ENDPOINT;
} else {
APIMHost = APIMHost + "/" + SERVICE_CATALOG_GET_SERVICES_ENDPOINT;
if (!APIMHost.endsWith("/")) {
APIMHost = APIMHost + "/";
}
APIMHost = APIMHost + SERVICE_CATALOG_ENDPOINT_PREFIX + API_VERSION + SERVICE_CATALOG_GET_SERVICES_ENDPOINT;

try {
HttpsURLConnection connection = (HttpsURLConnection) new URL(APIMHost).openConnection();
Expand Down Expand Up @@ -303,11 +310,10 @@ private static int uploadZip(Map<String, String> apimConfigs, String attachmentF
String APIMHost = apimConfigs.get(APIM_HOST);

// create POST URL
if (APIMHost.endsWith("/")) {
APIMHost = APIMHost + SERVICE_CATALOG_PUBLISH_ENDPOINT;
} else {
APIMHost = APIMHost + "/" + SERVICE_CATALOG_PUBLISH_ENDPOINT;
if (!APIMHost.endsWith("/")) {
APIMHost = APIMHost + "/";
}
APIMHost = APIMHost + SERVICE_CATALOG_ENDPOINT_PREFIX + API_VERSION + SERVICE_CATALOG_PUBLISH_ENDPOINT;

String encodeBytes =
Base64.getEncoder().encodeToString(
Expand Down
Loading