mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-12 00:41:32 +00:00
Merge pull request #79 from open-metadata/issue78
Fix #78 Change AuditLog from entity into a type
This commit is contained in:
commit
5fc946827c
@ -212,9 +212,9 @@ CREATE TABLE IF NOT EXISTS tag_usage (
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS audit_log (
|
||||
id VARCHAR(36) GENERATED ALWAYS AS (json ->> '$.id') STORED NOT NULL,
|
||||
id VARCHAR(36) GENERATED ALWAYS AS (json ->> '$.entityId') STORED NOT NULL,
|
||||
entityType VARCHAR(256) GENERATED ALWAYS AS (json ->> '$.entityType') NOT NULL,
|
||||
username VARCHAR(256) GENERATED ALWAYS AS (json ->> '$.username') NOT NULL,
|
||||
username VARCHAR(256) GENERATED ALWAYS AS (json ->> '$.userName') NOT NULL,
|
||||
json JSON NOT NULL,
|
||||
timestamp BIGINT,
|
||||
PRIMARY KEY (id)
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
package org.openmetadata.catalog.events;
|
||||
|
||||
import org.openmetadata.catalog.CatalogApplicationConfig;
|
||||
import org.openmetadata.catalog.entity.audit.AuditLog;
|
||||
import org.openmetadata.catalog.type.AuditLog;
|
||||
import org.openmetadata.catalog.jdbi3.AuditLogRepository;
|
||||
import org.openmetadata.catalog.type.EntityReference;
|
||||
import org.openmetadata.catalog.util.EntityUtil;
|
||||
@ -31,7 +31,6 @@ import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AuditEventHandler implements EventHandler {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AuditEventHandler.class);
|
||||
@ -59,14 +58,13 @@ public class AuditEventHandler implements EventHandler {
|
||||
EntityReference entityReference = EntityUtil.getEntityReference(responseContext.getEntity(),
|
||||
responseContext.getEntity().getClass());
|
||||
if (entityReference != null) {
|
||||
AuditLog auditLog = new AuditLog().withId(UUID.randomUUID())
|
||||
AuditLog auditLog = new AuditLog()
|
||||
.withPath(path)
|
||||
.withDate(nowAsISO)
|
||||
.withDateTime(nowAsISO)
|
||||
.withEntityId(entityReference.getId())
|
||||
.withEntityType(entityReference.getType())
|
||||
.withEntity(entityReference)
|
||||
.withMethod(method)
|
||||
.withUsername(username)
|
||||
.withMethod(AuditLog.Method.fromValue(method))
|
||||
.withUserName(username)
|
||||
.withResponseCode(responseCode);
|
||||
auditLogRepository.create(auditLog);
|
||||
LOG.debug("Added audit log entry: {}", auditLog);
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import org.openmetadata.catalog.entity.audit.AuditLog;
|
||||
import org.openmetadata.catalog.type.AuditLog;
|
||||
import org.openmetadata.catalog.util.EntityUtil;
|
||||
|
||||
import org.openmetadata.catalog.util.JsonUtils;
|
||||
|
||||
@ -1,49 +0,0 @@
|
||||
{
|
||||
"$id": "https://github.com/open-metadata/OpenMetadata/blob/main/catalog-rest-service/src/main/resources/json/schema/entity/audit/auditLog.json",
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Audit Log",
|
||||
"description": "This schema defines Audit Log entity. Audit Log is used to capture audit trail of POST, PUT, and PATCH API operations.",
|
||||
"type": "object",
|
||||
|
||||
"properties" : {
|
||||
"id": {
|
||||
"description": "Unique identifier that identifies a Audit Log Entry.",
|
||||
"$ref": "../../type/basic.json#/definitions/uuid"
|
||||
},
|
||||
"method": {
|
||||
"description": "HTTP Method used in a call.",
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 64
|
||||
},
|
||||
"responseCode": {
|
||||
"description": "HTTP response code for the api requested.",
|
||||
"type": "integer"
|
||||
},
|
||||
"path": {
|
||||
"description": "Requested API Path.",
|
||||
"type": "string"
|
||||
},
|
||||
"username": {
|
||||
"description": "Name of the user who requested for the API.",
|
||||
"type": "string"
|
||||
},
|
||||
"date": {
|
||||
"description": "Date which the api call is made.",
|
||||
"$ref": "../../type/basic.json#/definitions/date"
|
||||
},
|
||||
"entityId": {
|
||||
"description": "Entity reference.",
|
||||
"$ref": "../../type/basic.json#/definitions/uuid"
|
||||
},
|
||||
"entityType": {
|
||||
"description": "Entity Type.",
|
||||
"type": "string"
|
||||
},
|
||||
"entity" : {
|
||||
"description": "Link to entity on which api request is done.",
|
||||
"$ref" : "../../type/entityReference.json"
|
||||
}
|
||||
},
|
||||
"required": ["id", "method", "responseCode", "user", "entity"]
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
{
|
||||
"$id": "https://github.com/open-metadata/OpenMetadata/blob/main/catalog-rest-service/src/main/resources/json/schema/type/auditLog.json",
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Audit Log",
|
||||
"description": "This schema defines type for Audit Log. Audit Log is used to capture audit trail of POST, PUT, and PATCH API operations.",
|
||||
"type": "object",
|
||||
|
||||
"properties" : {
|
||||
"method": {
|
||||
"description": "HTTP Method used in a call.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"POST",
|
||||
"PUT",
|
||||
"PATCH",
|
||||
"DELETE"
|
||||
]
|
||||
},
|
||||
"responseCode": {
|
||||
"description": "HTTP response code for the api requested.",
|
||||
"type": "integer"
|
||||
},
|
||||
"path": {
|
||||
"description": "Requested API Path.",
|
||||
"type": "string"
|
||||
},
|
||||
"userName": {
|
||||
"description": "Name of the user who requested for the API.",
|
||||
"type": "string"
|
||||
},
|
||||
"dateTime": {
|
||||
"description": "Date which the api call is made.",
|
||||
"$ref": "basic.json#/definitions/dateTime"
|
||||
},
|
||||
"entityId": {
|
||||
"description": "Entity Id that was modified by the operation.",
|
||||
"$ref": "basic.json#/definitions/uuid"
|
||||
},
|
||||
"entityType": {
|
||||
"description": "Entity Type that modified by the operation.",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["method", "responseCode", "path", "userName", "entityId", "entityType"]
|
||||
}
|
||||
@ -7,11 +7,11 @@
|
||||
|
||||
"definitions": {
|
||||
"driverClass": {
|
||||
"$comment": "Type used for JDBC driver class",
|
||||
"description": "Type used for JDBC driver class",
|
||||
"type": "string"
|
||||
},
|
||||
"connectionUrl": {
|
||||
"$comment": "Type used for JDBC connection URL",
|
||||
"description": "Type used for JDBC connection URL",
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
},
|
||||
@ -19,7 +19,7 @@
|
||||
"jdbcInfo": {
|
||||
"type": "object",
|
||||
"javaType": "org.openmetadata.catalog.type.JdbcInfo",
|
||||
"$comment": "Type for capturing JDBC connector information",
|
||||
"description": "Type for capturing JDBC connector information",
|
||||
"properties": {
|
||||
"driverClass": {
|
||||
"$ref" : "#/definitions/driverClass",
|
||||
@ -36,7 +36,7 @@
|
||||
}
|
||||
},
|
||||
|
||||
"$comment":"JDBC connection information",
|
||||
"description":"JDBC connection information",
|
||||
"properties": {
|
||||
"driverClass": {
|
||||
"$ref" : "#/definitions/driverClass"
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
"javaType": "org.openmetadata.catalog.type.UsageDetails",
|
||||
"definitions": {
|
||||
"usageStats": {
|
||||
"$comment": "Type used to return usage statistics",
|
||||
"description": "Type used to return usage statistics",
|
||||
"type": "object",
|
||||
"javaType": "org.openmetadata.catalog.type.UsageStats",
|
||||
"properties": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user