use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class DynamoDBSSHRecordStoreConnection method getSSHCertRecord.
@Override
public SSHCertRecord getSSHCertRecord(String instanceId, String service) {
final String primaryKey = getPrimaryKey(instanceId, service);
try {
Item item = table.getItem(KEY_PRIMARY, primaryKey);
if (item == null) {
LOGGER.error("DynamoDB Get Error for {}: item not found", primaryKey);
return null;
}
SSHCertRecord certRecord = new SSHCertRecord();
certRecord.setInstanceId(instanceId);
certRecord.setService(service);
certRecord.setPrincipals(item.getString(KEY_PRINCIPALS));
certRecord.setClientIP(item.getString(KEY_CLIENT_IP));
certRecord.setPrivateIP(item.getString(KEY_PRIVATE_IP));
return certRecord;
} catch (Exception ex) {
LOGGER.error("DynamoDB Get Error for {}: {}/{}", primaryKey, ex.getClass(), ex.getMessage());
return null;
}
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class JDBCSSHRecordStoreConnection method getSSHCertRecord.
@Override
public SSHCertRecord getSSHCertRecord(String instanceId, String service) {
final String caller = "getSSHCertRecord";
SSHCertRecord sshCertRecord = null;
try (PreparedStatement ps = con.prepareStatement(SQL_GET_SSH_RECORD)) {
ps.setString(1, instanceId);
ps.setString(2, service);
try (ResultSet rs = executeQuery(ps, caller)) {
if (rs.next()) {
sshCertRecord = new SSHCertRecord();
sshCertRecord.setInstanceId(instanceId);
sshCertRecord.setService(service);
sshCertRecord.setClientIP(rs.getString(DB_COLUMN_CLIENT_IP));
sshCertRecord.setPrincipals(rs.getString(DB_COLUMN_PRINCIPALS));
sshCertRecord.setPrivateIP(rs.getString(DB_COLUMN_PRIVATE_IP));
}
}
} catch (SQLException ex) {
throw sqlError(ex, caller);
}
return sshCertRecord;
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class JDBCSSHRecordStoreConnectionTest method testUpdateSSHRecordNullableColumns.
@Test
public void testUpdateSSHRecordNullableColumns() throws Exception {
JDBCSSHRecordStoreConnection jdbcConn = new JDBCSSHRecordStoreConnection(mockConn);
SSHCertRecord certRecord = new SSHCertRecord();
certRecord.setInstanceId("id1");
certRecord.setService("athenz.api");
certRecord.setPrincipals("host1");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.updateSSHCertRecord(certRecord);
assertTrue(requestSuccess);
Mockito.verify(mockPrepStmt, times(1)).setString(1, "host1");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "");
Mockito.verify(mockPrepStmt, times(1)).setString(4, "id1");
Mockito.verify(mockPrepStmt, times(1)).setString(5, "athenz.api");
jdbcConn.close();
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class JDBCSSHRecordStoreConnectionTest method testInsertSSHRecord.
@Test
public void testInsertSSHRecord() throws Exception {
JDBCSSHRecordStoreConnection jdbcConn = new JDBCSSHRecordStoreConnection(mockConn);
SSHCertRecord certRecord = new SSHCertRecord();
certRecord.setInstanceId("id1");
certRecord.setService("athenz.api");
certRecord.setPrivateIP("10.10.10.11");
certRecord.setClientIP("10.10.10.12");
certRecord.setPrincipals("host1");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.insertSSHCertRecord(certRecord);
assertTrue(requestSuccess);
Mockito.verify(mockPrepStmt, times(1)).setString(1, "id1");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "athenz.api");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "host1");
Mockito.verify(mockPrepStmt, times(1)).setString(4, "10.10.10.12");
Mockito.verify(mockPrepStmt, times(1)).setString(5, "10.10.10.11");
jdbcConn.close();
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class JDBCSSHRecordStoreConnectionTest method testInsertSSHRecordNullableColumns.
@Test
public void testInsertSSHRecordNullableColumns() throws Exception {
JDBCSSHRecordStoreConnection jdbcConn = new JDBCSSHRecordStoreConnection(mockConn);
SSHCertRecord certRecord = new SSHCertRecord();
certRecord.setInstanceId("id1");
certRecord.setService("athenz.api");
certRecord.setPrivateIP("10.10.10.11");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.insertSSHCertRecord(certRecord);
assertTrue(requestSuccess);
Mockito.verify(mockPrepStmt, times(1)).setString(1, "id1");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "athenz.api");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "");
Mockito.verify(mockPrepStmt, times(1)).setString(4, "");
Mockito.verify(mockPrepStmt, times(1)).setString(5, "10.10.10.11");
jdbcConn.close();
}
Aggregations