Search in sources :

Example 1 with DescribeDBSecurityGroupsRequest

use of com.amazonaws.services.rds.model.DescribeDBSecurityGroupsRequest in project Synapse-Stack-Builder by Sage-Bionetworks.

the class DatabaseSecuritySetup method describeResources.

public void describeResources() {
    DescribeDBSecurityGroupsRequest req;
    DescribeDBSecurityGroupsResult res;
    resources.setIdGeneratorDatabaseSecurityGroup(describeDBSecurityGroup(config.getIdGeneratorDatabaseSecurityGroupName()));
    resources.setStackInstancesDatabaseSecurityGroup(describeDBSecurityGroup(config.getStackDatabaseSecurityGroupName()));
}
Also used : DescribeDBSecurityGroupsRequest(com.amazonaws.services.rds.model.DescribeDBSecurityGroupsRequest) DescribeDBSecurityGroupsResult(com.amazonaws.services.rds.model.DescribeDBSecurityGroupsResult)

Example 2 with DescribeDBSecurityGroupsRequest

use of com.amazonaws.services.rds.model.DescribeDBSecurityGroupsRequest in project Synapse-Stack-Builder by Sage-Bionetworks.

the class DatabaseSecuritySetupTest method testDescribeResourcesExist.

@Test
public void testDescribeResourcesExist() {
    DescribeDBSecurityGroupsRequest reqIdGen = new DescribeDBSecurityGroupsRequest();
    reqIdGen.setDBSecurityGroupName(config.getIdGeneratorDatabaseSecurityGroupName());
    DescribeDBSecurityGroupsRequest reqStackInst = new DescribeDBSecurityGroupsRequest();
    reqStackInst.setDBSecurityGroupName(config.getStackDatabaseSecurityGroupName());
    when(mockClient.describeDBSecurityGroups(reqIdGen)).thenReturn(new DescribeDBSecurityGroupsResult().withDBSecurityGroups(new DBSecurityGroup().withDBSecurityGroupName(config.getIdGeneratorDatabaseSecurityGroupName())));
    when(mockClient.describeDBSecurityGroups(reqStackInst)).thenReturn(new DescribeDBSecurityGroupsResult().withDBSecurityGroups(new DBSecurityGroup().withDBSecurityGroupName(config.getStackDatabaseSecurityGroupName())));
    databaseSecuritySetup.describeResources();
    assertNotNull(resources.getIdGeneratorDatabaseSecurityGroup());
    assertNotNull(resources.getStackInstancesDatabaseSecurityGroup());
}
Also used : DescribeDBSecurityGroupsRequest(com.amazonaws.services.rds.model.DescribeDBSecurityGroupsRequest) DBSecurityGroup(com.amazonaws.services.rds.model.DBSecurityGroup) DescribeDBSecurityGroupsResult(com.amazonaws.services.rds.model.DescribeDBSecurityGroupsResult) Test(org.junit.Test)

Example 3 with DescribeDBSecurityGroupsRequest

use of com.amazonaws.services.rds.model.DescribeDBSecurityGroupsRequest in project Synapse-Stack-Builder by Sage-Bionetworks.

the class DatabaseSecuritySetupTest method testDescribeSecurityGroupExists.

@Test
public void testDescribeSecurityGroupExists() {
    DescribeDBSecurityGroupsRequest req = new DescribeDBSecurityGroupsRequest();
    req.setDBSecurityGroupName("name");
    when(mockClient.describeDBSecurityGroups(req)).thenReturn(new DescribeDBSecurityGroupsResult().withDBSecurityGroups(new DBSecurityGroup().withDBSecurityGroupName("name")));
    DBSecurityGroup grp = databaseSecuritySetup.describeDBSecurityGroup("name");
    assertEquals("name", grp.getDBSecurityGroupName());
}
Also used : DescribeDBSecurityGroupsRequest(com.amazonaws.services.rds.model.DescribeDBSecurityGroupsRequest) DBSecurityGroup(com.amazonaws.services.rds.model.DBSecurityGroup) DescribeDBSecurityGroupsResult(com.amazonaws.services.rds.model.DescribeDBSecurityGroupsResult) Test(org.junit.Test)

Example 4 with DescribeDBSecurityGroupsRequest

use of com.amazonaws.services.rds.model.DescribeDBSecurityGroupsRequest in project Synapse-Stack-Builder by Sage-Bionetworks.

the class DatabaseSecuritySetupTest method testSetupDatabaseAllSecurityGroups.

/**
 * Test that the expected security groups are created.
 */
