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;
}
}
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;
}
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);
}
}
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"));
}
}
Aggregations