Search in sources :

Example 96 with DynamoDB

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();
}
Also used : AmazonDynamoDBException(com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException) UpdateItemSpec(com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 97 with DynamoDB

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;
    }
}
Also used : DeleteItemSpec(com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec)

Example 98 with DynamoDB

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);
}
Also used : ZTSClientNotificationSenderImpl(com.yahoo.athenz.zts.notification.ZTSClientNotificationSenderImpl) ResourceException(com.yahoo.athenz.zts.ResourceException) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Example 99 with DynamoDB

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);
    }
}
Also used : AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Example 100 with DynamoDB

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;
    }
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord)

Aggregations

DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)38 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)32 Table (com.amazonaws.services.dynamodbv2.document.Table)25 Item (com.amazonaws.services.dynamodbv2.document.Item)19 Test (org.junit.Test)18 AmazonServiceException (com.amazonaws.AmazonServiceException)16 HashMap (java.util.HashMap)15 TestRunner (org.apache.nifi.util.TestRunner)15 AmazonClientException (com.amazonaws.AmazonClientException)14 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)14 MockFlowFile (org.apache.nifi.util.MockFlowFile)14 ArrayList (java.util.ArrayList)11 Map (java.util.Map)11 TableWriteItems (com.amazonaws.services.dynamodbv2.document.TableWriteItems)10 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)10 IOException (java.io.IOException)10 TableKeysAndAttributes (com.amazonaws.services.dynamodbv2.document.TableKeysAndAttributes)9 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)9 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)9 List (java.util.List)9