use of com.yahoo.athenz.zms.SignedDomains in project athenz by yahoo.
the class DataStoreTest method testProcessDomainUpdatesFromZMSNoTagHeader.
@Test
public void testProcessDomainUpdatesFromZMSNoTagHeader() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
((MockZMSFileChangeLogStore) store.changeLogStore).setTagHeader(null);
SignedDomain signedDomain = createSignedDomain("coretech", "weather");
List<SignedDomain> domains = new ArrayList<>();
domains.add(signedDomain);
SignedDomains signedDomains = new SignedDomains();
signedDomains.setDomains(domains);
((MockZMSFileChangeLogStore) store.changeLogStore).setSignedDomains(signedDomains);
boolean result = store.processDomainUpdates();
assertFalse(result);
}
use of com.yahoo.athenz.zms.SignedDomains in project athenz by yahoo.
the class S3ChangeLogStoreTest method testGetUpdatedSignedDomainsNoChanges.
@Test
public void testGetUpdatedSignedDomainsNoChanges() {
MockS3ChangeLogStore store = new MockS3ChangeLogStore();
ArrayList<S3ObjectSummary> objectList = new ArrayList<>();
S3ObjectSummary objectSummary = new S3ObjectSummary();
objectSummary.setKey("iaas");
objectSummary.setLastModified(new Date(100));
objectList.add(objectSummary);
objectSummary = new S3ObjectSummary();
objectSummary.setKey("iaas.athenz");
objectSummary.setLastModified(new Date(200));
objectList.add(objectSummary);
ObjectListing objectListing = mock(ObjectListing.class);
when(objectListing.getObjectSummaries()).thenReturn(objectList);
when(objectListing.isTruncated()).thenReturn(false);
when(store.awsS3Client.listObjects(any(ListObjectsRequest.class))).thenReturn(objectListing);
// set the last modification time to not return any of the domains
store.lastModTime = (new Date(250)).getTime();
StringBuilder lastModTimeBuffer = new StringBuilder(512);
SignedDomains signedDomains = store.getUpdatedSignedDomains(lastModTimeBuffer);
assertTrue(lastModTimeBuffer.length() > 0);
assertEquals(signedDomains.getDomains().size(), 0);
}
use of com.yahoo.athenz.zms.SignedDomains in project athenz by yahoo.
the class S3ChangeLogStoreTest method testGetUpdatedSignedDomainsWithChange.
@Test
public void testGetUpdatedSignedDomainsWithChange() throws IOException {
MockS3ChangeLogStore store = new MockS3ChangeLogStore();
ArrayList<S3ObjectSummary> objectList = new ArrayList<>();
S3ObjectSummary objectSummary = new S3ObjectSummary();
objectSummary.setKey("iaas");
objectSummary.setLastModified(new Date(100));
objectList.add(objectSummary);
objectSummary = new S3ObjectSummary();
objectSummary.setKey("iaas.athenz");
objectSummary.setLastModified(new Date(200));
objectList.add(objectSummary);
// we'll also include an invalid domain that should be skipped
objectSummary = new S3ObjectSummary();
objectSummary.setKey("unknown");
objectSummary.setLastModified(new Date(200));
objectList.add(objectSummary);
ObjectListing objectListing = mock(ObjectListing.class);
when(objectListing.getObjectSummaries()).thenReturn(objectList);
when(objectListing.isTruncated()).thenReturn(false);
when(store.awsS3Client.listObjects(any(ListObjectsRequest.class))).thenReturn(objectListing);
InputStream is = new FileInputStream("src/test/resources/iaas.json");
MockS3ObjectInputStream s3Is = new MockS3ObjectInputStream(is, null);
S3Object object = mock(S3Object.class);
when(object.getObjectContent()).thenReturn(s3Is);
when(store.awsS3Client.getObject("s3-unit-test-bucket-name", "iaas")).thenReturn(object);
when(store.awsS3Client.getObject("s3-unit-test-bucket-name", "iaas.athenz")).thenReturn(object);
// set the last modification time to return one of the domains
store.lastModTime = (new Date(150)).getTime();
StringBuilder lastModTimeBuffer = new StringBuilder(512);
SignedDomains signedDomains = store.getUpdatedSignedDomains(lastModTimeBuffer);
assertTrue(lastModTimeBuffer.length() > 0);
List<SignedDomain> domainList = signedDomains.getDomains();
assertEquals(domainList.size(), 1);
DomainData domainData = domainList.get(0).getDomain();
assertNotNull(domainData);
assertEquals(domainData.getName(), "iaas");
is.close();
}
use of com.yahoo.athenz.zms.SignedDomains in project athenz by yahoo.
the class S3ChangeLogStore method getUpdatedSignedDomains.
@Override
public SignedDomains getUpdatedSignedDomains(StringBuilder lastModTimeBuffer) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("getUpdatedSignedDomains: Retrieving updating signed domains from S3...");
}
// We need save the timestamp at the beginning just in case we end up getting
// paged results and while processing the last page, S3 gets pushed
// updated domains from the earlier pages
lastModTimeBuffer.append(System.currentTimeMillis());
// AWS S3 API does not provide support for listing objects filtered
// based on its last modification timestamp so we need to get
// the full list and filter ourselves
// instead of using our fetched s3 client, we're going to
// obtain a new one to get the changes
AmazonS3 s3 = getS3Client();
ArrayList<String> domains = new ArrayList<>();
listObjects(s3, domains, lastModTime);
if (LOGGER.isInfoEnabled()) {
LOGGER.info("getUpdatedSignedDomains: {} updated domains", domains.size());
}
ArrayList<SignedDomain> signedDomainList = new ArrayList<>();
SignedDomain signedDomain = null;
for (String domain : domains) {
signedDomain = getSignedDomain(s3, domain);
if (signedDomain != null) {
signedDomainList.add(signedDomain);
}
}
SignedDomains signedDomains = new SignedDomains();
signedDomains.setDomains(signedDomainList);
return signedDomains;
}
use of com.yahoo.athenz.zms.SignedDomains 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;
}
Aggregations