Skip to content

Commit

Permalink
Add: Validations for APICTL Export scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
BLasan committed Sep 18, 2024
1 parent 1bbb128 commit 3032743
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2923,8 +2923,7 @@ public static void validateAPIEndpointConfig(Object endpointConfigObject, String
if (endpointConfigMap != null && endpointConfigMap.containsKey("endpoint_type")
&& APIConstants.ENDPOINT_TYPE_SEQUENCE.equals(
endpointConfigMap.get(APIConstants.API_ENDPOINT_CONFIG_PROTOCOL_TYPE))
&& !APIConstants.API_TYPE_HTTP.equalsIgnoreCase(apiType)
&& !APIConstants.API_TYPE_SOAPTOREST.equalsIgnoreCase(apiType)) {
&& !APIConstants.API_TYPE_HTTP.equalsIgnoreCase(apiType)) {
throw new APIManagementException("Invalid endpoint configuration provided for the API " + apiName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,16 @@ public static File exportApi(APIProvider apiProvider, APIIdentifier apiIdentifie
JsonObject endpointConfig = JsonParser.parseString(api.getEndpointConfig()).getAsJsonObject();
if (APIConstants.ENDPOINT_TYPE_SEQUENCE.equals(
endpointConfig.get(API_ENDPOINT_CONFIG_PROTOCOL_TYPE).getAsString()) && StringUtils.equals(
apiDtoToReturn.getType().toString().toLowerCase(), APIConstants.API_TYPE_HTTP.toLowerCase())
|| StringUtils.equals(apiDtoToReturn.getType().toString().toLowerCase(),
APIConstants.API_TYPE_SOAPTOREST.toLowerCase())) {
addCustomBackendToArchive(archivePath, apiProvider, currentApiUuid);
apiDtoToReturn.getType().toString().toLowerCase(), APIConstants.API_TYPE_HTTP.toLowerCase())) {
String sandSequenceName = null;
String prodSequenceName = null;
if (endpointConfig.get("sandbox") != null) {
sandSequenceName = endpointConfig.get("sandbox").getAsString();
}
if (endpointConfig.get("production") != null) {
prodSequenceName = endpointConfig.get("production").getAsString();
}
addCustomBackendToArchive(archivePath, apiProvider, currentApiUuid, sandSequenceName, prodSequenceName);
}
}

Expand Down Expand Up @@ -641,23 +647,29 @@ public static void addEndpointCertificatesToArchive(String archivePath, APIDTO a
}
}

public static void addCustomBackendToArchive(String archivePath, APIProvider apiProvider, String apiUUID)
throws APIManagementException {
public static void addCustomBackendToArchive(String archivePath, APIProvider apiProvider, String apiUUID,
String prodBackendName, String sandBackendName) throws APIManagementException {
try {
CommonUtil.createDirectory(archivePath + File.separator + ImportExportConstants.CUSTOM_BACKEND_DIRECTORY);

// Add production Backend Sequences
SequenceBackendData data = apiProvider.getCustomBackendByAPIUUID(apiUUID,
APIConstants.API_KEY_TYPE_PRODUCTION);
if (data != null) {
String seqName = APIUtil.getCustomBackendName(apiUUID, APIConstants.API_KEY_TYPE_PRODUCTION);
String seqName = prodBackendName;
if (StringUtils.isEmpty(seqName)) {
seqName = APIUtil.getCustomBackendName(apiUUID, APIConstants.API_KEY_TYPE_PRODUCTION);
}
exportCustomBackend(seqName, data.getSequence(), archivePath);
}

// Add sandbox Backend Sequences
data = apiProvider.getCustomBackendByAPIUUID(apiUUID, APIConstants.API_KEY_TYPE_SANDBOX);
if (data != null) {
String seqName = APIUtil.getCustomBackendName(apiUUID, APIConstants.API_KEY_TYPE_SANDBOX);
String seqName = sandBackendName;
if (StringUtils.isEmpty(seqName)) {
seqName = APIUtil.getCustomBackendName(apiUUID, APIConstants.API_KEY_TYPE_SANDBOX);
}
exportCustomBackend(seqName, data.getSequence(), archivePath);
}

Expand Down

0 comments on commit 3032743

Please sign in to comment.