use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.
the class DatasetInstanceHandler method create.
/**
* Creates a new dataset instance.
*
* @param namespaceId namespace of the new dataset instance
* @param name name of the new dataset instance
*/
@PUT
@Path("/data/datasets/{name}")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void create(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String name) throws Exception {
DatasetInstanceConfiguration creationProperties = ConversionHelpers.getInstanceConfiguration(request);
try {
instanceService.create(namespaceId, name, creationProperties);
responder.sendStatus(HttpResponseStatus.OK);
} catch (DatasetAlreadyExistsException e) {
responder.sendString(HttpResponseStatus.CONFLICT, e.getMessage());
} catch (DatasetTypeNotFoundException e) {
responder.sendString(HttpResponseStatus.NOT_FOUND, e.getMessage());
} catch (HandlerException e) {
responder.sendString(e.getFailureStatus(), e.getMessage());
}
}
use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.
the class DatasetInstanceHandler method update.
/**
* Updates an existing dataset specification properties.
*
* @param namespaceId namespace of the dataset instance
* @param name name of the dataset instance
* @throws Exception
*/
@PUT
@Path("/data/datasets/{name}/properties")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void update(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String name) throws Exception {
DatasetId instance = ConversionHelpers.toDatasetInstanceId(namespaceId, name);
Map<String, String> properties = ConversionHelpers.getProperties(request);
instanceService.update(instance, properties);
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.
the class StreamHandler method setConfig.
@PUT
@Path("/{stream}/properties")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void setConfig(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("stream") String stream) throws Exception {
StreamId streamId = validateAndGetStreamId(namespaceId, stream);
checkStreamExists(streamId);
StreamProperties properties = getAndValidateConfig(request);
streamAdmin.updateConfig(streamId, properties);
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.
the class StreamViewHttpHandler method createOrUpdate.
@PUT
@Path("/streams/{stream}/views/{view}")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void createOrUpdate(FullHttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("stream") String stream, @PathParam("view") String view) throws Exception {
StreamViewId viewId;
try {
viewId = new StreamViewId(namespace, stream, view);
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
}
try (Reader reader = new InputStreamReader(new ByteBufInputStream(request.content()), StandardCharsets.UTF_8)) {
ViewSpecification spec = GSON.fromJson(reader, ViewSpecification.class);
if (spec == null) {
throw new BadRequestException("Missing ViewSpecification in request body");
}
boolean created = admin.createOrUpdateView(viewId, spec);
responder.sendStatus(created ? HttpResponseStatus.CREATED : HttpResponseStatus.OK);
} catch (JsonSyntaxException e) {
responder.sendString(HttpResponseStatus.BAD_REQUEST, "Couldn't decode body as view config JSON");
} catch (IOException e) {
LOG.warn("Error closing InputStreamReader", e);
}
}
use of co.cask.cdap.common.security.AuditPolicy in project cdap by caskdata.
the class NamespacedExploreQueryExecutorHttpHandler method query.
@POST
@Path("data/explore/queries")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void query(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") final String namespaceId) throws Exception {
try {
Map<String, String> args = decodeArguments(request);
final String query = args.get("query");
final Map<String, String> additionalSessionConf = new HashMap<>(args);
additionalSessionConf.remove("query");
LOG.trace("Received query: {}", query);
QueryHandle queryHandle = impersonator.doAs(new NamespaceId(namespaceId), new Callable<QueryHandle>() {
@Override
public QueryHandle call() throws Exception {
return exploreService.execute(new NamespaceId(namespaceId), query, additionalSessionConf);
}
}, ImpersonatedOpType.EXPLORE);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(queryHandle));
} catch (IllegalArgumentException e) {
LOG.debug("Got exception:", e);
responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
} catch (SQLException e) {
LOG.debug("Got exception:", e);
responder.sendString(HttpResponseStatus.BAD_REQUEST, String.format("[SQLState %s] %s", e.getSQLState(), e.getMessage()));
}
}
Aggregations