Search in sources :

Example 31 with InstanceProvider

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);
}
Also used : SignedDomain(com.yahoo.athenz.zms.SignedDomain) InstanceProviderManager(com.yahoo.athenz.zts.InstanceProviderManager) InstanceProvider(com.yahoo.athenz.instance.provider.InstanceProvider) Test(org.testng.annotations.Test)

Example 32 with InstanceProvider

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) {
    }
}
Also used : InstanceProviderManager(com.yahoo.athenz.zts.InstanceProviderManager) URISyntaxException(java.net.URISyntaxException) InstanceProvider(com.yahoo.athenz.instance.provider.InstanceProvider) Test(org.testng.annotations.Test)

Example 33 with InstanceProvider

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);
}
Also used : SignedDomain(com.yahoo.athenz.zms.SignedDomain) InstanceProviderManager(com.yahoo.athenz.zts.InstanceProviderManager) InstanceProvider(com.yahoo.athenz.instance.provider.InstanceProvider) Test(org.testng.annotations.Test)

Example 34 with InstanceProvider

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);
}
Also used : SignedDomain(com.yahoo.athenz.zms.SignedDomain) InstanceProviderManager(com.yahoo.athenz.zts.InstanceProviderManager) InstanceProvider(com.yahoo.athenz.instance.provider.InstanceProvider) Test(org.testng.annotations.Test)

Example 35 with InstanceProvider

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;
}
Also used : InstanceHttpProvider(com.yahoo.athenz.instance.provider.impl.InstanceHttpProvider) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) DataCache(com.yahoo.athenz.zts.cache.DataCache) InstanceProvider(com.yahoo.athenz.instance.provider.InstanceProvider)

Aggregations

InstanceProvider (com.yahoo.athenz.instance.provider.InstanceProvider)36 Test (org.testng.annotations.Test)32 SignedDomain (com.yahoo.athenz.zms.SignedDomain)31 ChangeLogStore (com.yahoo.athenz.zts.store.ChangeLogStore)21 DataStore (com.yahoo.athenz.zts.store.DataStore)21 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)21 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)21 Path (java.nio.file.Path)21 InstanceConfirmation (com.yahoo.athenz.instance.provider.InstanceConfirmation)20 InstanceCertManager (com.yahoo.athenz.zts.cert.InstanceCertManager)20 X509Certificate (java.security.cert.X509Certificate)16 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)15 CertificateAuthority (com.yahoo.athenz.auth.impl.CertificateAuthority)14 X509CertRecord (com.yahoo.athenz.zts.cert.X509CertRecord)14 InstanceProviderManager (com.yahoo.athenz.zts.InstanceProviderManager)11 WebApplicationException (javax.ws.rs.WebApplicationException)3 PrincipalToken (com.yahoo.athenz.auth.token.PrincipalToken)2 CryptoException (com.yahoo.athenz.auth.util.CryptoException)2 AuditLogMsgBuilder (com.yahoo.athenz.common.server.log.AuditLogMsgBuilder)2 X509CertRequest (com.yahoo.athenz.zts.cert.X509CertRequest)2