use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class DynamoDBSSHRecordStoreConnectionTest method testGetSSHCertRecord.
@Test
public void testGetSSHCertRecord() {
Mockito.doReturn(item).when(table).getItem("primaryKey", "cn:1234");
Mockito.doReturn("1234").when(item).getString("instanceId");
Mockito.doReturn("cn").when(item).getString("service");
Mockito.doReturn("host1,host2").when(item).getString("principals");
Mockito.doReturn("10.10.10.11").when(item).getString("clientIP");
Mockito.doReturn("10.10.10.12").when(item).getString("privateIP");
DynamoDBSSHRecordStoreConnection dbConn = new DynamoDBSSHRecordStoreConnection(dynamoDB, tableName);
dbConn.setOperationTimeout(10);
SSHCertRecord certRecord = dbConn.getSSHCertRecord("1234", "cn");
assertEquals(certRecord.getInstanceId(), "1234");
assertEquals(certRecord.getService(), "cn");
assertEquals(certRecord.getPrincipals(), "host1,host2");
assertEquals(certRecord.getClientIP(), "10.10.10.11");
assertEquals(certRecord.getPrivateIP(), "10.10.10.12");
dbConn.close();
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class DynamoDBSSHRecordStoreConnectionTest method testGetSSHCertRecordNotFoundNull.
@Test
public void testGetSSHCertRecordNotFoundNull() {
Mockito.doReturn(null).when(table).getItem("primaryKey", "cn:1234");
DynamoDBSSHRecordStoreConnection dbConn = new DynamoDBSSHRecordStoreConnection(dynamoDB, tableName);
SSHCertRecord certRecord = dbConn.getSSHCertRecord("1234", "cn");
assertNull(certRecord);
dbConn.close();
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class DynamoDBSSHRecordStoreConnectionTest method testUpdateSSHRecordException.
@Test
public void testUpdateSSHRecordException() {
SSHCertRecord certRecord = new SSHCertRecord();
Mockito.doThrow(new AmazonDynamoDBException("invalid operation")).when(table).updateItem(ArgumentMatchers.any(UpdateItemSpec.class));
DynamoDBSSHRecordStoreConnection dbConn = new DynamoDBSSHRecordStoreConnection(dynamoDB, tableName);
boolean requestSuccess = dbConn.updateSSHCertRecord(certRecord);
assertFalse(requestSuccess);
dbConn.close();
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class ZTSImpl method generateSSHCertRecord.
SSHCertRecord generateSSHCertRecord(ResourceContext ctx, final String service, final String instanceId, final String privateIp) {
// generate a ssh object for recording
SSHCertRecord certRecord = new SSHCertRecord();
certRecord.setService(service);
certRecord.setInstanceId(instanceId);
certRecord.setClientIP(ServletRequestUtil.getRemoteAddress(ctx.request()));
if (StringUtil.isEmpty(privateIp)) {
certRecord.setPrivateIP(certRecord.getClientIP());
} else {
certRecord.setPrivateIP(privateIp);
}
return certRecord;
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class FileSSHRecordStoreConnection method getCertRecord.
private synchronized SSHCertRecord getCertRecord(String instanceId, String service) {
File file = new File(rootDir, getRecordFileName(instanceId, service));
if (!file.exists()) {
return null;
}
SSHCertRecord record = null;
try {
Path path = Paths.get(file.toURI());
record = JSON.fromBytes(Files.readAllBytes(path), SSHCertRecord.class);
} catch (IOException ex) {
LOGGER.error("Unable to get ssh certificate record", ex);
}
return record;
}
Aggregations