@Test
public void testSetupDatabaseAllSecurityGroups() {
    // Id gen
    DBSecurityGroup expectedIdGroup = new DBSecurityGroup().withDBSecurityGroupName(config.getIdGeneratorDatabaseSecurityGroupName());
    DescribeDBSecurityGroupsResult result = new DescribeDBSecurityGroupsResult().withDBSecurityGroups(expectedIdGroup);
    when(mockClient.describeDBSecurityGroups(new DescribeDBSecurityGroupsRequest().withDBSecurityGroupName(config.getIdGeneratorDatabaseSecurityGroupName()))).thenReturn(result);
    // stack
    DBSecurityGroup expectedStackGroup = new DBSecurityGroup().withDBSecurityGroupName(config.getStackDatabaseSecurityGroupName());
    result = new DescribeDBSecurityGroupsResult().withDBSecurityGroups(expectedStackGroup);
    when(mockClient.describeDBSecurityGroups(new DescribeDBSecurityGroupsRequest().withDBSecurityGroupName(config.getStackDatabaseSecurityGroupName()))).thenReturn(result);
    // Make the call
    databaseSecuritySetup.setupDatabaseAllSecurityGroups();
    // Verify the expected calls
    // Id gen db security group
    CreateDBSecurityGroupRequest request = new CreateDBSecurityGroupRequest();
    request.setDBSecurityGroupDescription(config.getIdGeneratorDatabaseSecurityGroupDescription());
    request.setDBSecurityGroupName(config.getIdGeneratorDatabaseSecurityGroupName());
    verify(mockClient, times(1)).createDBSecurityGroup(request);
    // Stack db security group
    request = new CreateDBSecurityGroupRequest();
    request.setDBSecurityGroupDescription(config.getStackDatabaseSecurityGroupDescription());
    request.setDBSecurityGroupName(config.getStackDatabaseSecurityGroupName());
    verify(mockClient, times(1)).createDBSecurityGroup(request);
    // Check the access adds
    // Add to id gen group
    AuthorizeDBSecurityGroupIngressRequest ingressRequest = new AuthorizeDBSecurityGroupIngressRequest(config.getIdGeneratorDatabaseSecurityGroupName());
    ingressRequest.setEC2SecurityGroupOwnerId(elasticSecurityGroup.getOwnerId());
    ingressRequest.setEC2SecurityGroupName(elasticSecurityGroup.getGroupName());
    verify(mockClient, times(1)).authorizeDBSecurityGroupIngress(ingressRequest);
    // add id gen CIDR
    ingressRequest = new AuthorizeDBSecurityGroupIngressRequest(config.getIdGeneratorDatabaseSecurityGroupName());
    ingressRequest.setCIDRIP(config.getCIDRForSSH());
    verify(mockClient, times(1)).authorizeDBSecurityGroupIngress(ingressRequest);
    // add to the stack db group
    // Check the access adds
    ingressRequest = new AuthorizeDBSecurityGroupIngressRequest(config.getStackDatabaseSecurityGroupName());
    ingressRequest.setEC2SecurityGroupOwnerId(elasticSecurityGroup.getOwnerId());
    ingressRequest.setEC2SecurityGroupName(elasticSecurityGroup.getGroupName());
    verify(mockClient, times(1)).authorizeDBSecurityGroupIngress(ingressRequest);
    // add stack CIDR
    ingressRequest = new AuthorizeDBSecurityGroupIngressRequest(config.getStackDatabaseSecurityGroupName());
    ingressRequest.setCIDRIP(config.getCIDRForSSH());
    verify(mockClient, times(1)).authorizeDBSecurityGroupIngress(ingressRequest);
    // Make sure the groups are set in the resources
    assertEquals(expectedIdGroup, resources.getIdGeneratorDatabaseSecurityGroup());
    assertEquals(expectedStackGroup, resources.getStackInstancesDatabaseSecurityGroup());
}
Also used : DescribeDBSecurityGroupsRequest(com.amazonaws.services.rds.model.DescribeDBSecurityGroupsRequest) AuthorizeDBSecurityGroupIngressRequest(com.amazonaws.services.rds.model.AuthorizeDBSecurityGroupIngressRequest) CreateDBSecurityGroupRequest(com.amazonaws.services.rds.model.CreateDBSecurityGroupRequest) DBSecurityGroup(com.amazonaws.services.rds.model.DBSecurityGroup) DescribeDBSecurityGroupsResult(com.amazonaws.services.rds.model.DescribeDBSecurityGroupsResult) Test(org.junit.Test)

Aggregations

DescribeDBSecurityGroupsRequest (com.amazonaws.services.rds.model.DescribeDBSecurityGroupsRequest)4 DescribeDBSecurityGroupsResult (com.amazonaws.services.rds.model.DescribeDBSecurityGroupsResult)4 DBSecurityGroup (com.amazonaws.services.rds.model.DBSecurityGroup)3 Test (org.junit.Test)3 AuthorizeDBSecurityGroupIngressRequest (com.amazonaws.services.rds.model.AuthorizeDBSecurityGroupIngressRequest)1 CreateDBSecurityGroupRequest (com.amazonaws.services.rds.model.CreateDBSecurityGroupRequest)1