use of org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method retrieveGatewayAPIDto.
public static GatewayAPIDTO retrieveGatewayAPIDto(APIProduct apiProduct, Environment environment, String tenantDomain, String extractedFolderPath) throws APIManagementException, XMLStreamException, APITemplateException {
List<ClientCertificateDTO> clientCertificatesDTOList = ImportUtils.retrieveClientCertificates(extractedFolderPath);
Map<String, APIDTO> apidtoMap = retrieveAssociatedApis(extractedFolderPath);
Map<String, APIDTO> associatedAPIsMap = convertAPIIdToDto(apidtoMap.values());
for (APIProductResource productResource : apiProduct.getProductResources()) {
String apiId = productResource.getApiId();
APIDTO apidto = associatedAPIsMap.get(apiId);
if (apidto != null) {
API api = APIMappingUtil.fromDTOtoAPI(apidto, apidto.getProvider());
productResource.setApiIdentifier(api.getId());
if (api.isAdvertiseOnly()) {
productResource.setEndpointConfig(APIUtil.generateEndpointConfigForAdvertiseOnlyApi(api));
} else {
productResource.setEndpointConfig(api.getEndpointConfig());
}
if (StringUtils.isNotEmpty(api.getInSequence())) {
String sequenceName = APIUtil.getSequenceExtensionName(apiProduct.getId().getName(), apiProduct.getId().getVersion()).concat("--").concat(productResource.getApiId()) + APIConstants.API_CUSTOM_SEQ_IN_EXT;
productResource.setInSequenceName(sequenceName);
}
if (StringUtils.isNotEmpty(api.getOutSequence())) {
String sequenceName = APIUtil.getSequenceExtensionName(apiProduct.getId().getName(), apiProduct.getId().getVersion()).concat("--").concat(productResource.getApiId()) + APIConstants.API_CUSTOM_SEQ_OUT_EXT;
productResource.setOutSequenceName(sequenceName);
}
if (StringUtils.isNotEmpty(api.getFaultSequence())) {
String sequenceName = APIUtil.getSequenceExtensionName(apiProduct.getId().getName(), apiProduct.getId().getVersion()).concat("--").concat(productResource.getApiId()) + APIConstants.API_CUSTOM_SEQ_FAULT_EXT;
productResource.setFaultSequenceName(sequenceName);
}
productResource.setProductIdentifier(apiProduct.getId());
productResource.setEndpointSecurityMap(APIUtil.setEndpointSecurityForAPIProduct(api));
}
}
APITemplateBuilder apiTemplateBuilder = TemplateBuilderUtil.getAPITemplateBuilder(apiProduct, tenantDomain, clientCertificatesDTOList, convertAPIIdToDto(associatedAPIsMap.values()));
return createAPIGatewayDTOtoPublishAPI(environment, apiProduct, apiTemplateBuilder, tenantDomain, apidtoMap, clientCertificatesDTOList);
}
use of org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method setClientCertificatesToBeAdded.
/**
* To deploy client certificate in given API environment.
*
* @param tenantDomain Tenant domain.
* @param clientCertificatesDTOList
*/
private static void setClientCertificatesToBeAdded(String tenantDomain, GatewayAPIDTO gatewayAPIDTO, List<ClientCertificateDTO> clientCertificatesDTOList) {
int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain);
if (clientCertificatesDTOList != null) {
for (ClientCertificateDTO clientCertificateDTO : clientCertificatesDTOList) {
GatewayContentDTO clientCertificate = new GatewayContentDTO();
clientCertificate.setName(clientCertificateDTO.getAlias() + "_" + tenantId);
clientCertificate.setContent(clientCertificateDTO.getCertificate());
gatewayAPIDTO.setClientCertificatesToBeAdd(addGatewayContentToList(clientCertificate, gatewayAPIDTO.getClientCertificatesToBeAdd()));
}
}
}
use of org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method addAWSCredentialsToList.
private static void addAWSCredentialsToList(String prefix, API api, GatewayAPIDTO gatewayAPIDTO, org.json.JSONObject endpointConfig) {
if (StringUtils.isNotEmpty((String) endpointConfig.get(APIConstants.AMZN_SECRET_KEY))) {
CredentialDto awsSecretDto = new CredentialDto();
if (StringUtils.isNotEmpty(prefix)) {
awsSecretDto.setAlias(prefix.concat("--").concat(GatewayUtils.retrieveAWSCredAlias(api.getId().getApiName(), api.getId().getVersion(), APIConstants.ENDPOINT_TYPE_AWSLAMBDA)));
} else {
awsSecretDto.setAlias(GatewayUtils.retrieveAWSCredAlias(api.getId().getApiName(), api.getId().getVersion(), APIConstants.ENDPOINT_TYPE_AWSLAMBDA));
}
awsSecretDto.setPassword((String) endpointConfig.get(APIConstants.AMZN_SECRET_KEY));
gatewayAPIDTO.setCredentialsToBeAdd(addCredentialsToList(awsSecretDto, gatewayAPIDTO.getCredentialsToBeAdd()));
}
}
use of org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method createAPIGatewayDTOtoPublishAPI.
private static GatewayAPIDTO createAPIGatewayDTOtoPublishAPI(Environment environment, APIProduct apiProduct, APITemplateBuilder builder, String tenantDomain, Map<String, APIDTO> associatedAPIsMap, List<ClientCertificateDTO> clientCertificatesDTOList) throws APITemplateException, XMLStreamException, APIManagementException {
APIProductIdentifier id = apiProduct.getId();
GatewayAPIDTO productAPIDto = new GatewayAPIDTO();
productAPIDto.setProvider(id.getProviderName());
productAPIDto.setApiId(apiProduct.getUuid());
productAPIDto.setName(id.getName());
productAPIDto.setVersion(id.getVersion());
productAPIDto.setTenantDomain(tenantDomain);
productAPIDto.setKeyManagers(Collections.singletonList(APIConstants.KeyManager.API_LEVEL_ALL_KEY_MANAGERS));
String definition = apiProduct.getDefinition();
productAPIDto.setLocalEntriesToBeRemove(GatewayUtils.addStringToList(apiProduct.getUuid(), productAPIDto.getLocalEntriesToBeRemove()));
GatewayContentDTO productLocalEntry = new GatewayContentDTO();
productLocalEntry.setName(apiProduct.getUuid());
productLocalEntry.setContent("<localEntry key=\"" + apiProduct.getUuid() + "\">" + definition.replaceAll("&(?!amp;)", "&").replaceAll("<", "<").replaceAll(">", ">") + "</localEntry>");
productAPIDto.setLocalEntriesToBeAdd(addGatewayContentToList(productLocalEntry, productAPIDto.getLocalEntriesToBeAdd()));
setClientCertificatesToBeAdded(tenantDomain, productAPIDto, clientCertificatesDTOList);
for (Map.Entry<String, APIDTO> apidtoEntry : associatedAPIsMap.entrySet()) {
String apiExtractedPath = apidtoEntry.getKey();
APIDTO apidto = apidtoEntry.getValue();
API api = APIMappingUtil.fromDTOtoAPI(apidto, apidto.getProvider());
api.setUuid(apidto.getId());
GatewayUtils.setCustomSequencesToBeRemoved(apiProduct.getId(), api.getUuid(), productAPIDto);
APITemplateBuilder apiTemplateBuilder = new APITemplateBuilderImpl(api, apiProduct);
addEndpoints(api, apiTemplateBuilder, productAPIDto);
setCustomSequencesToBeAdded(apiProduct, api, productAPIDto, apiExtractedPath, apidto);
setAPIFaultSequencesToBeAdded(api, productAPIDto, apiExtractedPath, apidto);
String prefix = id.getName() + "--v" + id.getVersion();
setSecureVaultPropertyToBeAdded(prefix, api, productAPIDto);
}
productAPIDto.setApiDefinition(builder.getConfigStringForTemplate(environment));
return productAPIDto;
}
use of org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method addEndpoints.
private static void addEndpoints(API api, APITemplateBuilder builder, GatewayAPIDTO gatewayAPIDTO) throws APITemplateException, XMLStreamException {
ArrayList<String> arrayListToAdd = getEndpointType(api);
for (String type : arrayListToAdd) {
String endpointConfigContext = builder.getConfigStringForEndpointTemplate(type);
GatewayContentDTO endpoint = new GatewayContentDTO();
endpoint.setName(getEndpointName(endpointConfigContext));
endpoint.setContent(endpointConfigContext);
gatewayAPIDTO.setEndpointEntriesToBeAdd(addGatewayContentToList(endpoint, gatewayAPIDTO.getEndpointEntriesToBeAdd()));
}
}
Aggregations