feat(audit-log): added doc for export endpoint

This commit is contained in:
Akhil Mohan
2023-11-22 17:04:09 +05:30
parent 9d9e830d73
commit 89ae3070ce
7 changed files with 445 additions and 47 deletions
+182 -3
View File
@@ -306,12 +306,77 @@
}, },
"/api/v1/workspace/{workspaceId}/audit-logs": { "/api/v1/workspace/{workspaceId}/audit-logs": {
"get": { "get": {
"description": "", "summary": "Return audit logs",
"description": "Return audit logs",
"parameters": [ "parameters": [
{ {
"name": "workspaceId", "name": "workspaceId",
"in": "path", "in": "path",
"required": true, "required": true,
"schema": {
"type": "string"
},
"description": "ID of the workspace where to get folders from"
},
{
"name": "offset",
"description": "Number of versions to skip",
"required": false,
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "limit",
"description": "Maximum number of versions to return",
"required": false,
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "startDate",
"description": "Filter logs from the provided date",
"required": false,
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "endDate",
"description": "Filter logs till the provided date",
"required": false,
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "eventType",
"description": "Type of event",
"required": false,
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "userAgentType",
"description": "Type of event",
"required": false,
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "actor",
"description": "Source of operation. It can be user, service token etc",
"required": false,
"in": "query",
"schema": { "schema": {
"type": "string" "type": "string"
} }
@@ -319,9 +384,31 @@
], ],
"responses": { "responses": {
"200": { "200": {
"description": "OK" "description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"auditLogs": {
"type": "array",
"items": {
"$ref": "#/components/schemas/AuditLog"
},
"description": "List of audit log"
}
}
}
}
}
} }
} },
"security": [
{
"apiKeyAuth": [],
"bearerAuth": []
}
]
} }
}, },
"/api/v1/workspace/{workspaceId}/audit-logs/filters/actors": { "/api/v1/workspace/{workspaceId}/audit-logs/filters/actors": {
@@ -1132,6 +1219,43 @@
} }
} }
}, },
"/api/v1/admin/config": {
"get": {
"description": "",
"responses": {
"200": {
"description": "OK"
}
}
},
"patch": {
"description": "",
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/v1/admin/signup": {
"post": {
"description": "",
"parameters": [
{
"name": "user-agent",
"in": "header",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/v1/bot/{workspaceId}": { "/api/v1/bot/{workspaceId}": {
"get": { "get": {
"description": "", "description": "",
@@ -6864,6 +6988,61 @@
"example": "2023-01-13T14:16:12.210Z" "example": "2023-01-13T14:16:12.210Z"
} }
} }
},
"AuditLog": {
"type": "object",
"properties": {
"actor": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": ""
},
"metadata": {
"type": "object",
"properties": {}
}
}
},
"organization": {
"type": "string",
"example": ""
},
"workspace": {
"type": "string",
"example": ""
},
"ipAddress": {
"type": "string",
"example": ""
},
"event": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": ""
},
"metadata": {
"type": "object",
"properties": {}
}
}
},
"userAgent": {
"type": "string",
"example": ""
},
"userAgentType": {
"type": "string",
"example": ""
},
"expiresAt": {
"type": "string",
"example": ""
}
}
} }
}, },
"securitySchemes": { "securitySchemes": {
@@ -567,6 +567,83 @@ export const rollbackWorkspaceSecretSnapshot = async (req: Request, res: Respons
* @param res * @param res
*/ */
export const getWorkspaceAuditLogs = async (req: Request, res: Response) => { export const getWorkspaceAuditLogs = async (req: Request, res: Response) => {
/*
#swagger.summary = 'Return audit logs'
#swagger.description = 'Return audit logs'
#swagger.security = [{
"apiKeyAuth": [],
"bearerAuth": []
}]
#swagger.parameters['workspaceId'] = {
"description": "ID of the workspace where to get folders from",
"required": true,
"type": "string",
"in": "path"
}
#swagger.parameters['offset'] = {
"description": "Number of versions to skip",
"required": false,
"type": "string"
}
#swagger.parameters['limit'] = {
"description": "Maximum number of versions to return",
"required": false,
"type": "string"
}
#swagger.parameters['startDate'] = {
"description": "Filter logs from the provided date",
"required": false,
"type": "string"
}
#swagger.parameters['endDate'] = {
"description": "Filter logs till the provided date",
"required": false,
"type": "string"
}
#swagger.parameters['eventType'] = {
"description": "Type of event",
"required": false,
"type": "string",
}
#swagger.parameters['userAgentType'] = {
"description": "Type of event",
"required": false,
"type": "string",
}
#swagger.parameters['actor'] = {
"description": "Source of operation. It can be user, service token etc",
"required": false,
"type": "string"
}
#swagger.responses[200] = {
content: {
"application/json": {
schema: {
"type": "object",
"properties": {
"auditLogs": {
"type": "array",
"items": {
$ref: "#/components/schemas/AuditLog",
},
"description": "List of audit log"
},
}
}
}
}
}
*/
const { const {
query: { limit, offset, endDate, eventType, startDate, userAgentType, actor }, query: { limit, offset, endDate, eventType, startDate, userAgentType, actor },
params: { workspaceId } params: { workspaceId }
+57 -41
View File
@@ -12,32 +12,32 @@ const generateOpenAPISpec = async () => {
const doc = { const doc = {
info: { info: {
title: "Infisical API", title: "Infisical API",
description: "List of all available APIs that can be consumed", description: "List of all available APIs that can be consumed"
}, },
host: ["https://infisical.com"], host: ["https://infisical.com"],
servers: [ servers: [
{ {
url: "https://app.infisical.com", url: "https://app.infisical.com",
description: "Production server", description: "Production server"
}, },
{ {
url: "http://localhost:8080", url: "http://localhost:8080",
description: "Local server", description: "Local server"
}, }
], ],
securityDefinitions: { securityDefinitions: {
bearerAuth: { bearerAuth: {
type: "http", type: "http",
scheme: "bearer", scheme: "bearer",
bearerFormat: "JWT", bearerFormat: "JWT",
description: "A service token in Infisical", description: "A service token in Infisical"
}, },
apiKeyAuth: { apiKeyAuth: {
type: "apiKey", type: "apiKey",
in: "header", in: "header",
name: "X-API-Key", name: "X-API-Key",
description: "An API Key in Infisical", description: "An API Key in Infisical"
}, }
}, },
definitions: { definitions: {
CurrentUser: { CurrentUser: {
@@ -50,7 +50,7 @@ const generateOpenAPISpec = async () => {
iv: "iv_of_enc_nacl_private_key", iv: "iv_of_enc_nacl_private_key",
tag: "tag_of_enc_nacl_private_key", tag: "tag_of_enc_nacl_private_key",
updatedAt: "2023-01-13T14:16:12.210Z", updatedAt: "2023-01-13T14:16:12.210Z",
createdAt: "2023-01-13T14:16:12.210Z", createdAt: "2023-01-13T14:16:12.210Z"
}, },
Membership: { Membership: {
user: { user: {
@@ -60,10 +60,10 @@ const generateOpenAPISpec = async () => {
lastName: "Doe", lastName: "Doe",
publicKey: "johns_nacl_public_key", publicKey: "johns_nacl_public_key",
updatedAt: "2023-01-13T14:16:12.210Z", updatedAt: "2023-01-13T14:16:12.210Z",
createdAt: "2023-01-13T14:16:12.210Z", createdAt: "2023-01-13T14:16:12.210Z"
}, },
workspace: "", workspace: "",
role: "admin", role: "admin"
}, },
MembershipOrg: { MembershipOrg: {
user: { user: {
@@ -73,33 +73,35 @@ const generateOpenAPISpec = async () => {
lastName: "Doe", lastName: "Doe",
publicKey: "johns_nacl_public_key", publicKey: "johns_nacl_public_key",
updatedAt: "2023-01-13T14:16:12.210Z", updatedAt: "2023-01-13T14:16:12.210Z",
createdAt: "2023-01-13T14:16:12.210Z", createdAt: "2023-01-13T14:16:12.210Z"
}, },
organization: "", organization: "",
role: "owner", role: "owner",
status: "accepted", status: "accepted"
}, },
Organization: { Organization: {
_id: "", _id: "",
name: "Acme Corp.", name: "Acme Corp.",
customerId: "", customerId: ""
}, },
Project: { Project: {
name: "My Project", name: "My Project",
organization: "", organization: "",
environments: [{ environments: [
name: "development", {
slug: "dev", name: "development",
}], slug: "dev"
}
]
}, },
ProjectKey: { ProjectKey: {
encryptedkey: "", encryptedkey: "",
nonce: "", nonce: "",
sender: { sender: {
publicKey: "senders_nacl_public_key", publicKey: "senders_nacl_public_key"
}, },
receiver: "", receiver: "",
workspace: "", workspace: ""
}, },
CreateSecret: { CreateSecret: {
type: "shared", type: "shared",
@@ -111,7 +113,7 @@ const generateOpenAPISpec = async () => {
secretValueTag: "", secretValueTag: "",
secretCommentCiphertext: "", secretCommentCiphertext: "",
secretCommentIV: "", secretCommentIV: "",
secretCommentTag: "", secretCommentTag: ""
}, },
UpdateSecret: { UpdateSecret: {
id: "", id: "",
@@ -123,12 +125,12 @@ const generateOpenAPISpec = async () => {
secretValueTag: "", secretValueTag: "",
secretCommentCiphertext: "", secretCommentCiphertext: "",
secretCommentIV: "", secretCommentIV: "",
secretCommentTag: "", secretCommentTag: ""
}, },
Secret: { Secret: {
_id: "", _id: "",
version: 1, version: 1,
workspace : "", workspace: "",
type: "shared", type: "shared",
user: null, user: null,
secretKeyCiphertext: "", secretKeyCiphertext: "",
@@ -141,7 +143,7 @@ const generateOpenAPISpec = async () => {
secretCommentIV: "", secretCommentIV: "",
secretCommentTag: "", secretCommentTag: "",
updatedAt: "2023-01-13T14:16:12.210Z", updatedAt: "2023-01-13T14:16:12.210Z",
createdAt: "2023-01-13T14:16:12.210Z", createdAt: "2023-01-13T14:16:12.210Z"
}, },
RawSecret: { RawSecret: {
_id: "abc123", _id: "abc123",
@@ -167,12 +169,10 @@ const generateOpenAPISpec = async () => {
_id: "", _id: "",
email: "[email protected]", email: "[email protected]",
firstName: "John", firstName: "John",
lastName: "Doe", lastName: "Doe"
}, },
workspace: "", workspace: "",
actionNames: [ actionNames: ["addSecrets"],
"addSecrets",
],
actions: [ actions: [
{ {
name: "addSecrets", name: "addSecrets",
@@ -181,24 +181,24 @@ const generateOpenAPISpec = async () => {
payload: [ payload: [
{ {
oldSecretVersion: "", oldSecretVersion: "",
newSecretVersion: "", newSecretVersion: ""
}, }
], ]
}, }
], ],
channel: "cli", channel: "cli",
ipAddress: "192.168.0.1", ipAddress: "192.168.0.1",
updatedAt: "2023-01-13T14:16:12.210Z", updatedAt: "2023-01-13T14:16:12.210Z",
createdAt: "2023-01-13T14:16:12.210Z", createdAt: "2023-01-13T14:16:12.210Z"
}, },
SecretSnapshot: { SecretSnapshot: {
workspace: "", workspace: "",
version: 1, version: 1,
secretVersions: [ secretVersions: [
{ {
_id: "", _id: ""
}, }
], ]
}, },
SecretVersion: { SecretVersion: {
_id: "", _id: "",
@@ -214,7 +214,7 @@ const generateOpenAPISpec = async () => {
secretKeyTag: "", secretKeyTag: "",
secretValueCiphertext: "", secretValueCiphertext: "",
secretValueIV: "", secretValueIV: "",
secretValueTag: "", secretValueTag: ""
}, },
ServiceTokenData: { ServiceTokenData: {
_id: "", _id: "",
@@ -224,16 +224,32 @@ const generateOpenAPISpec = async () => {
user: { user: {
_id: "", _id: "",
firstName: "", firstName: "",
lastName: "", lastName: ""
}, },
expiresAt: "2023-01-13T14:16:12.210Z", expiresAt: "2023-01-13T14:16:12.210Z",
encryptedKey: "", encryptedKey: "",
iv: "", iv: "",
tag: "", tag: "",
updatedAt: "2023-01-13T14:16:12.210Z", updatedAt: "2023-01-13T14:16:12.210Z",
createdAt: "2023-01-13T14:16:12.210Z", createdAt: "2023-01-13T14:16:12.210Z"
}, },
}, AuditLog: {
actor: {
type: "",
metadata: {}
},
organization: "",
workspace: "",
ipAddress: "",
event: {
type: "",
metadata: {}
},
userAgent: "",
userAgentType: "",
expiresAt: ""
}
}
}; };
const outputJSONFile = "../spec.json"; const outputJSONFile = "../spec.json";
@@ -243,6 +259,6 @@ const generateOpenAPISpec = async () => {
const spec = await swaggerAutogen(outputJSONFile, endpointsFiles, doc); const spec = await swaggerAutogen(outputJSONFile, endpointsFiles, doc);
await fs.writeFile(outputYAMLFile, yaml.dump(spec.data)); await fs.writeFile(outputYAMLFile, yaml.dump(spec.data));
} };
generateOpenAPISpec(); generateOpenAPISpec();
@@ -0,0 +1,4 @@
---
title: "Export"
openapi: "GET /api/v1/{workspaceId}/audit-logs"
---
@@ -1,4 +1,4 @@
--- ---
title: "Create" title: "Create"
openapi: "POST /api/v2/workspace/{workspaceId}/environments" openapi: "POST /api/v1/workspace/{workspaceId}/environments"
--- ---
+4
View File
@@ -380,6 +380,10 @@
{ {
"group": "Service Tokens", "group": "Service Tokens",
"pages": ["api-reference/endpoints/service-tokens/get"] "pages": ["api-reference/endpoints/service-tokens/get"]
},
{
"group": "Audit Logs",
"pages": ["api-reference/endpoints/audit-logs/export-audit-log"]
} }
] ]
}, },
+119 -1
View File
@@ -192,16 +192,73 @@ paths:
description: Version of secret snapshot to roll back to description: Version of secret snapshot to roll back to
/api/v1/workspace/{workspaceId}/audit-logs: /api/v1/workspace/{workspaceId}/audit-logs:
get: get:
description: '' summary: Return audit logs
description: Return audit logs
parameters: parameters:
- name: workspaceId - name: workspaceId
in: path in: path
required: true required: true
schema: schema:
type: string type: string
description: ID of the workspace where to get folders from
- name: offset
description: Number of versions to skip
required: false
in: query
schema:
type: string
- name: limit
description: Maximum number of versions to return
required: false
in: query
schema:
type: string
- name: startDate
description: Filter logs from the provided date
required: false
in: query
schema:
type: string
- name: endDate
description: Filter logs till the provided date
required: false
in: query
schema:
type: string
- name: eventType
description: Type of event
required: false
in: query
schema:
type: string
- name: userAgentType
description: Type of event
required: false
in: query
schema:
type: string
- name: actor
description: Source of operation. It can be user, service token etc
required: false
in: query
schema:
type: string
responses: responses:
'200': '200':
description: OK description: OK
content:
application/json:
schema:
type: object
properties:
auditLogs:
type: array
items:
$ref: '#/components/schemas/AuditLog'
description: List of audit log
security:
- apiKeyAuth: []
bearerAuth: []
/api/v1/workspace/{workspaceId}/audit-logs/filters/actors: /api/v1/workspace/{workspaceId}/audit-logs/filters/actors:
get: get:
description: '' description: ''
@@ -691,6 +748,28 @@ paths:
responses: responses:
'200': '200':
description: OK description: OK
/api/v1/admin/config:
get:
description: ''
responses:
'200':
description: OK
patch:
description: ''
responses:
'200':
description: OK
/api/v1/admin/signup:
post:
description: ''
parameters:
- name: user-agent
in: header
schema:
type: string
responses:
'200':
description: OK
/api/v1/bot/{workspaceId}: /api/v1/bot/{workspaceId}:
get: get:
description: '' description: ''
@@ -4342,6 +4421,45 @@ components:
createdAt: createdAt:
type: string type: string
example: '2023-01-13T14:16:12.210Z' example: '2023-01-13T14:16:12.210Z'
AuditLog:
type: object
properties:
actor:
type: object
properties:
type:
type: string
example: ''
metadata:
type: object
properties: {}
organization:
type: string
example: ''
workspace:
type: string
example: ''
ipAddress:
type: string
example: ''
event:
type: object
properties:
type:
type: string
example: ''
metadata:
type: object
properties: {}
userAgent:
type: string
example: ''
userAgentType:
type: string
example: ''
expiresAt:
type: string
example: ''
securitySchemes: securitySchemes:
bearerAuth: bearerAuth:
type: http type: http