Search in sources :

Example 26 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class ZMSFileChangeLogStoreTest method testGetLocalDomainListMultiple.

@Test
public void testGetLocalDomainListMultiple() {
    ZMSFileChangeLogStore fstore = new ZMSFileChangeLogStore(FSTORE_PATH, null, null);
    ZMSFileChangeLogStoreCommon cstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    Struct data = new Struct();
    data.put("key", "val1");
    cstore.put("test1", JSON.bytes(data));
    data = new Struct();
    data.put("key", "val1");
    cstore.put("test2", JSON.bytes(data));
    data = new Struct();
    data.put("key", "val1");
    cstore.put("test3", JSON.bytes(data));
    List<String> ls = fstore.getLocalDomainList();
    assertEquals(ls.size(), 3);
    assertTrue(ls.contains("test1"));
    assertTrue(ls.contains("test2"));
    assertTrue(ls.contains("test3"));
}
Also used : Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 27 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class CloudStore method getSshKeyReqType.

String getSshKeyReqType(String sshKeyReq) {
    Struct keyReq = JSON.fromString(sshKeyReq, Struct.class);
    if (keyReq == null) {
        LOGGER.error("getSshKeyReqType: Unable to parse ssh key req: {}", sshKeyReq);
        return null;
    }
    String sshType = keyReq.getString(ZTSConsts.ZTS_SSH_TYPE);
    if (sshType == null) {
        LOGGER.error("getSshKeyReqType: SSH Key request does not have certtype: {}", sshKeyReq);
    }
    return sshType;
}
Also used : Struct(com.yahoo.rdl.Struct)

Example 28 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class CloudStore method fetchRoleCredentials.

boolean fetchRoleCredentials() {
    if (awsRole == null || awsRole.isEmpty()) {
        LOGGER.error("CloudStore: awsRole is not available to fetch role credentials");
        return false;
    }
    final String creds = getMetaData("/meta-data/iam/security-credentials/" + awsRole);
    if (creds == null) {
        return false;
    }
    Struct credsStruct = JSON.fromString(creds, Struct.class);
    if (credsStruct == null) {
        LOGGER.error("CloudStore: unable to parse role credentials data: {}", creds);
        return false;
    }
    String accessKeyId = credsStruct.getString("AccessKeyId");
    String secretAccessKey = credsStruct.getString("SecretAccessKey");
    String token = credsStruct.getString("Token");
    credentials = new BasicSessionCredentials(accessKeyId, secretAccessKey, token);
    return true;
}
Also used : BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) Struct(com.yahoo.rdl.Struct)

Example 29 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class DBServiceTest method testExecutePutEntityUpdate.

@Test
public void testExecutePutEntityUpdate() {
    String domainName = "createentitydom1-mod";
    String entityName = "entity1";
    TopLevelDomain dom1 = createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", adminUser);
    zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1);
    Entity entity1 = createEntityObject(domainName, entityName);
    zms.dbService.executePutEntity(mockDomRsrcCtx, domainName, entityName, entity1, auditRef, "putEntity");
    Struct value = new Struct();
    value.put("Key2", "Value2");
    entity1.setValue(value);
    zms.dbService.executePutEntity(mockDomRsrcCtx, domainName, entityName, entity1, auditRef, "putEntity");
    Entity entity2 = zms.getEntity(mockDomRsrcCtx, domainName, entityName);
    assertNotNull(entity2);
    assertEquals(entity2.getName(), ResourceUtils.entityResourceName(domainName, entityName));
    value = entity2.getValue();
    assertEquals("Value2", value.getString("Key2"));
    zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef);
}
Also used : Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 30 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class InstanceAWSProvider method validateAWSDocument.

boolean validateAWSDocument(final String provider, AWSAttestationData info, final String awsAccount, final String instanceId, StringBuilder errMsg) {
    final String document = info.getDocument();
    if (!validateAWSSignature(document, info.getSignature(), errMsg)) {
        return false;
    }
    // convert our document into a struct that we can extract data
    Struct instanceDocument = JSON.fromString(document, Struct.class);
    if (instanceDocument == null) {
        errMsg.append("Unable to parse identity document");
        LOGGER.error("Identity Document: {}", document);
        return false;
    }
    if (!validateAWSProvider(provider, instanceDocument.getString(ATTR_REGION), errMsg)) {
        return false;
    }
    if (!validateAWSAccount(awsAccount, instanceDocument.getString(ATTR_ACCOUNT_ID), errMsg)) {
        return false;
    }
    // verify the request has the expected account id
    final String infoInstanceId = getInstanceId(info, instanceDocument);
    if (!validateAWSInstanceId(instanceId, infoInstanceId, errMsg)) {
        return false;
    }
    if (!validateInstanceBootTime(instanceDocument, errMsg)) {
        return false;
    }
    return true;
}
Also used : Struct(com.yahoo.rdl.Struct)

Aggregations

Struct (com.yahoo.rdl.Struct)61 Test (org.testng.annotations.Test)30 Array (com.yahoo.rdl.Array)10 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)7 AuthzDetailsEntity (com.yahoo.athenz.common.config.AuthzDetailsEntity)5 Path (java.nio.file.Path)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Assertion (com.yahoo.athenz.zms.Assertion)3 Policy (com.yahoo.athenz.zms.Policy)3 ZpeMatch (com.yahoo.athenz.zpe.match.ZpeMatch)3 File (java.io.File)3 AuthzDetailsField (com.yahoo.athenz.common.config.AuthzDetailsField)2 FilesHelper (com.yahoo.athenz.common.server.util.FilesHelper)2 PublicKeyEntry (com.yahoo.athenz.zms.PublicKeyEntry)2 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 AthenzConfig (com.yahoo.athenz.common.config.AthenzConfig)1