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());
}
}
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();
}
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();
}
Aggregations