use of org.finra.gatekeeper.services.db.exception.GKUnsupportedDBException in project Gatekeeper by FINRAOS.
the class RdsLookupService method loadToGatekeeperRDSInstance.
/**
* Loads the DB instances from a aws fetch call for RDS databases into a list of Gatekeeper RDS Objects
* @param instances
* @return
*/
private List<GatekeeperRDSInstance> loadToGatekeeperRDSInstance(AmazonRDSClient client, List<DBInstance> instances, List<String> securityGroupIds) {
ArrayList<GatekeeperRDSInstance> gatekeeperRDSInstances = new ArrayList<>();
instances.forEach(item -> {
String application = getApplicationTagforInstanceArn(client, item.getDBInstanceArn());
if (item.getDBInstanceStatus().equalsIgnoreCase("available")) {
Boolean enabled = item.getVpcSecurityGroups().stream().anyMatch(sg -> {
return securityGroupIds.contains(sg.getVpcSecurityGroupId());
});
String status = item.getDBInstanceStatus();
String dbName = item.getDBName();
if (dbName == null && item.getEngine().equalsIgnoreCase("postgres")) {
dbName = item.getEngine().toLowerCase();
}
if (!enabled) {
status = "Missing FINRA-RDS-support Security Group";
} else {
try {
String dbStatus = databaseConnectionService.checkDb(item.getEngine(), item.getEndpoint().getAddress() + ":" + item.getEndpoint().getPort() + "/" + dbName);
status = !dbStatus.isEmpty() ? dbStatus : status;
} catch (GKUnsupportedDBException e) {
logger.error("Database Engine is not supported", e);
status = "DB Engine not supported";
}
}
gatekeeperRDSInstances.add(new GatekeeperRDSInstance(item.getDbiResourceId(), item.getDBInstanceIdentifier(), dbName != null ? dbName : "", item.getEngine(), status, item.getDBInstanceArn(), item.getEndpoint().getAddress() + ":" + item.getEndpoint().getPort(), application, enabled));
}
});
return gatekeeperRDSInstances;
}
Aggregations