use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testListServicesWithBothNamespaceAndCriteria.
@Test(description = "Test .listServices(Namespace, Criteria) method")
public void testListServicesWithBothNamespaceAndCriteria() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
sdKubernetes.setClient(openShiftClient);
// Include ClusterIPs
sdKubernetes.setIncludeClusterIP(true);
// Include ExternalNames
sdKubernetes.setIncludeExternalNameTypeServices(true);
Map<String, String> oneLabel = createOneLabelHashMap();
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
BaseOperation baseOperation = Mockito.mock(BaseOperation.class);
Mockito.when(openShiftClient.services().inNamespace("dev")).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.withLabels(oneLabel)).thenReturn(baseOperation);
Mockito.when(baseOperation.list()).thenReturn(createServiceListWithBothNamespaceAndCriteria());
List<Endpoint> endpoints = sdKubernetes.listServices("dev", oneLabel);
Assert.assertEquals(endpoints.size(), 2);
}
use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testListServicesWithoutCLusterIPAndExternalName.
@Test(description = "Test .listServices() method without ClusterIPs and ExternalNamesURLs")
public void testListServicesWithoutCLusterIPAndExternalName() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
sdKubernetes.setClient(openShiftClient);
// Not include ClusterIPs
sdKubernetes.setIncludeClusterIP(false);
// Not include ExternalNames
sdKubernetes.setIncludeExternalNameTypeServices(false);
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
Mockito.when(openShiftClient.services().inNamespace(null)).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.list()).thenReturn(createServiceList());
Mockito.when(openShiftClient.getMasterUrl()).thenReturn(new URL(MASTER_URL));
List<Endpoint> endpoints = sdKubernetes.listServices();
Assert.assertEquals(endpoints.size(), 5);
Mockito.verify(openShiftClient, Mockito.times(2)).getMasterUrl();
}
use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.
the class ServiceDiscovererKubernetesTestCase method testListServicesWithNamespace.
@Test(description = "Test .listServices(Namespace) method")
public void testListServicesWithNamespace() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
sdKubernetes.setClient(openShiftClient);
// Not include ClusterIPs
sdKubernetes.setIncludeClusterIP(false);
// Include ExternalNames
sdKubernetes.setIncludeExternalNameTypeServices(true);
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
Mockito.when(openShiftClient.services().inNamespace("dev")).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.list()).thenReturn(createServiceListWithNamespace());
Mockito.when(openShiftClient.getMasterUrl()).thenReturn(new URL(MASTER_URL));
List<Endpoint> endpoints = sdKubernetes.listServices("dev");
Assert.assertEquals(endpoints.size(), 4);
}
use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.
the class MappingUtil method toEndpointListDto.
/**
* Converts {@link Endpoint} list to {@link EndPointDTO} list
*
* @param endpointList {@link Endpoint} list
* @return EndPointDTO list
*/
public static List<EndPointDTO> toEndpointListDto(List<Endpoint> endpointList) {
List<EndPointDTO> endPointDTOList = new ArrayList<>();
endpointList.forEach(endpoint -> endPointDTOList.add(new EndPointDTO().endpointConfig(endpoint.getEndpointConfig()).id(endpoint.getId()).type(endpoint.getType()).name(endpoint.getName()).security(endpoint.getSecurity())));
return endPointDTOList;
}
use of org.wso2.carbon.apimgt.core.models.Endpoint in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processSecureSocketAnnotation.
/**
* Extract key-store/trust-store file location from endpoint.
*
* @param endpointName Endpoint name
* @param secureSocketKeyValues secureSocket annotation struct
* @return List of @{@link SecretModel} objects
*/
Set<SecretModel> processSecureSocketAnnotation(String endpointName, List<BLangRecordLiteral.BLangRecordKeyValue> secureSocketKeyValues) throws KubernetesPluginException {
Set<SecretModel> secrets = new HashSet<>();
String keyStoreFile = null;
String trustStoreFile = null;
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : secureSocketKeyValues) {
// extract file paths.
String key = keyValue.getKey().toString();
if ("keyStore".equals(key)) {
keyStoreFile = extractFilePath(keyValue);
} else if ("trustStore".equals(key)) {
trustStoreFile = extractFilePath(keyValue);
}
}
if (keyStoreFile != null && trustStoreFile != null) {
if (getMountPath(keyStoreFile).equals(getMountPath(trustStoreFile))) {
// trust-store and key-store mount to same path
String keyStoreContent = readSecretFile(keyStoreFile);
String trustStoreContent = readSecretFile(trustStoreFile);
SecretModel secretModel = new SecretModel();
secretModel.setName(getValidName(endpointName) + "-secure-socket");
secretModel.setMountPath(getMountPath(keyStoreFile));
Map<String, String> dataMap = new HashMap<>();
dataMap.put(String.valueOf(Paths.get(keyStoreFile).getFileName()), keyStoreContent);
dataMap.put(String.valueOf(Paths.get(trustStoreFile).getFileName()), trustStoreContent);
secretModel.setData(dataMap);
secrets.add(secretModel);
return secrets;
}
}
if (keyStoreFile != null) {
String keyStoreContent = readSecretFile(keyStoreFile);
SecretModel secretModel = new SecretModel();
secretModel.setName(getValidName(endpointName) + "-keystore");
secretModel.setMountPath(getMountPath(keyStoreFile));
Map<String, String> dataMap = new HashMap<>();
dataMap.put(String.valueOf(Paths.get(keyStoreFile).getFileName()), keyStoreContent);
secretModel.setData(dataMap);
secrets.add(secretModel);
}
if (trustStoreFile != null) {
String trustStoreContent = readSecretFile(trustStoreFile);
SecretModel secretModel = new SecretModel();
secretModel.setName(getValidName(endpointName) + "-truststore");
secretModel.setMountPath(getMountPath(trustStoreFile));
Map<String, String> dataMap = new HashMap<>();
dataMap.put(String.valueOf(Paths.get(trustStoreFile).getFileName()), trustStoreContent);
secretModel.setData(dataMap);
secrets.add(secretModel);
}
return secrets;
}
Aggregations