Search in sources :

Example 11 with GatewayAPIDTO

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);
}
Also used : GatewayAPIDTO(org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO) APIDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) APITemplateBuilder(org.wso2.carbon.apimgt.impl.template.APITemplateBuilder) ClientCertificateDTO(org.wso2.carbon.apimgt.api.dto.ClientCertificateDTO) API(org.wso2.carbon.apimgt.api.model.API)

Example 12 with GatewayAPIDTO

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()));
        }
    }
}
Also used : ClientCertificateDTO(org.wso2.carbon.apimgt.api.dto.ClientCertificateDTO) GatewayContentDTO(org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO)

Example 13 with GatewayAPIDTO

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()));
    }
}
Also used : CredentialDto(org.wso2.carbon.apimgt.api.gateway.CredentialDto)

Example 14 with GatewayAPIDTO

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;)", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;") + "</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;
}
Also used : GatewayAPIDTO(org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) GatewayAPIDTO(org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO) APIDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO) APITemplateBuilder(org.wso2.carbon.apimgt.impl.template.APITemplateBuilder) API(org.wso2.carbon.apimgt.api.model.API) Map(java.util.Map) HashMap(java.util.HashMap) APITemplateBuilderImpl(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APITemplateBuilderImpl) GatewayContentDTO(org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO)

Example 15 with GatewayAPIDTO

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()));
    }
}
Also used : GatewayContentDTO(org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO)

Aggregations

GatewayContentDTO (org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO)11 GatewayAPIDTO (org.wso2.carbon.apimgt.api.gateway.GatewayAPIDTO)10 API (org.wso2.carbon.apimgt.api.model.API)5 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)4 APITemplateBuilder (org.wso2.carbon.apimgt.impl.template.APITemplateBuilder)4 Gson (com.google.gson.Gson)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AxisFault (org.apache.axis2.AxisFault)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3 ClientCertificateDTO (org.wso2.carbon.apimgt.api.dto.ClientCertificateDTO)3 CredentialDto (org.wso2.carbon.apimgt.api.gateway.CredentialDto)3 ArtifactSynchronizerException (org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException)3 APIDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO)3 HashSet (java.util.HashSet)2 JSONObject (org.json.simple.JSONObject)2 APIDefinition (org.wso2.carbon.apimgt.api.APIDefinition)2 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)2 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)2