-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin'
- Loading branch information
Showing
45 changed files
with
1,322 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
backend/src/db/migrations/20240503101144_audit-log-stream.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Knex } from "knex"; | ||
|
||
import { TableName } from "../schemas"; | ||
import { createOnUpdateTrigger, dropOnUpdateTrigger } from "../utils"; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
if (!(await knex.schema.hasTable(TableName.AuditLogStream))) { | ||
await knex.schema.createTable(TableName.AuditLogStream, (t) => { | ||
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid()); | ||
t.string("url").notNullable(); | ||
t.text("encryptedHeadersCiphertext"); | ||
t.text("encryptedHeadersIV"); | ||
t.text("encryptedHeadersTag"); | ||
t.string("encryptedHeadersAlgorithm"); | ||
t.string("encryptedHeadersKeyEncoding"); | ||
t.uuid("orgId").notNullable(); | ||
t.foreign("orgId").references("id").inTable(TableName.Organization).onDelete("CASCADE"); | ||
t.timestamps(true, true, true); | ||
}); | ||
} | ||
|
||
await createOnUpdateTrigger(knex, TableName.AuditLogStream); | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
await dropOnUpdateTrigger(knex, TableName.AuditLogStream); | ||
await knex.schema.dropTableIfExists(TableName.AuditLogStream); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Code generated by automation script, DO NOT EDIT. | ||
// Automated by pulling database and generating zod schema | ||
// To update. Just run npm run generate:schema | ||
// Written by akhilmhdh. | ||
|
||
import { z } from "zod"; | ||
|
||
import { TImmutableDBKeys } from "./models"; | ||
|
||
export const AuditLogStreamsSchema = z.object({ | ||
id: z.string().uuid(), | ||
url: z.string(), | ||
encryptedHeadersCiphertext: z.string().nullable().optional(), | ||
encryptedHeadersIV: z.string().nullable().optional(), | ||
encryptedHeadersTag: z.string().nullable().optional(), | ||
encryptedHeadersAlgorithm: z.string().nullable().optional(), | ||
encryptedHeadersKeyEncoding: z.string().nullable().optional(), | ||
orgId: z.string().uuid(), | ||
createdAt: z.date(), | ||
updatedAt: z.date() | ||
}); | ||
|
||
export type TAuditLogStreams = z.infer<typeof AuditLogStreamsSchema>; | ||
export type TAuditLogStreamsInsert = Omit<z.input<typeof AuditLogStreamsSchema>, TImmutableDBKeys>; | ||
export type TAuditLogStreamsUpdate = Partial<Omit<z.input<typeof AuditLogStreamsSchema>, TImmutableDBKeys>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
import { z } from "zod"; | ||
|
||
import { AUDIT_LOG_STREAMS } from "@app/lib/api-docs"; | ||
import { readLimit } from "@app/server/config/rateLimiter"; | ||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth"; | ||
import { SanitizedAuditLogStreamSchema } from "@app/server/routes/sanitizedSchemas"; | ||
import { AuthMode } from "@app/services/auth/auth-type"; | ||
|
||
export const registerAuditLogStreamRouter = async (server: FastifyZodProvider) => { | ||
server.route({ | ||
method: "POST", | ||
url: "/", | ||
config: { | ||
rateLimit: readLimit | ||
}, | ||
schema: { | ||
description: "Create an Audit Log Stream.", | ||
security: [ | ||
{ | ||
bearerAuth: [] | ||
} | ||
], | ||
body: z.object({ | ||
url: z.string().min(1).describe(AUDIT_LOG_STREAMS.CREATE.url), | ||
headers: z | ||
.object({ | ||
key: z.string().min(1).trim().describe(AUDIT_LOG_STREAMS.CREATE.headers.key), | ||
value: z.string().min(1).trim().describe(AUDIT_LOG_STREAMS.CREATE.headers.value) | ||
}) | ||
.describe(AUDIT_LOG_STREAMS.CREATE.headers.desc) | ||
.array() | ||
.optional() | ||
}), | ||
response: { | ||
200: z.object({ | ||
auditLogStream: SanitizedAuditLogStreamSchema | ||
}) | ||
} | ||
}, | ||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), | ||
handler: async (req) => { | ||
const auditLogStream = await server.services.auditLogStream.create({ | ||
actorId: req.permission.id, | ||
actor: req.permission.type, | ||
actorOrgId: req.permission.orgId, | ||
actorAuthMethod: req.permission.authMethod, | ||
url: req.body.url, | ||
headers: req.body.headers | ||
}); | ||
|
||
return { auditLogStream }; | ||
} | ||
}); | ||
|
||
server.route({ | ||
method: "PATCH", | ||
url: "/:id", | ||
config: { | ||
rateLimit: readLimit | ||
}, | ||
schema: { | ||
description: "Update an Audit Log Stream by ID.", | ||
security: [ | ||
{ | ||
bearerAuth: [] | ||
} | ||
], | ||
params: z.object({ | ||
id: z.string().describe(AUDIT_LOG_STREAMS.UPDATE.id) | ||
}), | ||
body: z.object({ | ||
url: z.string().optional().describe(AUDIT_LOG_STREAMS.UPDATE.url), | ||
headers: z | ||
.object({ | ||
key: z.string().min(1).trim().describe(AUDIT_LOG_STREAMS.UPDATE.headers.key), | ||
value: z.string().min(1).trim().describe(AUDIT_LOG_STREAMS.UPDATE.headers.value) | ||
}) | ||
.describe(AUDIT_LOG_STREAMS.UPDATE.headers.desc) | ||
.array() | ||
.optional() | ||
}), | ||
response: { | ||
200: z.object({ | ||
auditLogStream: SanitizedAuditLogStreamSchema | ||
}) | ||
} | ||
}, | ||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), | ||
handler: async (req) => { | ||
const auditLogStream = await server.services.auditLogStream.updateById({ | ||
actorId: req.permission.id, | ||
actor: req.permission.type, | ||
actorOrgId: req.permission.orgId, | ||
actorAuthMethod: req.permission.authMethod, | ||
id: req.params.id, | ||
url: req.body.url, | ||
headers: req.body.headers | ||
}); | ||
|
||
return { auditLogStream }; | ||
} | ||
}); | ||
|
||
server.route({ | ||
method: "DELETE", | ||
url: "/:id", | ||
config: { | ||
rateLimit: readLimit | ||
}, | ||
schema: { | ||
description: "Delete an Audit Log Stream by ID.", | ||
security: [ | ||
{ | ||
bearerAuth: [] | ||
} | ||
], | ||
params: z.object({ | ||
id: z.string().describe(AUDIT_LOG_STREAMS.DELETE.id) | ||
}), | ||
response: { | ||
200: z.object({ | ||
auditLogStream: SanitizedAuditLogStreamSchema | ||
}) | ||
} | ||
}, | ||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), | ||
handler: async (req) => { | ||
const auditLogStream = await server.services.auditLogStream.deleteById({ | ||
actorId: req.permission.id, | ||
actor: req.permission.type, | ||
actorOrgId: req.permission.orgId, | ||
actorAuthMethod: req.permission.authMethod, | ||
id: req.params.id | ||
}); | ||
|
||
return { auditLogStream }; | ||
} | ||
}); | ||
|
||
server.route({ | ||
method: "GET", | ||
url: "/:id", | ||
config: { | ||
rateLimit: readLimit | ||
}, | ||
schema: { | ||
description: "Get an Audit Log Stream by ID.", | ||
security: [ | ||
{ | ||
bearerAuth: [] | ||
} | ||
], | ||
params: z.object({ | ||
id: z.string().describe(AUDIT_LOG_STREAMS.GET_BY_ID.id) | ||
}), | ||
response: { | ||
200: z.object({ | ||
auditLogStream: SanitizedAuditLogStreamSchema.extend({ | ||
headers: z | ||
.object({ | ||
key: z.string(), | ||
value: z.string() | ||
}) | ||
.array() | ||
.optional() | ||
}) | ||
}) | ||
} | ||
}, | ||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), | ||
handler: async (req) => { | ||
const auditLogStream = await server.services.auditLogStream.getById({ | ||
actorId: req.permission.id, | ||
actor: req.permission.type, | ||
actorOrgId: req.permission.orgId, | ||
actorAuthMethod: req.permission.authMethod, | ||
id: req.params.id | ||
}); | ||
|
||
return { auditLogStream }; | ||
} | ||
}); | ||
|
||
server.route({ | ||
method: "GET", | ||
url: "/", | ||
config: { | ||
rateLimit: readLimit | ||
}, | ||
schema: { | ||
description: "List Audit Log Streams.", | ||
security: [ | ||
{ | ||
bearerAuth: [] | ||
} | ||
], | ||
response: { | ||
200: z.object({ | ||
auditLogStreams: SanitizedAuditLogStreamSchema.array() | ||
}) | ||
} | ||
}, | ||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), | ||
handler: async (req) => { | ||
const auditLogStreams = await server.services.auditLogStream.list({ | ||
actorId: req.permission.id, | ||
actor: req.permission.type, | ||
actorOrgId: req.permission.orgId, | ||
actorAuthMethod: req.permission.authMethod | ||
}); | ||
|
||
return { auditLogStreams }; | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
backend/src/ee/services/audit-log-stream/audit-log-stream-dal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { TDbClient } from "@app/db"; | ||
import { TableName } from "@app/db/schemas"; | ||
import { ormify } from "@app/lib/knex"; | ||
|
||
export type TAuditLogStreamDALFactory = ReturnType<typeof auditLogStreamDALFactory>; | ||
|
||
export const auditLogStreamDALFactory = (db: TDbClient) => { | ||
const orm = ormify(db, TableName.AuditLogStream); | ||
|
||
return orm; | ||
}; |
Oops, something went wrong.