From 9c40f674ce38ab5b9050a221807af7f81ee5788c Mon Sep 17 00:00:00 2001 From: BLasan Date: Tue, 17 Sep 2024 11:38:07 +0530 Subject: [PATCH] Add: API Validation for Sequence Backend --- .../main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java | 4 +--- .../carbon/apimgt/persistence/RegistryPersistenceImpl.java | 2 +- .../rest/api/publisher/v1/common/TemplateBuilderUtil.java | 4 +++- .../rest/api/publisher/v1/common/mappings/ExportUtils.java | 5 ++++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java index 271795adbdd4..dba95b8f28bf 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java @@ -2920,10 +2920,8 @@ public static void validateAPIEndpointConfig(Object endpointConfigObject, String throws APIManagementException { Map endpointConfigMap = (Map) endpointConfigObject; - if (endpointConfigMap.containsKey("endpoint_type") && endpointConfigMap.containsKey("sequence_name") - && APIConstants.ENDPOINT_TYPE_SEQUENCE.equals( + if (endpointConfigMap.containsKey("endpoint_type") && APIConstants.ENDPOINT_TYPE_SEQUENCE.equals( endpointConfigMap.get(APIConstants.API_ENDPOINT_CONFIG_PROTOCOL_TYPE)) - && !APIConstants.APITransportType.GRAPHQL.toString().equalsIgnoreCase(apiType) && !APIConstants.API_TYPE_HTTP.equalsIgnoreCase(apiType) && !APIConstants.API_TYPE_SOAPTOREST.equalsIgnoreCase(apiType)) { throw new APIManagementException("Invalid endpoint configuration provided for the API " + apiName); diff --git a/components/apimgt/org.wso2.carbon.apimgt.persistence/src/main/java/org/wso2/carbon/apimgt/persistence/RegistryPersistenceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.persistence/src/main/java/org/wso2/carbon/apimgt/persistence/RegistryPersistenceImpl.java index 0bd6cada9623..06e588be0f40 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.persistence/src/main/java/org/wso2/carbon/apimgt/persistence/RegistryPersistenceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.persistence/src/main/java/org/wso2/carbon/apimgt/persistence/RegistryPersistenceImpl.java @@ -393,7 +393,7 @@ public void restoreAPIRevision(Organization org, String apiUUID, String revision GenericArtifact artifact = getAPIArtifact(apiUUID, registry); artifact.setAttribute(APIConstants.API_OVERVIEW_STATUS, lifecycleStatus); // Update with the modified artifact - artifactManager.updateGenericArtifact(artifact); + artifactManager.updateGenericArtifact(apiArtifact); RegistryPersistenceUtil.clearResourcePermissions(apiPath, api.getId(), ((UserRegistry) registry).getTenantId()); RegistryPersistenceUtil.setResourcePermissions(api.getId().getProviderName(), api.getVisibility(), diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/TemplateBuilderUtil.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/TemplateBuilderUtil.java index 04436fa171fa..a0b04bc18049 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/TemplateBuilderUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/TemplateBuilderUtil.java @@ -727,7 +727,9 @@ private static void setCustomSequencesToBeAdded(APIProduct apiProduct, API api, JsonObject endpointConfigMap = JsonParser.parseString(api.getEndpointConfig()).getAsJsonObject(); if (endpointConfigMap != null && APIConstants.ENDPOINT_TYPE_SEQUENCE.equals( - endpointConfigMap.get(APIConstants.API_ENDPOINT_CONFIG_PROTOCOL_TYPE).getAsString())) { + endpointConfigMap.get(APIConstants.API_ENDPOINT_CONFIG_PROTOCOL_TYPE).getAsString()) && ( + APIConstants.API_TYPE_HTTP.equals(api.getType()) || APIConstants.API_TYPE_SOAPTOREST.equals( + api.getType()))) { GatewayContentDTO gatewayCustomBackendSequenceDTO = retrieveCustomBackendSequence(api, APIConstants.API_KEY_TYPE_SANDBOX, extractedPath); if (gatewayCustomBackendSequenceDTO != null) { diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java index b78b0d3719f4..116b5e500b2a 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java @@ -220,7 +220,10 @@ 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())) { + 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); }