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

Add: Validation for Policy Type #12371

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -3104,6 +3104,7 @@ public enum ConfigType {
public static final String SYNAPSE_POLICY_DEFINITION_EXTENSION_XML = ".xml";
public static final String CC_POLICY_DEFINITION_EXTENSION = ".gotmpl";
public static final String YAML_CONTENT_TYPE = "yaml";
public static final String J2_CONTENT_TYPE = "j2";
public static final String COMMON_OPERATION_POLICY_SPECIFICATIONS_LOCATION = "repository" + File.separator
+ "resources" + File.separator + "operation_policies" + File.separator + "specifications";
public static final String COMMON_OPERATION_POLICY_DEFINITIONS_LOCATION = "repository" + File.separator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public Response addCommonOperationPolicy(InputStream policySpecFileInputStream,
if (org.apache.commons.lang3.StringUtils.isBlank(fileContentType)) {
fileContentType = policySpecFileDetail.getContentType().toString();
}

if (APIConstants.YAML_CONTENT_TYPE.equals(fileContentType)) {
jsonContent = CommonUtil.yamlToJson(jsonContent);
}
Expand All @@ -107,6 +108,14 @@ public Response addCommonOperationPolicy(InputStream policySpecFileInputStream,
.prepareOperationPolicyData(policySpecification, organization);

if (synapsePolicyDefinitionFileInputStream != null) {
String defFileName = synapsePolicyDefinitionFileDetail.getDataHandler().getName();
String defFileContentType = FilenameUtils.getExtension(defFileName);
if (org.apache.commons.lang3.StringUtils.isBlank(defFileContentType)) {
defFileContentType = synapsePolicyDefinitionFileDetail.getContentType().toString();
}
if (!APIConstants.J2_CONTENT_TYPE.equals(defFileContentType)) {
throw new APIManagementException("Unsupported file type for Operation Policy");
}
String synapsePolicyDefinition =
RestApiPublisherUtils.readInputStream(synapsePolicyDefinitionFileInputStream,
synapsePolicyDefinitionFileDetail);
Expand All @@ -117,6 +126,14 @@ public Response addCommonOperationPolicy(InputStream policySpecFileInputStream,
}

if (ccPolicyDefinitionFileInputStream != null) {
String defFileName = ccPolicyDefinitionFileDetail.getDataHandler().getName();
String defFileContentType = FilenameUtils.getExtension(defFileName);
if (org.apache.commons.lang3.StringUtils.isBlank(defFileContentType)) {
defFileContentType = ccPolicyDefinitionFileDetail.getContentType().toString();
}
if (!APIConstants.CC_POLICY_DEFINITION_EXTENSION.equals(defFileContentType)) {
throw new APIManagementException("Unsupported file type for Operation Policy");
}
String choreoConnectPolicyDefinition = RestApiPublisherUtils
.readInputStream(ccPolicyDefinitionFileInputStream, ccPolicyDefinitionFileDetail);
ccPolicyDefinition = new OperationPolicyDefinition();
Expand Down
Loading