Search in sources :

Example 1 with DataSourceCredentials

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSourceCredentials in project kylo by Teradata.

the class DataSourceController method listCredentials.

@GET
@Path("{id}/credentials")
@ApiOperation("List credentials for a data source")
@ApiResponses({ @ApiResponse(code = 200, message = "List of credentials", response = DataSetTable.class, responseContainer = "List"), @ApiResponse(code = 404, message = "Data source does not exist", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "Failed to list credentials", response = RestResponseStatus.class) })
public Response listCredentials(@PathParam("id") final String dataSourceId) {
    final boolean encrypted = true;
    log.entry(dataSourceId, encrypted);
    log.debug("List tables for catalog:{} encrypted:{}", encrypted);
    try {
        final DataSource dataSource = findDataSource(dataSourceId, true);
        final Set<Principal> principals = SecurityContextUtil.getCurrentPrincipals();
        final Map<String, String> credProps = this.credentialManager.getCredentials(dataSource, encrypted, principals);
        DataSourceCredentials credentials = new DataSourceCredentials(credProps, encrypted);
        return Response.ok(log.exit(credentials)).build();
    } catch (final Exception e) {
        if (exceptionTransformer.causesInChain(e)) {
            throw new ThriftConnectionException(e);
        }
        log.error("Failed to retrieve credentials for datasource [{}] encrypted={}: " + e, dataSourceId, encrypted, e);
        final RestResponseStatus status = new RestResponseStatus.ResponseStatusBuilder().message(getMessage("catalog.datasource.credentials.error", dataSourceId)).url(request.getRequestURI()).setDeveloperMessage(e).buildError();
        throw new InternalServerErrorException(Response.serverError().entity(status).build());
    }
}
Also used : DataSourceCredentials(com.thinkbiganalytics.kylo.catalog.rest.model.DataSourceCredentials) ThriftConnectionException(com.thinkbiganalytics.hive.exceptions.ThriftConnectionException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Principal(java.security.Principal) TTransportException(org.apache.thrift.transport.TTransportException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) AccessDeniedException(java.nio.file.AccessDeniedException) SQLException(java.sql.SQLException) ThriftConnectionException(com.thinkbiganalytics.hive.exceptions.ThriftConnectionException) CatalogException(com.thinkbiganalytics.kylo.catalog.CatalogException) PotentialControllerServiceConflictException(com.thinkbiganalytics.kylo.catalog.datasource.PotentialControllerServiceConflictException) ForbiddenException(javax.ws.rs.ForbiddenException) DataSourceAlreadyExistsException(com.thinkbiganalytics.metadata.api.catalog.DataSourceAlreadyExistsException) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with DataSourceCredentials

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSourceCredentials in project kylo by Teradata.

the class DataSourceController method getDataSource.

@GET
@ApiOperation("Gets the specified data source")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the data source", response = DataSource.class), @ApiResponse(code = 404, message = "Data source was not found", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "Internal server error", response = RestResponseStatus.class) })
@Path("{id}")
public Response getDataSource(@PathParam("id") final String dataSourceId, @QueryParam("credentials") @DefaultValue("embed") final String credentialMode) {
    // TODO Change default to be "none"
    log.entry(dataSourceId);
    CredentialMode mode;
    final boolean encryptCredentials = true;
    try {
        mode = CredentialMode.valueOf(credentialMode.toUpperCase());
    } catch (IllegalArgumentException e) {
        return Response.status(log.exit(Status.BAD_REQUEST)).entity(getMessage("catalog.datasource.credential.arg.invalid", credentialMode)).build();
    }
    final Set<Principal> principals = SecurityContextUtil.getCurrentPrincipals();
    // TODO remove encrypt flag when real credential manager is in place
    DataSource dataSource = findDataSource(dataSourceId, encryptCredentials);
    switch(mode) {
        case NONE:
            dataSource = this.credentialManager.applyPlaceholders(dataSource, principals);
            break;
        case EMBED:
            dataSource = this.credentialManager.applyCredentials(dataSource, principals);
            break;
        case ATTACH:
            Map<String, String> credProps = this.credentialManager.getCredentials(dataSource, encryptCredentials, principals);
            DataSourceCredentials creds = new DataSourceCredentials(credProps, encryptCredentials);
            dataSource = this.credentialManager.applyPlaceholders(dataSource, principals);
            dataSource.setCredentials(creds);
    }
    return Response.ok(log.exit(dataSource)).build();
}
Also used : DataSourceCredentials(com.thinkbiganalytics.kylo.catalog.rest.model.DataSourceCredentials) Principal(java.security.Principal) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with DataSourceCredentials

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSourceCredentials in project kylo by Teradata.

the class CatalogMetadataController method getDataSource.

@GET
@ApiOperation("Gets the specified data source")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the data source", response = DataSource.class), @ApiResponse(code = 404, message = "Data source was not found", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "Internal server error", response = RestResponseStatus.class) })
@Path("datasource/{id}")
public Response getDataSource(@PathParam("id") final String dataSourceId, @QueryParam("credentials") @DefaultValue("embed") final String credentialMode) {
    // TODO Change default to be "none"
    log.entry(dataSourceId);
    final boolean encryptCredentials = true;
    CredentialMode mode;
    try {
        mode = CredentialMode.valueOf(credentialMode.toUpperCase());
    } catch (IllegalArgumentException e) {
        return Response.status(log.exit(Response.Status.BAD_REQUEST)).entity(getMessage("catalog.datasource.credential.arg.invalid", credentialMode)).build();
    }
    final Set<Principal> principals = SecurityContextUtil.getCurrentPrincipals();
    // TODO remove encrypt flag when real credential manager is in place
    DataSource dataSource = findDataSource(dataSourceId, encryptCredentials);
    switch(mode) {
        case NONE:
            dataSource = this.credentialManager.applyPlaceholders(dataSource, principals);
            break;
        case EMBED:
            dataSource = this.credentialManager.applyCredentials(dataSource, principals);
            break;
        case ATTACH:
            Map<String, String> credProps = this.credentialManager.getCredentials(dataSource, encryptCredentials, principals);
            DataSourceCredentials creds = new DataSourceCredentials(credProps, encryptCredentials);
            dataSource = this.credentialManager.applyPlaceholders(dataSource, principals);
            dataSource.setCredentials(creds);
    }
    return Response.ok(log.exit(dataSource)).build();
}
Also used : DataSourceCredentials(com.thinkbiganalytics.kylo.catalog.rest.model.DataSourceCredentials) Principal(java.security.Principal) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)3 DataSourceCredentials (com.thinkbiganalytics.kylo.catalog.rest.model.DataSourceCredentials)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Principal (java.security.Principal)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 ThriftConnectionException (com.thinkbiganalytics.hive.exceptions.ThriftConnectionException)1 CatalogException (com.thinkbiganalytics.kylo.catalog.CatalogException)1 PotentialControllerServiceConflictException (com.thinkbiganalytics.kylo.catalog.datasource.PotentialControllerServiceConflictException)1 DataSourceAlreadyExistsException (com.thinkbiganalytics.metadata.api.catalog.DataSourceAlreadyExistsException)1 RestResponseStatus (com.thinkbiganalytics.rest.model.RestResponseStatus)1 AccessDeniedException (java.nio.file.AccessDeniedException)1 SQLException (java.sql.SQLException)1 BadRequestException (javax.ws.rs.BadRequestException)1 ForbiddenException (javax.ws.rs.ForbiddenException)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 NotFoundException (javax.ws.rs.NotFoundException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 TTransportException (org.apache.thrift.transport.TTransportException)1