Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

METRON-2267: Audit Zookeeper config changes in REST #1521

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
import org.apache.metron.common.aggregator.Aggregators;
import org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig;
import org.apache.metron.rest.RestException;
import org.apache.metron.rest.security.SecurityUtils;
import org.apache.metron.rest.service.SensorEnrichmentConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -34,13 +37,16 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/sensor/enrichment/config")
public class SensorEnrichmentConfigController {

private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

@Autowired
private SensorEnrichmentConfigService sensorEnrichmentConfigService;

Expand All @@ -50,6 +56,7 @@ public class SensorEnrichmentConfigController {
@RequestMapping(value = "/{name}", method = RequestMethod.POST)
ResponseEntity<SensorEnrichmentConfig> save(@ApiParam(name="name", value="SensorEnrichmentConfig name", required=true)@PathVariable String name,
@ApiParam(name="sensorEnrichmentConfig", value="SensorEnrichmentConfig", required=true)@RequestBody SensorEnrichmentConfig sensorEnrichmentConfig) throws RestException {
LOG.info(String.format("User '%s' changed the '%s' enrichment config to %s", SecurityUtils.getCurrentUser(), name, sensorEnrichmentConfig.toString()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using slf4j tokenization instead of String.format()

LOG.info("User '{}' changed the '{}' enrichment config to {}", SecurityUtils.getCurrentUser(), name, sensorEnrichmentConfig.toString());

if (sensorEnrichmentConfigService.findOne(name) == null) {
return new ResponseEntity<>(sensorEnrichmentConfigService.save(name, sensorEnrichmentConfig), HttpStatus.CREATED);
} else {
Expand Down Expand Up @@ -83,6 +90,7 @@ ResponseEntity<Map<String, SensorEnrichmentConfig>> getAll() throws Exception {
@RequestMapping(value = "/{name}", method = RequestMethod.DELETE)
ResponseEntity<Void> delete(@ApiParam(name="name", value="SensorEnrichmentConfig name", required=true)@PathVariable String name) throws RestException {
if (sensorEnrichmentConfigService.delete(name)) {
LOG.info(String.format("User '%s' deleted the '%s' enrichment config", SecurityUtils.getCurrentUser(), name));
return new ResponseEntity<>(HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.metron.rest.RestException;
import org.apache.metron.rest.security.SecurityUtils;
import org.apache.metron.rest.service.SensorIndexingConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -32,13 +35,16 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/sensor/indexing/config")
public class SensorIndexingConfigController {

private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

@Autowired
private SensorIndexingConfigService sensorIndexingConfigService;

Expand All @@ -48,6 +54,7 @@ public class SensorIndexingConfigController {
@RequestMapping(value = "/{name}", method = RequestMethod.POST)
ResponseEntity<Map<String, Object>> save(@ApiParam(name="name", value="SensorIndexingConfig name", required=true)@PathVariable String name,
@ApiParam(name="sensorIndexingConfig", value="SensorIndexingConfig", required=true)@RequestBody Map<String, Object> sensorIndexingConfig) throws RestException {
LOG.info(String.format("User '%s' changed the '%s' indexing config to %s", SecurityUtils.getCurrentUser(), name, sensorIndexingConfig.toString()));
if (sensorIndexingConfigService.findOne(name) == null) {
return new ResponseEntity<>(sensorIndexingConfigService.save(name, sensorIndexingConfig), HttpStatus.CREATED);
} else {
Expand Down Expand Up @@ -88,6 +95,7 @@ ResponseEntity<Iterable<String>> getAllIndices(@ApiParam(name="writerName", valu
@RequestMapping(value = "/{name}", method = RequestMethod.DELETE)
ResponseEntity<Void> delete(@ApiParam(name="name", value="SensorIndexingConfig name", required=true)@PathVariable String name) throws RestException {
if (sensorIndexingConfigService.delete(name)) {
LOG.info(String.format("User '%s' deleted the '%s' indexing config", SecurityUtils.getCurrentUser(), name));
return new ResponseEntity<>(HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
import org.apache.metron.common.configuration.SensorParserConfig;
import org.apache.metron.rest.RestException;
import org.apache.metron.rest.model.ParseMessageRequest;
import org.apache.metron.rest.security.SecurityUtils;
import org.apache.metron.rest.service.SensorParserConfigService;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -35,12 +38,15 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.lang.invoke.MethodHandles;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/sensor/parser/config")
public class SensorParserConfigController {

private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

@Autowired
private SensorParserConfigService sensorParserConfigService;

Expand All @@ -50,6 +56,7 @@ public class SensorParserConfigController {
@RequestMapping(value = "/{name}", method = RequestMethod.POST)
ResponseEntity<SensorParserConfig> save(@ApiParam(name="name", value="SensorParserConfig name", required=true)@PathVariable String name,
@ApiParam(name="sensorParserConfig", value="SensorParserConfig", required=true)@RequestBody SensorParserConfig sensorParserConfig) throws RestException {
LOG.info(String.format("User '%s' changed the '%s' parser config to %s", SecurityUtils.getCurrentUser(), name, sensorParserConfig.toString()));
if (sensorParserConfigService.findOne(name) == null) {
return new ResponseEntity<>(sensorParserConfigService.save(name, sensorParserConfig), HttpStatus.CREATED);
} else {
Expand Down Expand Up @@ -83,6 +90,7 @@ ResponseEntity<Map<String, SensorParserConfig>> findAll() throws RestException {
@RequestMapping(value = "/{name}", method = RequestMethod.DELETE)
ResponseEntity<Void> delete(@ApiParam(name="name", value="SensorParserConfig name", required=true)@PathVariable String name) throws RestException {
if (sensorParserConfigService.delete(name)) {
LOG.info(String.format("User '%s' deleted the '%s' parser config", SecurityUtils.getCurrentUser(), name));
return new ResponseEntity<>(HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
Expand Down