Search in sources :

Example 6 with SignedDomains

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);
}
Also used : ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) SignedDomain(com.yahoo.athenz.zms.SignedDomain) ArrayList(java.util.ArrayList) SignedDomains(com.yahoo.athenz.zms.SignedDomains) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) Test(org.testng.annotations.Test)

Example 7 with SignedDomains

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);
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) SignedDomains(com.yahoo.athenz.zms.SignedDomains) Test(org.testng.annotations.Test)

Example 8 with SignedDomains

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();
}
Also used : S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) DomainData(com.yahoo.athenz.zms.DomainData) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) SignedDomains(com.yahoo.athenz.zms.SignedDomains) ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) SignedDomain(com.yahoo.athenz.zms.SignedDomain) S3Object(com.amazonaws.services.s3.model.S3Object) Test(org.testng.annotations.Test)

Example 9 with SignedDomains

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;
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) ArrayList(java.util.ArrayList) SignedDomain(com.yahoo.athenz.zms.SignedDomain) SignedDomains(com.yahoo.athenz.zms.SignedDomains)

Example 10 with 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;
}
Also used : SignedDomain(com.yahoo.athenz.zms.SignedDomain) ArrayList(java.util.ArrayList) SignedDomains(com.yahoo.athenz.zms.SignedDomains) ZMSClientException(com.yahoo.athenz.zms.ZMSClientException)

Aggregations

SignedDomains (com.yahoo.athenz.zms.SignedDomains)13 SignedDomain (com.yahoo.athenz.zms.SignedDomain)10 ArrayList (java.util.ArrayList)9 Test (org.testng.annotations.Test)8 ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)4 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)4 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)4 DomainData (com.yahoo.athenz.zms.DomainData)4 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)4 ZMSClient (com.yahoo.athenz.zms.ZMSClient)3 AmazonS3 (com.amazonaws.services.s3.AmazonS3)2 S3Object (com.amazonaws.services.s3.model.S3Object)2 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)2 ZMSClientException (com.yahoo.athenz.zms.ZMSClientException)2 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)2 Date (java.util.Date)2 Role (com.yahoo.athenz.zms.Role)1 RoleMember (com.yahoo.athenz.zms.RoleMember)1 DataCache (com.yahoo.athenz.zts.cache.DataCache)1 MemberRole (com.yahoo.athenz.zts.cache.MemberRole)1