Search in sources :

Example 1 with ZMSClientException

use of com.yahoo.athenz.zms.ZMSClientException in project athenz by yahoo.

the class ZMSFileChangeLogStore method getUpdatedSignedDomains.

@Override
public SignedDomains getUpdatedSignedDomains(StringBuilder lastModTimeBuffer) {
    try (ZMSClient zmsClient = getZMSClient()) {
        // request all the changes from ZMS. In this call we're asking for
        // meta data only so we'll only get the list of domains
        Map<String, List<String>> responseHeaders = new HashMap<String, List<String>>();
        SignedDomains domainList = zmsClient.getSignedDomains(null, VALUE_TRUE, lastModTime, responseHeaders);
        // retrieve the tag value for the request
        String newLastModTime = retrieveTagHeader(responseHeaders);
        if (newLastModTime == null) {
            return null;
        }
        // set the last modification time to be returned to the caller
        lastModTimeBuffer.setLength(0);
        lastModTimeBuffer.append(newLastModTime);
        if (domainList == null || domainList.getDomains() == null) {
            return null;
        }
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("getUpdatedSignedDomains: {} updated domains", domainList.getDomains().size());
        }
        List<SignedDomain> domains = getSignedDomainList(zmsClient, domainList);
        return new SignedDomains().setDomains(domains);
    } catch (ZMSClientException ex) {
        LOGGER.error("Error when refreshing data from ZMS: {}", ex.getMessage());
        return null;
    }
}
Also used : HashMap(java.util.HashMap) SignedDomain(com.yahoo.athenz.zms.SignedDomain) ArrayList(java.util.ArrayList) List(java.util.List) SignedDomains(com.yahoo.athenz.zms.SignedDomains) ZMSClient(com.yahoo.athenz.zms.ZMSClient) ZMSClientException(com.yahoo.athenz.zms.ZMSClientException)

Example 2 with ZMSClientException

use of com.yahoo.athenz.zms.ZMSClientException in project athenz by yahoo.

the class ZMSFileChangeLogStore method getSignedDomainList.

List<SignedDomain> getSignedDomainList(ZMSClient zmsClient, SignedDomains domainList) {
    List<SignedDomain> domains = new ArrayList<>();
    for (SignedDomain domain : domainList.getDomains()) {
        final String domainName = domain.getDomain().getName();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("getSignedDomainList: fetching domain {}", domainName);
        }
        try {
            SignedDomains singleDomain = zmsClient.getSignedDomains(domainName, null, null, null);
            if (singleDomain == null || singleDomain.getDomains().isEmpty()) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("getSignedDomainList: unable to fetch domain {}", domainName);
                }
                continue;
            }
            domains.addAll(singleDomain.getDomains());
        } catch (ZMSClientException ex) {
            LOGGER.error("Error fetching domain {} from ZMS: {}", domainName, ex.getMessage());
        }
    }
    return domains;
}
Also used : SignedDomain(com.yahoo.athenz.zms.SignedDomain) ArrayList(java.util.ArrayList) SignedDomains(com.yahoo.athenz.zms.SignedDomains) ZMSClientException(com.yahoo.athenz.zms.ZMSClientException)

Example 3 with ZMSClientException

use of com.yahoo.athenz.zms.ZMSClientException in project athenz by yahoo.

the class ZMSTLSClient method main.

public static void main(String[] args) {
    // parse our command line to retrieve required input
    CommandLine cmd = parseCommandLine(args);
    final String resource = cmd.getOptionValue("resource").toLowerCase();
    final String action = cmd.getOptionValue("action").toLowerCase();
    final String principal = cmd.getOptionValue("principal").toLowerCase();
    final String zmsUrl = cmd.getOptionValue("zmsurl");
    final String keyPath = cmd.getOptionValue("key");
    final String certPath = cmd.getOptionValue("cert");
    final String trustStorePath = cmd.getOptionValue("trustStorePath");
    final String trustStorePassword = cmd.getOptionValue("trustStorePassword");
    try {
        KeyRefresher keyRefresher = Utils.generateKeyRefresher(trustStorePath, trustStorePassword, certPath, keyPath);
        SSLContext sslContext = Utils.buildSSLContext(keyRefresher.getKeyManagerProxy(), keyRefresher.getTrustManagerProxy());
        try (ZMSClient zmsClient = new ZMSClient(zmsUrl, sslContext)) {
            try {
                Access access = zmsClient.getAccess(action, resource, null, principal);
                System.out.println("Access: " + access.getGranted());
            } catch (ZMSClientException ex) {
                System.out.println("Unable to carry out access check: " + ex.getMessage());
                System.exit(2);
            }
        }
    } catch (Exception ex) {
        System.out.println("Exception: " + ex.getMessage());
        ex.printStackTrace();
        System.exit(1);
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) Access(com.yahoo.athenz.zms.Access) SSLContext(javax.net.ssl.SSLContext) ZMSClient(com.yahoo.athenz.zms.ZMSClient) KeyRefresher(com.oath.auth.KeyRefresher) ZMSClientException(com.yahoo.athenz.zms.ZMSClientException) ParseException(org.apache.commons.cli.ParseException) ZMSClientException(com.yahoo.athenz.zms.ZMSClientException)

Example 4 with ZMSClientException

use of com.yahoo.athenz.zms.ZMSClientException in project athenz by yahoo.

the class MockZMSFileChangeLogStore method setDomainList.

public void setDomainList(List<String> domains) {
    if (domains != null) {
        domList = new DomainList();
        domList.setNames(domains);
        when(zms.getDomainList()).thenReturn(domList);
    } else {
        when(zms.getDomainList()).thenThrow(new ZMSClientException(500, "Invalid request"));
    }
}
Also used : DomainList(com.yahoo.athenz.zms.DomainList) ZMSClientException(com.yahoo.athenz.zms.ZMSClientException)

Aggregations

ZMSClientException (com.yahoo.athenz.zms.ZMSClientException)4 SignedDomain (com.yahoo.athenz.zms.SignedDomain)2 SignedDomains (com.yahoo.athenz.zms.SignedDomains)2 ZMSClient (com.yahoo.athenz.zms.ZMSClient)2 ArrayList (java.util.ArrayList)2 KeyRefresher (com.oath.auth.KeyRefresher)1 Access (com.yahoo.athenz.zms.Access)1 DomainList (com.yahoo.athenz.zms.DomainList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 SSLContext (javax.net.ssl.SSLContext)1 CommandLine (org.apache.commons.cli.CommandLine)1 ParseException (org.apache.commons.cli.ParseException)1