use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetes method listServices.
/**
* {@inheritDoc}
*/
@Override
public List<Endpoint> listServices(String namespace) throws ServiceDiscoveryException {
List<Endpoint> endpointList = new ArrayList<>();
if (client != null) {
log.debug("Looking for services in namespace {}", namespace);
try {
List<Service> serviceList = client.services().inNamespace(namespace).list().getItems();
addServicesToEndpointList(serviceList, endpointList);
} catch (KubernetesClientException | MalformedURLException e) {
String msg = "Error occurred while trying to list services using Kubernetes client";
throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_WHILE_TRYING_TO_DISCOVER_SERVICES);
}
}
return endpointList;
}
use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetes method listServices.
/**
* {@inheritDoc}
*/
@Override
public List<Endpoint> listServices(Map<String, String> criteria) throws ServiceDiscoveryException {
List<Endpoint> endpointList = new ArrayList<>();
if (client != null) {
log.debug("Looking for services, with the specified labels, in all namespaces");
try {
// namespace has to be set to null to check all allowed namespaces
List<Service> serviceList = client.services().inNamespace(null).withLabels(criteria).list().getItems();
addServicesToEndpointList(serviceList, endpointList);
} catch (KubernetesClientException | MalformedURLException e) {
String msg = "Error occurred while trying to list services using Kubernetes client";
throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_WHILE_TRYING_TO_DISCOVER_SERVICES);
} catch (NoSuchMethodError e) {
String msg = "Filtering criteria in the deployment yaml includes unwanted characters";
throw new ServiceDiscoveryException(msg, e, ExceptionCodes.ERROR_WHILE_TRYING_TO_DISCOVER_SERVICES);
}
}
return endpointList;
}
use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.
the class WSO2ISKeyManagerImpl method revokeAccessToken.
// TODO: Remove after revoke endpoint implementation done in key manager.
@Override
public void revokeAccessToken(String accessToken, String clientId, String clientSecret) throws KeyManagementException {
log.debug("Revoking access token");
Response response;
try {
response = oAuth2ServiceStubs.getRevokeServiceStub().revokeAccessToken(accessToken, clientId, clientSecret);
} catch (APIManagementException e) {
throw new KeyManagementException("Error occurred while revoking current access token", e, ExceptionCodes.ACCESS_TOKEN_REVOKE_FAILED);
}
if (response == null) {
throw new KeyManagementException("Error occurred while revoking current access token. " + "Response is null", ExceptionCodes.ACCESS_TOKEN_REVOKE_FAILED);
}
if (response.status() == APIMgtConstants.HTTPStatusCodes.SC_200_OK) {
if (log.isDebugEnabled()) {
log.debug("Successfully revoked access token: " + accessToken);
}
} else {
throw new KeyManagementException("Token revocation failed. HTTP error code: " + response.status() + " Error Response Body: " + response.body().toString(), ExceptionCodes.ACCESS_TOKEN_REVOKE_FAILED);
}
}
use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createUniqueAPI.
public static API.APIBuilder createUniqueAPI() {
Set<String> transport = new HashSet<>();
transport.add(HTTP);
Set<String> tags = new HashSet<>();
tags.add(TAG_FOOD);
tags.add(TAG_BEVERAGE);
Set<Policy> policies = new HashSet<>();
policies.add(silverSubscriptionPolicy);
policies.add(bronzeSubscriptionPolicy);
BusinessInformation businessInformation = new BusinessInformation();
businessInformation.setBusinessOwner(NAME_BUSINESS_OWNER_1);
businessInformation.setBusinessOwnerEmail(EMAIL_BUSINESS_OWNER_1);
businessInformation.setTechnicalOwner(NAME_BUSINESS_OWNER_2);
businessInformation.setBusinessOwnerEmail(EMAIL_BUSINESS_OWNER_2);
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setEnabled(true);
corsConfiguration.setAllowMethods(Arrays.asList(APIMgtConstants.FunctionsConstants.GET, APIMgtConstants.FunctionsConstants.POST, APIMgtConstants.FunctionsConstants.DELETE));
corsConfiguration.setAllowHeaders(Arrays.asList(ALLOWED_HEADER_AUTHORIZATION, ALLOWED_HEADER_CUSTOM));
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setAllowOrigins(Arrays.asList("*"));
String permissionJson = "[{\"groupId\" : \"developer\", \"permission\" : " + "[\"READ\",\"UPDATE\"]},{\"groupId\" : \"admin\", \"permission\" : [\"READ\",\"UPDATE\"," + "\"DELETE\", \"MANAGE_SUBSCRIPTION\"]}]";
Map permissionMap = new HashMap();
permissionMap.put(DEVELOPER_ROLE_ID, 6);
permissionMap.put(ADMIN_ROLE_ID, 15);
List<String> defaultLabels = getDefaultLabels();
API.APIBuilder apiBuilder = new API.APIBuilder(UUID.randomUUID().toString(), UUID.randomUUID().toString(), API_VERSION).id(UUID.randomUUID().toString()).context(UUID.randomUUID().toString()).description("Get Food & Beverage Info").lifeCycleStatus(APIStatus.CREATED.getStatus()).endpoint(Collections.emptyMap()).isResponseCachingEnabled(true).cacheTimeout(120).isDefaultVersion(true).apiPolicy(goldApiPolicy).transport(transport).tags(tags).labels(defaultLabels).policies(policies).visibility(API.Visibility.RESTRICTED).visibleRoles(new HashSet<>(Arrays.asList(CUSTOMER_ROLE, MANAGER_ROLE, EMPLOYEE_ROLE))).businessInformation(businessInformation).corsConfiguration(corsConfiguration).apiPermission(permissionJson).permissionMap(permissionMap).createdTime(LocalDateTime.now()).createdBy(API_CREATOR).uriTemplates(Collections.emptyMap()).apiDefinition(apiDefinition).lastUpdatedTime(LocalDateTime.now()).securityScheme(3).threatProtectionPolicies(threatProtectionPolicies);
return apiBuilder;
}
use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testAddEndPointsForApi.
@Test(description = "Test adding API with endpointMap")
public void testAddEndPointsForApi() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
Map<String, Endpoint> endpointMap = new HashMap<>();
endpointMap.put(APIMgtConstants.PRODUCTION_ENDPOINT, new Endpoint.Builder().id(SampleTestObjectCreator.endpointId).applicableLevel(APIMgtConstants.GLOBAL_ENDPOINT).build());
API api = SampleTestObjectCreator.createDefaultAPI().endpoint(endpointMap).build();
testAddGetEndpoint();
apiDAO.addAPI(api);
API apiFromDB = apiDAO.getAPI(api.getId());
Assert.assertNotNull(apiFromDB);
Assert.assertTrue(api.equals(apiFromDB), TestUtil.printDiff(api, apiFromDB));
}
Aggregations