use of com.yahoo.rdl.Struct in project athenz by yahoo.
the class SignUtils method asStruct.
private static Struct asStruct(DomainData domainData) {
// all of our fields are in canonical order based
// on their attribute name
Struct struct = new Struct();
appendObject(struct, ATTR_ACCOUNT, domainData.getAccount());
appendObject(struct, ATTR_AUDIT_ENABLED, domainData.getAuditEnabled());
appendObject(struct, ATTR_CERT_DNS_DOMAIN, domainData.getCertDnsDomain());
appendObject(struct, ATTR_ENABLED, domainData.getEnabled());
if (domainData.getGroups() != null && !domainData.getGroups().isEmpty()) {
Array structGroups = new Array();
for (Group group : domainData.getGroups()) {
structGroups.add(asStruct(group));
}
appendArray(struct, ATTR_GROUPS, structGroups);
}
appendObject(struct, ATTR_MEMBER_EXPIRY_DAYS, domainData.getMemberExpiryDays());
appendObject(struct, ATTR_MODIFIED, domainData.getModified());
appendObject(struct, ATTR_NAME, domainData.getName());
SignedPolicies signedPolicies = domainData.getPolicies();
if (signedPolicies != null) {
Struct structSignedPolicies = new Struct();
appendObject(structSignedPolicies, ATTR_CONTENTS, asStruct(signedPolicies.getContents()));
appendObject(structSignedPolicies, ATTR_KEYID, signedPolicies.getKeyId());
appendObject(struct, ATTR_POLICIES, structSignedPolicies);
appendObject(structSignedPolicies, ATTR_SIGNATURE, signedPolicies.getSignature());
}
appendObject(struct, ATTR_ROLE_CERT_EXPIRY_MINS, domainData.getRoleCertExpiryMins());
Array structRoles = new Array();
if (domainData.getRoles() != null) {
for (Role role : domainData.getRoles()) {
structRoles.add(asStruct(role));
}
}
appendArray(struct, ATTR_ROLES, structRoles);
Array structServices = new Array();
if (domainData.getServices() != null) {
for (ServiceIdentity service : domainData.getServices()) {
structServices.add(asStruct(service));
}
}
appendObject(struct, ATTR_SERVICE_CERT_EXPIRY_MINS, domainData.getServiceCertExpiryMins());
appendObject(struct, ATTR_SERVICE_EXPIRY_DAYS, domainData.getServiceExpiryDays());
appendArray(struct, ATTR_SERVICES, structServices);
appendObject(struct, ATTR_SIGN_ALGORITHM, domainData.getSignAlgorithm());
appendObject(struct, ATTR_TOKEN_EXPIRY_MINS, domainData.getTokenExpiryMins());
appendObject(struct, ATTR_YPMID, domainData.getYpmId());
return struct;
}
use of com.yahoo.rdl.Struct in project athenz by yahoo.
the class ZMSFileChangeLogStoreCommonTest method testDeleteExistent.
@Test
public void testDeleteExistent() {
ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
Struct data = new Struct();
data.put("key", "val1");
fstore.put("test1", JSON.bytes(data));
fstore.delete("test1");
Struct st = fstore.get("test1", Struct.class);
assertNull(st);
}
use of com.yahoo.rdl.Struct in project athenz by yahoo.
the class ZMSFileMTLSChangeLogStoreTest method testGetLocalDomainListHidden.
@Test
public void testGetLocalDomainListHidden() throws InterruptedException, IOException, KeyRefresherException {
ZMSFileMTLSChangeLogStore fstore = new ZMSFileMTLSChangeLogStore(FSTORE_PATH, keyPath, certPath, trustStorePath, trustStorePassword);
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(), 1);
assertTrue(ls.contains("test1"));
}
use of com.yahoo.rdl.Struct in project athenz by yahoo.
the class ZMSFileMTLSChangeLogStoreTest method testGetLocalDomainListSingle.
@Test
public void testGetLocalDomainListSingle() throws IOException, KeyRefresherException, InterruptedException {
File rootDir = new File(FSTORE_PATH);
// noinspection ResultOfMethodCallIgnored
rootDir.mkdirs();
Struct lastModStruct = new Struct();
lastModStruct.put("lastModTime", 1001);
File file = new File(FSTORE_PATH, ".lastModTime");
Path path = Paths.get(file.toURI());
Files.write(path, JSON.bytes(lastModStruct));
ZMSFileMTLSChangeLogStore fstore = new ZMSFileMTLSChangeLogStore(FSTORE_PATH, keyPath, certPath, trustStorePath, trustStorePassword);
ZMSFileChangeLogStoreCommon cstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
Struct data = new Struct();
data.put("key", "val1");
cstore.put("test1", JSON.bytes(data));
List<String> ls = fstore.getLocalDomainList();
assertEquals(ls.size(), 1);
assertTrue(ls.contains("test1"));
}
use of com.yahoo.rdl.Struct in project athenz by yahoo.
the class ZMSFileChangeLogStoreCommonTest method testPutException.
@Test
public void testPutException() throws IOException {
ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
FilesHelper helper = Mockito.mock(FilesHelper.class);
Mockito.when(helper.write(any(), any())).thenThrow(new IOException("io exception"));
fstore.filesHelper = helper;
Struct data = new Struct();
data.put("key", "val1");
try {
fstore.put("test1", JSON.bytes(data));
fail();
} catch (Exception ex) {
assertTrue(true);
}
}
Aggregations