DynamoDBSSHRecordStoreConnection implements SSHRecordStoreConnection { @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; } } DynamoDBSSHRecordStoreConnection(DynamoDB dynamoDB, final String tableName); @Override void setOperationTimeout(int queryTimeout); @Override void close(); @Override SSHCertRecord getSSHCertRecord(String instanceId, String service); @Override boolean updateSSHCertRecord(SSHCertRecord certRecord); @Override boolean insertSSHCertRecord(SSHCertRecord certRecord); @Override boolean deleteSSHCertRecord(String instanceId, String service); @Override int deleteExpiredSSHCertRecords(int expiryTimeMins);  }
@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(); }