diff --git a/bootstrap/sql/mysql/v001__create_db_connection_info.sql b/bootstrap/sql/mysql/v001__create_db_connection_info.sql index 678fcd222dc..4c0d18d7307 100644 --- a/bootstrap/sql/mysql/v001__create_db_connection_info.sql +++ b/bootstrap/sql/mysql/v001__create_db_connection_info.sql @@ -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) diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AuditEventHandler.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AuditEventHandler.java index 7e2dd4de7e9..cda87829588 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AuditEventHandler.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AuditEventHandler.java @@ -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); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/AuditLogRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/AuditLogRepository.java index 320fc480939..af8703f891d 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/AuditLogRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/AuditLogRepository.java @@ -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; diff --git a/catalog-rest-service/src/main/resources/json/schema/entity/audit/auditLog.json b/catalog-rest-service/src/main/resources/json/schema/entity/audit/auditLog.json deleted file mode 100644 index bf2efe1e489..00000000000 --- a/catalog-rest-service/src/main/resources/json/schema/entity/audit/auditLog.json +++ /dev/null @@ -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"] -} \ No newline at end of file diff --git a/catalog-rest-service/src/main/resources/json/schema/type/auditLog.json b/catalog-rest-service/src/main/resources/json/schema/type/auditLog.json new file mode 100644 index 00000000000..c77970b4eb0 --- /dev/null +++ b/catalog-rest-service/src/main/resources/json/schema/type/auditLog.json @@ -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"] +} \ No newline at end of file diff --git a/catalog-rest-service/src/main/resources/json/schema/type/jdbcConnection.json b/catalog-rest-service/src/main/resources/json/schema/type/jdbcConnection.json index 934f98967cf..a7f9dc8cb92 100644 --- a/catalog-rest-service/src/main/resources/json/schema/type/jdbcConnection.json +++ b/catalog-rest-service/src/main/resources/json/schema/type/jdbcConnection.json @@ -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" diff --git a/catalog-rest-service/src/main/resources/json/schema/type/usageDetails.json b/catalog-rest-service/src/main/resources/json/schema/type/usageDetails.json index 443b0df274e..064961f6bd7 100644 --- a/catalog-rest-service/src/main/resources/json/schema/type/usageDetails.json +++ b/catalog-rest-service/src/main/resources/json/schema/type/usageDetails.json @@ -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": {