Search in sources :

Example 1 with RoleType

use of org.finra.gatekeeper.services.accessrequest.model.RoleType in project Gatekeeper by FINRAOS.

the class MySQLDBConnection method getAvailableTables.

public Map<RoleType, List<String>> getAvailableTables(String address) throws SQLException {
    Map<RoleType, List<String>> results = new HashMap<>();
    JdbcTemplate template = connect(address);
    String schemaQuery = "select concat(table_schema,'.',table_name) from information_schema.tables where table_schema not in ('information_schema', 'mysql', 'sys', 'performance_schema')";
    for (RoleType roleType : RoleType.values()) {
        try {
            results.put(roleType, template.queryForList(schemaQuery, String.class));
        } catch (Exception ex) {
            logger.error("An exception was thrown while trying to fetch tables over MySQL at address " + address, ex);
            results.put(roleType, Collections.singletonList("Unable to get available schemas"));
        }
    }
    return results;
}
Also used : RoleType(org.finra.gatekeeper.services.accessrequest.model.RoleType) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DataAccessException(org.springframework.dao.DataAccessException) CannotGetJdbcConnectionException(org.springframework.jdbc.CannotGetJdbcConnectionException) GatekeeperException(org.finra.gatekeeper.exception.GatekeeperException) GKUnsupportedDBException(org.finra.gatekeeper.services.db.exception.GKUnsupportedDBException)

Example 2 with RoleType

use of org.finra.gatekeeper.services.accessrequest.model.RoleType in project Gatekeeper by FINRAOS.

the class PostgresDBConnection method getAvailableTables.

public Map<RoleType, List<String>> getAvailableTables(String address) throws SQLException {
    Map<RoleType, List<String>> results = new HashMap<>();
    PGPoolingDataSource dataSource = connect(address);
    JdbcTemplate conn = new JdbcTemplate(dataSource);
    logger.info("Getting available schema information for " + address);
    for (RoleType roleType : RoleType.values()) {
        try {
            List<String> schemas = conn.queryForList(getSchemas, new Object[] { roleType.getDbRole() }, String.class);
            results.put(roleType, !schemas.isEmpty() ? schemas : Collections.singletonList("No Schemas are available for role " + roleType.getDbRole() + " at this time."));
            logger.info("Retrieved available schema information for database " + address + " for role " + roleType.getDbRole());
        } catch (Exception ex) {
            logger.error("Could not retrieve available role information for database " + address + " for role " + roleType.getDbRole(), ex);
            results.put(roleType, Collections.singletonList("Unable to get available schemas for role " + roleType.getDbRole()));
        }
    }
    dataSource.close();
    return results;
}
Also used : RoleType(org.finra.gatekeeper.services.accessrequest.model.RoleType) PGPoolingDataSource(org.postgresql.ds.PGPoolingDataSource) DataAccessException(org.springframework.dao.DataAccessException) CannotGetJdbcConnectionException(org.springframework.jdbc.CannotGetJdbcConnectionException) GKUnsupportedDBException(org.finra.gatekeeper.services.db.exception.GKUnsupportedDBException)

Aggregations

RoleType (org.finra.gatekeeper.services.accessrequest.model.RoleType)2 GKUnsupportedDBException (org.finra.gatekeeper.services.db.exception.GKUnsupportedDBException)2 DataAccessException (org.springframework.dao.DataAccessException)2 CannotGetJdbcConnectionException (org.springframework.jdbc.CannotGetJdbcConnectionException)2 GatekeeperException (org.finra.gatekeeper.exception.GatekeeperException)1 PGPoolingDataSource (org.postgresql.ds.PGPoolingDataSource)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1