use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class WebSubConfigContextTest method testWithoutSecretConfigContextForAPI.
@Test
public void testWithoutSecretConfigContextForAPI() throws Exception {
API api = new API(new APIIdentifier("admin", "websubAPI", "1.0.0"));
api.setStatus(APIConstants.CREATED);
api.setContextTemplate("/websub");
api.setTransports(Constants.TRANSPORT_HTTP);
api.setEndpointSecured(false);
api.setUriTemplates(setAPIUriTemplates());
api.setType(APIConstants.APITransportType.WEBSUB.toString());
WebsubSubscriptionConfiguration webSubConfig = new WebsubSubscriptionConfiguration(false, "", "", "");
api.setWebsubSubscriptionConfiguration(webSubConfig);
Environment environment = new Environment();
environment.setType("production");
config = Mockito.mock(APIManagerConfiguration.class);
APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl(config);
ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(apiManagerConfigurationService);
String templatePath = System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator;
System.setProperty("carbon.home", templatePath);
APITemplateBuilderImpl apiTemplateBuilder = new APITemplateBuilderImpl(api, null, null);
String updatedTemplate = apiTemplateBuilder.getConfigStringForTemplate(environment);
Assert.assertFalse("The websub velocity template is not updated correctly", updatedTemplate.contains("generated_signature"));
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method deployAPIRevision.
/**
* Deploy a revision
*
* @param apiId UUID of the API
* @param revisionId Revision ID of the API
* @param messageContext message context object
* @return response with 200 status code
*/
@Override
public Response deployAPIRevision(String apiId, String revisionId, List<APIRevisionDeploymentDTO> apIRevisionDeploymentDTOList, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
// validate if api exists
APIInfo apiInfo = validateAPIExistence(apiId);
// validate API update operation permitted based on the LC state
validateAPIOperationsPerLC(apiInfo.getStatus().toString());
String organization = RestApiUtil.getValidatedOrganization(messageContext);
// validate whether the API is advertise only
APIDTO apiDto = getAPIByID(apiId, apiProvider, organization);
if (apiDto != null && apiDto.getAdvertiseInfo() != null && apiDto.getAdvertiseInfo().isAdvertised()) {
throw new APIManagementException("Deploying API Revisions is not supported for third party APIs: " + apiId);
}
Map<String, Environment> environments = APIUtil.getEnvironments(organization);
List<APIRevisionDeployment> apiRevisionDeployments = new ArrayList<>();
for (APIRevisionDeploymentDTO apiRevisionDeploymentDTO : apIRevisionDeploymentDTOList) {
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
apiRevisionDeployment.setRevisionUUID(revisionId);
String environment = apiRevisionDeploymentDTO.getName();
if (environments.get(environment) == null) {
RestApiUtil.handleBadRequest("Gateway environment not found: " + environment, log);
}
apiRevisionDeployment.setDeployment(environment);
apiRevisionDeployment.setVhost(apiRevisionDeploymentDTO.getVhost());
if (StringUtils.isEmpty(apiRevisionDeploymentDTO.getVhost())) {
// vhost is only required when deploying an revision, not required when un-deploying a revision
// since the same scheme 'APIRevisionDeployment' is used for deploy and undeploy, handle it here.
RestApiUtil.handleBadRequest("Required field 'vhost' not found in deployment", log);
}
apiRevisionDeployment.setDisplayOnDevportal(apiRevisionDeploymentDTO.isDisplayOnDevportal());
apiRevisionDeployments.add(apiRevisionDeployment);
}
apiProvider.deployAPIRevision(apiId, revisionId, apiRevisionDeployments, organization);
List<APIRevisionDeployment> apiRevisionDeploymentsResponse = apiProvider.getAPIRevisionsDeploymentList(apiId);
List<APIRevisionDeploymentDTO> apiRevisionDeploymentDTOS = new ArrayList<>();
for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeploymentsResponse) {
apiRevisionDeploymentDTOS.add(APIMappingUtil.fromAPIRevisionDeploymenttoDTO(apiRevisionDeployment));
}
Response.Status status = Response.Status.CREATED;
return Response.status(status).entity(apiRevisionDeploymentDTOS).build();
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class ImportUtils method importDependentAPIs.
/**
* This method imports dependent APIs of the API Product.
*
* @param path Location of the extracted folder of the API Product
* @param currentUser The current logged in user
* @param isDefaultProviderAllowed Decision to keep or replace the provider
* @param apiProvider API provider
* @param overwriteAPIs Whether to overwrite the APIs or not
* @param apiProductDto API Product DTO
* @param tokenScopes Scopes of the token
* @param organization Organization Identifier
* @return Modified API Product DTO with the correct API UUIDs
* @throws IOException If there is an error while reading an API file
* @throws APIImportExportException If there is an error in importing an API
* @throws APIManagementException If failed to get the API Provider of an API, or failed when
* checking the existence of an API
*/
private static APIProductDTO importDependentAPIs(String path, String currentUser, boolean isDefaultProviderAllowed, APIProvider apiProvider, boolean overwriteAPIs, Boolean rotateRevision, APIProductDTO apiProductDto, String[] tokenScopes, String organization) throws IOException, APIManagementException {
JsonObject dependentAPIParamsConfigObject = null;
// Retrieve the dependent APIs param configurations from the params file of the API Product
JsonObject dependentAPIsParams = APIControllerUtil.getDependentAPIsParams(path);
String apisDirectoryPath = path + File.separator + ImportExportConstants.APIS_DIRECTORY;
File apisDirectory = new File(apisDirectoryPath);
File[] apisDirectoryListing = apisDirectory.listFiles();
if (apisDirectoryListing != null) {
for (File apiDirectory : apisDirectoryListing) {
String apiDirectoryPath = path + File.separator + ImportExportConstants.APIS_DIRECTORY + File.separator + apiDirectory.getName();
// API in the API directory will be retrieved if available
if (dependentAPIsParams != null) {
dependentAPIParamsConfigObject = APIControllerUtil.getDependentAPIParams(dependentAPIsParams, apiDirectory.getName());
// If the "certificates" directory is specified, copy it inside Deployment directory of the
// dependent API since there may be certificates required for APIs
String deploymentCertificatesDirectoryPath = path + ImportExportConstants.DEPLOYMENT_DIRECTORY + ImportExportConstants.CERTIFICATE_DIRECTORY;
if (CommonUtil.checkFileExistence(deploymentCertificatesDirectoryPath)) {
try {
CommonUtil.copyDirectory(deploymentCertificatesDirectoryPath, apiDirectoryPath + ImportExportConstants.DEPLOYMENT_DIRECTORY + ImportExportConstants.CERTIFICATE_DIRECTORY);
} catch (APIImportExportException e) {
throw new APIManagementException("Error while copying the directory " + deploymentCertificatesDirectoryPath, e);
}
}
}
JsonElement jsonObject = retrieveValidatedDTOObject(apiDirectoryPath, isDefaultProviderAllowed, currentUser, ImportExportConstants.TYPE_API);
APIDTO apiDtoToImport = new Gson().fromJson(jsonObject, APIDTO.class);
API importedApi = null;
String apiName = apiDtoToImport.getName();
String apiVersion = apiDtoToImport.getVersion();
if (isDefaultProviderAllowed) {
APIIdentifier apiIdentifier = new APIIdentifier(APIUtil.replaceEmailDomain(apiDtoToImport.getProvider()), apiName, apiVersion);
// Checking whether the API exists
if (apiProvider.isAPIAvailable(apiIdentifier, organization)) {
// otherwise do not update the API. (Just skip it)
if (Boolean.TRUE.equals(overwriteAPIs)) {
importedApi = importApi(apiDirectoryPath, apiDtoToImport, isDefaultProviderAllowed, rotateRevision, Boolean.TRUE, Boolean.TRUE, tokenScopes, dependentAPIParamsConfigObject, organization);
}
} else {
// If the API is not already imported, import it
importedApi = importApi(apiDirectoryPath, apiDtoToImport, isDefaultProviderAllowed, rotateRevision, Boolean.FALSE, Boolean.TRUE, tokenScopes, dependentAPIParamsConfigObject, organization);
}
} else {
// Retrieve the current tenant domain of the logged in user
String currentTenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(currentUser));
// Get the provider of the API if the API is in current user's tenant domain.
String apiProviderInCurrentTenantDomain = APIUtil.getAPIProviderFromAPINameVersionTenant(apiName, apiVersion, currentTenantDomain);
if (StringUtils.isBlank(apiProviderInCurrentTenantDomain)) {
// If there is no API in the current tenant domain (which means the provider name is blank)
// then the API should be imported freshly
importedApi = importApi(apiDirectoryPath, apiDtoToImport, isDefaultProviderAllowed, rotateRevision, Boolean.FALSE, Boolean.TRUE, tokenScopes, dependentAPIParamsConfigObject, organization);
} else {
// otherwise do not import/update the API. (Just skip it)
if (Boolean.TRUE.equals(overwriteAPIs)) {
importedApi = importApi(apiDirectoryPath, apiDtoToImport, isDefaultProviderAllowed, rotateRevision, Boolean.TRUE, Boolean.TRUE, tokenScopes, dependentAPIParamsConfigObject, organization);
}
}
}
if (importedApi == null) {
// Retrieve the API from the environment (This happens when you have not specified
// the overwrite flag, so that we should retrieve the API from inside)
importedApi = retrieveApiToOverwrite(apiDtoToImport.getName(), apiDtoToImport.getVersion(), MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(currentUser)), apiProvider, Boolean.FALSE, organization);
}
updateApiUuidInApiProduct(apiProductDto, importedApi);
}
} else {
String msg = "No dependent APIs supplied. Continuing ...";
log.info(msg);
}
return apiProductDto;
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method undeployAPIRevision.
@Override
public Response undeployAPIRevision(String apiId, String revisionId, String revisionNum, Boolean allEnvironments, List<APIRevisionDeploymentDTO> apIRevisionDeploymentDTOList, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
// validate if api exists
APIInfo apiInfo = validateAPIExistence(apiId);
// validate API update operation permitted based on the LC state
validateAPIOperationsPerLC(apiInfo.getStatus().toString());
String organization = RestApiUtil.getValidatedOrganization(messageContext);
if (revisionId == null && revisionNum != null) {
revisionId = apiProvider.getAPIRevisionUUID(revisionNum, apiId);
if (revisionId == null) {
return Response.status(Response.Status.BAD_REQUEST).entity(null).build();
}
}
Map<String, Environment> environments = APIUtil.getEnvironments(organization);
List<APIRevisionDeployment> apiRevisionDeployments = new ArrayList<>();
if (allEnvironments) {
apiRevisionDeployments = apiProvider.getAPIRevisionDeploymentList(revisionId);
} else {
for (APIRevisionDeploymentDTO apiRevisionDeploymentDTO : apIRevisionDeploymentDTOList) {
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
apiRevisionDeployment.setRevisionUUID(revisionId);
String environment = apiRevisionDeploymentDTO.getName();
if (environments.get(environment) == null) {
RestApiUtil.handleBadRequest("Gateway environment not found: " + environment, log);
}
apiRevisionDeployment.setDeployment(environment);
apiRevisionDeployment.setVhost(apiRevisionDeploymentDTO.getVhost());
apiRevisionDeployment.setDisplayOnDevportal(apiRevisionDeploymentDTO.isDisplayOnDevportal());
apiRevisionDeployments.add(apiRevisionDeployment);
}
}
apiProvider.undeployAPIRevisionDeployment(apiId, revisionId, apiRevisionDeployments, organization);
List<APIRevisionDeployment> apiRevisionDeploymentsResponse = apiProvider.getAPIRevisionDeploymentList(revisionId);
List<APIRevisionDeploymentDTO> apiRevisionDeploymentDTOS = new ArrayList<>();
for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeploymentsResponse) {
apiRevisionDeploymentDTOS.add(APIMappingUtil.fromAPIRevisionDeploymenttoDTO(apiRevisionDeployment));
}
Response.Status status = Response.Status.CREATED;
return Response.status(status).entity(apiRevisionDeploymentDTOS).build();
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class APIMappingUtil method fromAPIRevisionListToEndpointsList.
public static List<APIEndpointURLsDTO> fromAPIRevisionListToEndpointsList(APIDTO apidto, String organization) throws APIManagementException {
Map<String, Environment> environments = APIUtil.getEnvironments(organization);
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
List<APIRevisionDeployment> revisionDeployments = apiConsumer.getAPIRevisionDeploymentListOfAPI(apidto.getId());
// custom gateway URL of tenant
Map<String, String> domains = new HashMap<>();
if (organization != null) {
domains = apiConsumer.getTenantDomainMappings(organization, APIConstants.API_DOMAIN_MAPPINGS_GATEWAY);
}
String customGatewayUrl = domains.get(APIConstants.CUSTOM_URL);
List<APIEndpointURLsDTO> endpointUrls = new ArrayList<>();
for (APIRevisionDeployment revisionDeployment : revisionDeployments) {
if (revisionDeployment.isDisplayOnDevportal()) {
// Deployed environment
Environment environment = environments.get(revisionDeployment.getDeployment());
if (environment != null) {
APIEndpointURLsDTO apiEndpointURLsDTO = fromAPIRevisionToEndpoints(apidto, environment, revisionDeployment.getVhost(), customGatewayUrl, organization);
endpointUrls.add(apiEndpointURLsDTO);
}
}
}
return endpointUrls;
}
Aggregations