Skip to content

Commit 1723f5d

Browse files
authored
feat: Add audit record APIs and deprecate existing audit log APIs (#422)
* feat: Add audit record APIs and deprecate existing audit log APIs * chore: Update deprecation notice * add uuid validation for actor id * make `type` field optional in `AuditRecordActor` * add idempotency_key field with UUID validation to AuditRecord
1 parent 00c55b6 commit 1723f5d

File tree

3 files changed

+100
-3
lines changed

3 files changed

+100
-3
lines changed

raystack/frontier/v1beta1/admin.proto

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,9 @@ service AdminService {
788788
// Revoke a specific session for a specific user (admin only).
789789
rpc RevokeUserSession(RevokeUserSessionRequest) returns (RevokeUserSessionResponse) {}
790790

791+
// Audit Records (Admin Only)
792+
rpc ListAuditRecords(ListAuditRecordsRequest) returns (ListAuditRecordsResponse) {}
793+
791794
}
792795

793796
message ListAllUsersRequest {
@@ -1720,3 +1723,15 @@ message RevokeUserSessionRequest {
17201723
}
17211724

17221725
message RevokeUserSessionResponse {}
1726+
1727+
// Admin Audit Record messages
1728+
1729+
message ListAuditRecordsRequest {
1730+
RQLRequest query = 1;
1731+
}
1732+
1733+
message ListAuditRecordsResponse {
1734+
repeated AuditRecord audit_records = 1;
1735+
RQLQueryPaginationResponse pagination = 2;
1736+
RQLQueryGroupResponse group = 3;
1737+
}

raystack/frontier/v1beta1/frontier.proto

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,32 +1308,38 @@ service FrontierService {
13081308

13091309
// Audit logs
13101310
rpc ListOrganizationAuditLogs(ListOrganizationAuditLogsRequest) returns (ListOrganizationAuditLogsResponse) {
1311+
option deprecated = true;
13111312
option (google.api.http) = {get: "/v1beta1/organizations/{org_id}/auditlogs"};
13121313
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
13131314
tags: "AuditLog";
13141315
summary: "List audit logs";
1315-
description: "Returns a list of audit logs of an organization in Frontier.";
1316+
description: "Returns a list of audit logs of an organization in Frontier. DEPRECATED: Use admin ListAuditRecords API instead.";
1317+
deprecated: true;
13161318
};
13171319
}
13181320

13191321
rpc CreateOrganizationAuditLogs(CreateOrganizationAuditLogsRequest) returns (CreateOrganizationAuditLogsResponse) {
1322+
option deprecated = true;
13201323
option (google.api.http) = {
13211324
post: "/v1beta1/organizations/{org_id}/auditlogs",
13221325
body: "*"
13231326
};
13241327
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
13251328
tags: "AuditLog";
13261329
summary: "Create audit log";
1327-
description: "Create new audit logs in a batch.";
1330+
description: "Create new audit logs in a batch. DEPRECATED: Use ListAuditRecords API instead with filters.";
1331+
deprecated: true;
13281332
};
13291333
}
13301334

13311335
rpc GetOrganizationAuditLog(GetOrganizationAuditLogRequest) returns (GetOrganizationAuditLogResponse) {
1336+
option deprecated = true;
13321337
option (google.api.http) = {get: "/v1beta1/organizations/{org_id}/auditlogs/{id}"};
13331338
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
13341339
tags: "AuditLog";
13351340
summary: "Get audit log";
1336-
description: "Get an audit log by ID.";
1341+
description: "Get an audit log by ID. DEPRECATED: Use admin GetAuditRecord API instead.";
1342+
deprecated: true;
13371343
};
13381344
}
13391345

@@ -1915,6 +1921,9 @@ service FrontierService {
19151921
description: "Create prospect for given email and activity. Available for public access.";
19161922
};
19171923
}
1924+
1925+
// Audit Records
1926+
rpc CreateAuditRecord(CreateAuditRecordRequest) returns (CreateAuditRecordResponse) {}
19181927
}
19191928

19201929
// Billing
@@ -4165,3 +4174,38 @@ message RevokeSessionResponse {}
41654174
message PingUserSessionRequest {}
41664175

41674176
message PingUserSessionResponse {}
4177+
4178+
message CreateAuditRecordRequest {
4179+
AuditRecordActor actor = 1 [(google.api.field_behavior) = REQUIRED];
4180+
4181+
string event = 2 [
4182+
(google.api.field_behavior) = REQUIRED,
4183+
(validate.rules).string = {min_len: 3}
4184+
];
4185+
4186+
// Base resource on which this change happened
4187+
AuditRecordResource resource = 3 [(google.api.field_behavior) = REQUIRED];
4188+
4189+
// Related resource info (optional)
4190+
AuditRecordTarget target = 4;
4191+
4192+
// When the event occurred
4193+
google.protobuf.Timestamp occurred_at = 5 [(google.api.field_behavior) = REQUIRED];
4194+
4195+
string org_id = 6 [(validate.rules).string.uuid = true];
4196+
4197+
// Request ID for tracing
4198+
string req_id = 7;
4199+
4200+
// Flexible metadata field for any additional data including reason, changes, etc.
4201+
google.protobuf.Struct metadata = 8;
4202+
4203+
// Idempotency key to prevent duplicate audit records. Can be used for storing external id.
4204+
string idempotency_key = 9 [
4205+
(google.api.field_behavior) = REQUIRED,
4206+
(validate.rules).string.uuid = true];
4207+
}
4208+
4209+
message CreateAuditRecordResponse {
4210+
AuditRecord audit_record = 1;
4211+
}

raystack/frontier/v1beta1/models.proto

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,3 +1044,41 @@ message Session {
10441044
google.protobuf.Timestamp created_at = 4;
10451045
google.protobuf.Timestamp updated_at = 5;
10461046
}
1047+
1048+
// Audit Record models
1049+
1050+
message AuditRecordActor {
1051+
string id = 1 [(google.api.field_behavior) = REQUIRED, (validate.rules).string.uuid = true];
1052+
string type = 2; // not mandatory if id is zeroUUID
1053+
string name = 3;
1054+
google.protobuf.Struct metadata = 4;
1055+
}
1056+
1057+
message AuditRecordResource {
1058+
string id = 1 [(google.api.field_behavior) = REQUIRED];
1059+
string type = 2 [(google.api.field_behavior) = REQUIRED];
1060+
string name = 3;
1061+
google.protobuf.Struct metadata = 4;
1062+
}
1063+
1064+
message AuditRecordTarget {
1065+
string id = 1;
1066+
string type = 2;
1067+
string name = 3;
1068+
google.protobuf.Struct metadata = 4;
1069+
}
1070+
1071+
message AuditRecord {
1072+
string id = 1;
1073+
1074+
AuditRecordActor actor = 2;
1075+
string event = 3;
1076+
AuditRecordResource resource = 4;
1077+
AuditRecordTarget target = 5;
1078+
google.protobuf.Timestamp occurred_at = 6;
1079+
string org_id = 7;
1080+
string req_id = 8;
1081+
google.protobuf.Struct metadata = 9;
1082+
1083+
google.protobuf.Timestamp created_at = 10;
1084+
}

0 commit comments

Comments
 (0)