use of com.yahoo.athenz.instance.provider.InstanceProvider in project athenz by yahoo.
the class InstanceProviderManagerTest method testGetProviderClientInvalidEndpointParse.
@Test
public void testGetProviderClientInvalidEndpointParse() {
SignedDomain signedDomain = createSignedDomain("coretech", "weather", true, true, "://test.athenz.com/");
store.processDomain(signedDomain, false);
InstanceProviderManager provider = new InstanceProviderManager(store, null);
InstanceProvider client = provider.getProvider("coretech.weather");
assertNull(client);
}
use of com.yahoo.athenz.instance.provider.InstanceProvider in project athenz by yahoo.
the class InstanceProviderManagerTest method testGetClassInstance.
@Test
public void testGetClassInstance() {
InstanceProviderManager providerManager = new InstanceProviderManager(null, null);
InstanceProvider provider = providerManager.getClassProvider("unknown.class", "provider");
assertNull(provider);
provider = providerManager.getClassProvider("com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", "provider");
assertNotNull(provider);
// we should get this from the cache now
provider = providerManager.getClassProvider("com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", "provider");
assertNotNull(provider);
// some invalid class name
provider = providerManager.getClassProvider("com.yahoo.athenz.unknown.class", "provider");
assertNull(provider);
try {
providerManager.getClassProvider("com.yahoo.athenz.zts.ZTSConsts", "provider");
fail();
} catch (Exception ex) {
}
}
use of com.yahoo.athenz.instance.provider.InstanceProvider in project athenz by yahoo.
the class InstanceProviderManagerTest method testGetProviderClientInvalidEndpoint.
@Test
public void testGetProviderClientInvalidEndpoint() {
SignedDomain signedDomain = createSignedDomain("coretech", "weather", true, true, "http://invalid");
store.processDomain(signedDomain, false);
InstanceProviderManager provider = new InstanceProviderManager(store, null);
InstanceProvider client = provider.getProvider("coretech.weather");
assertNull(client);
}
use of com.yahoo.athenz.instance.provider.InstanceProvider in project athenz by yahoo.
the class InstanceProviderManagerTest method testGetProviderClientNoServices.
@Test
public void testGetProviderClientNoServices() {
SignedDomain signedDomain = createSignedDomainHttpsEndpoint("coretech", "weather", false, true);
store.processDomain(signedDomain, false);
InstanceProviderManager provider = new InstanceProviderManager(store, null);
InstanceProvider client = provider.getProvider("coretech.weather");
assertNull(client);
}
use of com.yahoo.athenz.instance.provider.InstanceProvider in project athenz by yahoo.
the class InstanceProviderManager method getProvider.
public InstanceProvider getProvider(String provider) {
int idx = provider.lastIndexOf('.');
if (idx == -1) {
LOGGER.error("getProviderClient: Invalid provider service name: {}", provider);
return null;
}
final String domainName = provider.substring(0, idx);
DataCache dataCache = dataStore.getDataCache(domainName);
if (dataCache == null) {
LOGGER.error("getProviderClient: Unknown domain: {}", domainName);
return null;
}
String providerEndpoint = null;
boolean validProviderName = false;
List<com.yahoo.athenz.zms.ServiceIdentity> services = dataCache.getDomainData().getServices();
if (services == null) {
LOGGER.error("getProviderClient: Unknown provider servicee: {}", provider);
return null;
}
for (com.yahoo.athenz.zms.ServiceIdentity service : services) {
if (service.getName().equals(provider)) {
providerEndpoint = service.getProviderEndpoint();
validProviderName = true;
break;
}
}
if (providerEndpoint == null || providerEndpoint.isEmpty()) {
if (validProviderName) {
LOGGER.error("getProviderClient: Unknown provider service name: {}", provider);
} else {
LOGGER.error("getProviderClient: Provider service {} does not have endpoint defined", provider);
}
return null;
}
// before using our endpoint we need to make sure
// it's valid according to configuration settings
InstanceProvider instanceProvider = null;
URI uri = null;
try {
uri = new URI(providerEndpoint);
} catch (URISyntaxException ex) {
LOGGER.error("getProviderClient: Unable to parse {}: {}", providerEndpoint, ex.getMessage());
return null;
}
ProviderScheme schemeType = getProviderEndpointScheme(uri);
switch(schemeType) {
case HTTPS:
instanceProvider = new InstanceHttpProvider();
instanceProvider.initialize(provider, providerEndpoint, keyStore);
break;
case CLASS:
instanceProvider = getClassProvider(uri.getHost(), provider);
break;
default:
break;
}
return instanceProvider;
}
Aggregations