use of com.yahoo.athenz.zms.PublicKeyEntry in project athenz by yahoo.
the class FileConnection method updateServiceIdentity.
@Override
public boolean updateServiceIdentity(String domainName, ServiceIdentity service) {
DomainStruct domainStruct = getDomainStruct(domainName);
if (domainStruct == null) {
throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "updateServiceIdentity");
}
if (domainStruct.getServices() == null) {
domainStruct.setServices(new HashMap<String, ServiceIdentity>());
}
HashMap<String, ServiceIdentity> services = domainStruct.getServices();
service.setModified(Timestamp.fromCurrentTime());
String serviceName = extractServiceName(domainName, service.getName());
// here we only need to update the main attrs and not
// the public keys and hosts
List<PublicKeyEntry> publicKeys = service.getPublicKeys();
List<String> hosts = service.getHosts();
ServiceIdentity originalService = getServiceObject(domainStruct, serviceName);
if (originalService != null) {
service.setPublicKeys(originalService.getPublicKeys());
service.setHosts(originalService.getHosts());
} else {
service.setPublicKeys(null);
service.setHosts(null);
}
service.setModified(Timestamp.fromCurrentTime());
services.put(serviceName, service);
putDomainStruct(domainName, domainStruct);
service.setPublicKeys(publicKeys);
service.setHosts(hosts);
return true;
}
use of com.yahoo.athenz.zms.PublicKeyEntry in project athenz by yahoo.
the class FileConnection method deletePublicKeyEntry.
@Override
public boolean deletePublicKeyEntry(String domainName, String serviceName, String keyId) {
DomainStruct domainStruct = getDomainStruct(domainName);
if (domainStruct == null) {
throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "deletePublicKeyEntry");
}
ServiceIdentity service = getServiceObject(domainStruct, serviceName);
if (service == null) {
throw ZMSUtils.error(ResourceException.NOT_FOUND, "service not found", "deletePublicKeyEntry");
}
List<PublicKeyEntry> keyList = service.getPublicKeys();
boolean keyRemoved = removePublicKeyEntry(keyList, keyId);
if (!keyRemoved) {
return false;
}
putDomainStruct(domainName, domainStruct);
return true;
}
use of com.yahoo.athenz.zms.PublicKeyEntry in project athenz by yahoo.
the class JDBCConnectionTest method testGetPublicKeyEntry.
@Test
public void testGetPublicKeyEntry() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// service id
7);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for service id
true).thenReturn(// for key
true);
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_KEY_VALUE)).thenReturn("Value1");
PublicKeyEntry publicKey = jdbcConn.getPublicKeyEntry("my-domain", "service1", "zone1", false);
assertNotNull(publicKey);
assertEquals("Value1", publicKey.getKey());
assertEquals("zone1", publicKey.getId());
jdbcConn.close();
}
use of com.yahoo.athenz.zms.PublicKeyEntry in project athenz by yahoo.
the class JDBCConnectionTest method testUpdatePublicKeyEntryException.
@Test
public void testUpdatePublicKeyEntryException() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
PublicKeyEntry publicKey = new PublicKeyEntry().setId("zms1").setKey("Value1");
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// service id
7);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for service id
true);
Mockito.when(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("failed operation", "state", 1001));
try {
jdbcConn.updatePublicKeyEntry("my-domain", "service1", publicKey);
fail();
} catch (Exception ex) {
assertTrue(true);
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.PublicKeyEntry in project athenz by yahoo.
the class JDBCConnectionTest method testListPublicKeys.
@Test
public void testListPublicKeys() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
// return domain/service id
Mockito.when(mockResultSet.getInt(1)).thenReturn(5).thenReturn(7);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for service id
true).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_KEY_ID)).thenReturn("zms1.zone1").thenReturn("zms2.zone1").thenReturn("zms3.zone1");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_KEY_VALUE)).thenReturn("Value1").thenReturn("Value2").thenReturn("Value3");
List<PublicKeyEntry> publicKeys = jdbcConn.listPublicKeys("my-domain", "service1");
// data back is sorted
assertEquals(3, publicKeys.size());
assertEquals("zms1.zone1", publicKeys.get(0).getId());
assertEquals("Value1", publicKeys.get(0).getKey());
assertEquals("zms2.zone1", publicKeys.get(1).getId());
assertEquals("Value2", publicKeys.get(1).getKey());
assertEquals("zms3.zone1", publicKeys.get(2).getId());
assertEquals("Value3", publicKeys.get(2).getKey());
jdbcConn.close();
}
Aggregations