use of com.amazonaws.services.dynamodbv2.document.DynamoDB 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.amazonaws.services.dynamodbv2.document.DynamoDB in project athenz by yahoo.
the class DynamoDBSSHRecordStoreConnection method deleteSSHCertRecord.
@Override
public boolean deleteSSHCertRecord(String instanceId, String service) {
final String primaryKey = getPrimaryKey(instanceId, service);
try {
DeleteItemSpec deleteItemSpec = new DeleteItemSpec().withPrimaryKey(KEY_PRIMARY, primaryKey);
table.deleteItem(deleteItemSpec);
return true;
} catch (Exception ex) {
LOGGER.error("DynamoDB Delete Error for {}: {}/{}", primaryKey, ex.getClass(), ex.getMessage());
return false;
}
}
use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project athenz by yahoo.
the class DynamoDBCertRecordStoreFactory method create.
@Override
public CertRecordStore create(PrivateKeyStore keyStore) {
final String tableName = System.getProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME);
if (tableName == null || tableName.isEmpty()) {
LOGGER.error("Cert Store DynamoDB table name not specified");
throw new ResourceException(ResourceException.SERVICE_UNAVAILABLE, "DynamoDB table name not specified");
}
final String currentTimeIndexName = System.getProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_CURRENT_TIME_NAME);
if (currentTimeIndexName == null || currentTimeIndexName.isEmpty()) {
LOGGER.error("Cert Store DynamoDB index current-time not specified");
throw new ResourceException(ResourceException.SERVICE_UNAVAILABLE, "DynamoDB index current-time not specified");
}
final String hostNameIndex = System.getProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_HOST_NAME);
if (hostNameIndex == null || hostNameIndex.isEmpty()) {
LOGGER.error("Cert Store DynamoDB index host-name not specified");
throw new ResourceException(ResourceException.SERVICE_UNAVAILABLE, "DynamoDB index host-name not specified");
}
ZTSClientNotificationSenderImpl ztsClientNotificationSender = new ZTSClientNotificationSenderImpl();
AmazonDynamoDB client = getDynamoDBClient(ztsClientNotificationSender, keyStore);
return new DynamoDBCertRecordStore(client, tableName, currentTimeIndexName, hostNameIndex, ztsClientNotificationSender);
}
use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project athenz by yahoo.
the class DynamoDBClientFetcherImpl method getDynamoDBClient.
@Override
public DynamoDBClientAndCredentials getDynamoDBClient(ZTSClientNotificationSender ztsClientNotificationSender, PrivateKeyStore keyStore) {
// if we're given key/cert path settings then
// we'll deal with aws temporary credentials otherwise
// we'll assume we're running in aws thus our ec2 already
// has credentials to access dynamodb
DynamoDBClientSettings dynamoDBClientSettings = new DynamoDBClientSettings(keyStore);
if (dynamoDBClientSettings.areCredentialsProvided()) {
LOGGER.info("DynamoDB Client will use temporary AWS credentials");
return getAuthenticatedDynamoDBClient(dynamoDBClientSettings, ztsClientNotificationSender);
} else {
LOGGER.info("DynamoDB client will use existing AWS authentication");
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withRegion(getAWSRegion(dynamoDBClientSettings.getRegion())).build();
return new DynamoDBClientAndCredentials(client, null);
}
}
use of com.amazonaws.services.dynamodbv2.document.DynamoDB 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;
}
}
Aggregations