Skip to content

Commit cfcb954

Browse files
committed
Restrict deploying revision in read only environment
1 parent 63326ef commit cfcb954

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ public enum ExceptionCodes implements ErrorHandler {
165165
"A Gateway Environment with %s already exists"),
166166
READONLY_GATEWAY_ENVIRONMENT(900508, "Gateway Environment is read only", 400,
167167
"A Gateway Environment with %s is read only"),
168+
READ_ONLY_MODE_GATEWAY_ENVIRONMENT(900515, "Gateway environment mode is read only", 400,
169+
"Cannot deploy revision in gateway environment %s with read only mode."),
168170
GATEWAY_ENVIRONMENT_DUPLICATE_VHOST_FOUND(900509, "Gateway Environment with duplicate virtual hosts",
169171
400, "A Gateway Environment cannot exists with duplicate virtual hosts"),
170172
READONLY_GATEWAY_ENVIRONMENT_NAME(900510, "Names of Gateway Environment cannot be changed",

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/restapi/publisher/ApisApiServiceImplUtils.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818

1919
package org.wso2.carbon.apimgt.impl.restapi.publisher;
2020

21-
import org.wso2.carbon.apimgt.api.model.Backend;
21+
import org.wso2.carbon.apimgt.api.model.*;
2222
import org.apache.http.client.HttpClient;
23-
import org.wso2.carbon.apimgt.api.model.BackendOperation;
24-
import org.wso2.carbon.apimgt.api.model.BackendOperationMapping;
2523
import org.wso2.carbon.apimgt.impl.MCPInitializerAndToolFetcher;
2624
import software.amazon.awssdk.core.exception.SdkClientException;
2725
import com.fasterxml.jackson.core.type.TypeReference;
@@ -53,19 +51,6 @@
5351
import org.wso2.carbon.apimgt.api.ExceptionCodes;
5452
import org.wso2.carbon.apimgt.api.dto.APIEndpointValidationDTO;
5553
import org.wso2.carbon.apimgt.api.dto.EnvironmentPropertiesDTO;
56-
import org.wso2.carbon.apimgt.api.model.API;
57-
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
58-
import org.wso2.carbon.apimgt.api.model.APIRevision;
59-
import org.wso2.carbon.apimgt.api.model.APIRevisionDeployment;
60-
import org.wso2.carbon.apimgt.api.model.Comment;
61-
import org.wso2.carbon.apimgt.api.model.Environment;
62-
import org.wso2.carbon.apimgt.api.model.ResourceFile;
63-
import org.wso2.carbon.apimgt.api.model.Scope;
64-
import org.wso2.carbon.apimgt.api.model.ServiceEntry;
65-
import org.wso2.carbon.apimgt.api.model.SwaggerData;
66-
import org.wso2.carbon.apimgt.api.model.Tier;
67-
import org.wso2.carbon.apimgt.api.model.URITemplate;
68-
import org.wso2.carbon.apimgt.api.model.VHost;
6954
import org.wso2.carbon.apimgt.impl.APIConstants;
7055
import org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO;
7156
import org.wso2.carbon.apimgt.impl.restapi.CommonUtils;
@@ -1103,10 +1088,19 @@ public static APIRevisionDeployment mapAPIRevisionDeploymentWithValidation(Strin
11031088
String vhost, boolean mandatoryVHOST)
11041089
throws APIManagementException {
11051090

1106-
if (environments.get(environment) == null) {
1091+
Environment env = environments.get(environment);
1092+
if (env == null) {
11071093
final String errorMessage = "Gateway environment not found: " + environment;
11081094
throw new APIManagementException(errorMessage, ExceptionCodes.from(
11091095
ExceptionCodes.INVALID_GATEWAY_ENVIRONMENT, String.format("name '%s'", environment)));
1096+
} else {
1097+
if (GatewayMode.READ_ONLY.getMode().equals(env.getMode())) {
1098+
final String errorMessage = "The mode of gateway environment : " + environment
1099+
+ " is READ_ONLY. Cannot deploy revision";
1100+
throw new APIManagementException(errorMessage,
1101+
ExceptionCodes.from(ExceptionCodes.READ_ONLY_MODE_GATEWAY_ENVIRONMENT,
1102+
String.format("name '%s'", environment)));
1103+
}
11101104
}
11111105

11121106
if (mandatoryVHOST && StringUtils.isEmpty(vhost)) {

0 commit comments

Comments
 (0)