Skip to content
Snippets Groups Projects
Commit 24f5206c authored by Dmitriy Rudko's avatar Dmitriy Rudko :speech_balloon:
Browse files

Merge branch 'gcp-audit-logger-implementation' into 'master'

Audit Logger Implementation (GONRG-1546)

See merge request !74
parents b34ffdce a8e29618
No related branches found
No related tags found
1 merge request!74Audit Logger Implementation (GONRG-1546)
Pipeline #24040 failed
......@@ -19,6 +19,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import java.util.List;
import java.util.stream.Collectors;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import lombok.extern.java.Log;
......@@ -28,6 +29,7 @@ import org.opengroup.osdu.core.common.model.indexer.RecordInfo;
import org.opengroup.osdu.core.common.model.search.RecordChangedMessages;
import org.opengroup.osdu.core.common.model.search.SearchServiceRole;
import org.opengroup.osdu.indexer.SwaggerDoc;
import org.opengroup.osdu.indexer.logging.AuditLogger;
import org.opengroup.osdu.indexer.service.IndexerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
......@@ -46,6 +48,9 @@ public class CleanupIndiciesApi {
@Autowired
private IndexerService indexerService;
@Autowired
private AuditLogger auditLogger;
@PostMapping(path = "/index-cleanup", consumes = "application/json")
@PreAuthorize("@authorizationFilter.hasPermission('" + SearchServiceRole.ADMIN + "')")
public ResponseEntity cleanupIndices(@NotNull(message = SwaggerDoc.REQUEST_VALIDATION_NOT_NULL_BODY)
......@@ -69,6 +74,10 @@ public class CleanupIndiciesApi {
return new ResponseEntity(HttpStatus.OK);
}
indexerService.processSchemaMessages(recordInfos);
auditLogger.getIndexCleanUpJobRun(recordInfos.stream()
.map(RecordInfo::getKind)
.collect(Collectors.toList()));
return new ResponseEntity(HttpStatus.OK);
} catch (AppException e) {
throw e;
......
......@@ -38,6 +38,9 @@ public class AuditEvents {
private static final String INDEX_PURGE_RECORD_ACTION_ID = "IN004";
private static final String INDEX_STARTED_ACTION_ID = "IN006";
private static final String INDEX_STARTED_OPERATION = "Indexing started";
private static final String REINDEX_KIND_ACTION_ID = "IN007";
private static final String REINDEX_KIND_OPERATION = "Reindex kind";
......@@ -151,6 +154,17 @@ public class AuditEvents {
.build();
}
public AuditPayload getIndexEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.CREATE)
.status(AuditStatus.SUCCESS)
.actionId(INDEX_STARTED_ACTION_ID)
.message(INDEX_STARTED_OPERATION)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getReindexEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.CREATE)
......
......@@ -73,6 +73,10 @@ public class AuditLogger {
this.writeLog(this.getAuditEvents().getIndexPurgeRecordFailEvent(resources));
}
public void indexStarted(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexEvent(resources));
}
public void getReindex(List<String> resources) {
this.writeLog(this.getAuditEvents().getReindexEvent(resources));
}
......
......@@ -125,6 +125,10 @@ public class IndexerServiceImpl implements IndexerService {
retryRecordIds.addAll(deleteFailureRecordIds);
}
auditLogger.indexStarted(recordInfos.stream()
.map(RecordInfo::getKind)
.collect(Collectors.toList()));
// process schema change messages
Map<String, OperationType> schemaMsgs = RecordInfo.getSchemaMsgs(recordInfos);
if (schemaMsgs != null && !schemaMsgs.isEmpty()) {
......
......@@ -14,6 +14,7 @@ import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.search.RecordChangedMessages;
import org.opengroup.osdu.core.common.search.Config;
import org.opengroup.osdu.indexer.logging.AuditLogger;
import org.opengroup.osdu.indexer.service.IndexerService;
import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder;
import org.powermock.core.classloader.annotations.PrepareForTest;
......@@ -36,6 +37,9 @@ public class CleanupIndiciesApiTest {
@Mock
private IndexerService indexerService;
@Mock
private AuditLogger auditLogger;
@Before
public void setup() {
initMocks(this);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment