{
  "swagger": "2.0",
  "info": {
    "title": "TiDB Cloud Starter and Essential Database Audit Logging Open API",
    "description": "TiDB Cloud Starter and Essential Database Audit Logging Open API",
    "version": "v1beta1"
  },
  "tags": [
    {
      "name": "AuditLogService"
    }
  ],
  "host": "serverless.tidbapi.com",
  "schemes": [
    "https"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/v1beta1/clusters/{clusterId}/auditlogs": {
      "get": {
        "summary": "List database audit logs.",
        "operationId": "AuditLogService_ListAuditLogs",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/ListAuditLogsResponseV1"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "clusterId",
            "description": "Required. The ID of the cluster.",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "date",
            "description": "Optional. The UTC date of the audit logs in the format of `YYYY-MM-DD` (e.g. 2025-01-01).",
            "in": "query",
            "required": false,
            "type": "string"
          },
          {
            "name": "pageSize",
            "description": "Optional. The maximum number to return, default is 100, and the maximum is 1000.",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int32"
          },
          {
            "name": "pageToken",
            "description": "Optional. The page token from the previous response for pagination.",
            "in": "query",
            "required": false,
            "type": "string"
          }
        ],
        "tags": [
          "AuditLogService"
        ]
      }
    },
    "/v1beta1/clusters/{clusterId}/auditlogs:download": {
      "post": {
        "summary": "Generate audit logs download url",
        "operationId": "AuditLogService_DownloadAuditLogs",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/DownloadAuditLogsResponseV1"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "clusterId",
            "description": "Required. The ID of the cluster.",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/AuditLogService.DownloadAuditLogsBody"
            }
          }
        ],
        "tags": [
          "AuditLogService"
        ]
      }
    },
    "/v1beta1/clusters/{clusterId}/auditlogs/filterRules/{name}": {
      "get": {
        "summary": "Get audit log filter rule.",
        "operationId": "AuditLogService_GetAuditLogFilterRule",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/AuditLogFilterRuleV1"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "clusterId",
            "description": "Required.",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "name",
            "description": "Required. The name of the filter rule.",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "tags": [
          "AuditLogService"
        ]
      },
      "delete": {
        "summary": "Delete audit log filter rule.",
        "operationId": "AuditLogService_DeleteAuditLogFilterRule",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/AuditLogFilterRuleV1"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "clusterId",
            "description": "Required.",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "name",
            "description": "Required. The name of the filter rule.",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "tags": [
          "AuditLogService"
        ]
      },
      "patch": {
        "summary": "Update audit log filter rule.",
        "operationId": "AuditLogService_UpdateAuditLogFilterRule",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/AuditLogFilterRuleV1"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "clusterId",
            "description": "Required.",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "name",
            "description": "Required. The name of the filter rule.",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/AuditLogService.UpdateAuditLogFilterRuleBody"
            }
          }
        ],
        "tags": [
          "AuditLogService"
        ]
      }
    },
    "/v1beta1/clusters/{clusterId}/auditlogs/filterRules": {
      "get": {
        "summary": "List audit log filter rules.",
        "operationId": "AuditLogService_ListAuditLogFilterRules",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/ListAuditLogFilterRulesResponseV1"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "clusterId",
            "description": "Required.",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "tags": [
          "AuditLogService"
        ]
      },
      "post": {
        "summary": "Create audit log filter rule.",
        "operationId": "AuditLogService_CreateAuditLogFilterRule",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/AuditLogFilterRuleV1"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/Status"
            }
          }
        },
        "parameters": [
          {
            "name": "clusterId",
            "description": "Required.",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/AuditLogService.CreateAuditLogFilterRuleBody"
            }
          }
        ],
        "tags": [
          "AuditLogService"
        ]
      }
    }
  },
  "definitions": {
    "Any": {
      "type": "object",
      "properties": {
        "@type": {
          "type": "string"
        }
      },
      "additionalProperties": {}
    },
    "AuditLogFilterRuleV1": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "description": "Required. Unique name of the filter rule within a cluster."
        },
        "users": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "title": "Required. Database users in the format <user>@<host> or <user> (host defaults to %), e.g., %@%, 4C3z3cdMX8iXks5.root"
        },
        "filters": {
          "type": "array",
          "items": {
            "type": "object",
            "$ref": "#/definitions/AuditLogFilterV1"
          },
          "description": "Required. List of filters combined with an OR relationship. Set filters to [{}] will filter all logs."
        },
        "disabled": {
          "type": "boolean",
          "description": "OUTPUT_ONLY. Indicates whether the filter rule is disabled.",
          "readOnly": true
        }
      },
      "required": [
        "name",
        "users",
        "filters"
      ]
    },
    "AuditLogFilterV1": {
      "type": "object",
      "properties": {
        "classes": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "OPTIONAL. Classes to include in the filter combined with an OR relationship."
        },
        "tables": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "OPTIONAL. Tables to include in the filter combined with an OR relationship."
        },
        "statusCodes": {
          "type": "array",
          "items": {
            "type": "integer",
            "format": "int32"
          },
          "description": "OPTIONAL. Status codes to include in the filter combined with an OR relationship."
        }
      },
      "description": "Message for filter, only the entry matching all the conditions will be audit logged."
    },
    "AuditLogService.CreateAuditLogFilterRuleBody": {
      "type": "object",
      "properties": {
        "filterRule": {
          "description": "Required. The filter rule to create.",
          "allOf": [
            {
              "$ref": "#/definitions/AuditLogFilterRuleV1"
            }
          ]
        }
      },
      "required": [
        "filterRule"
      ]
    },
    "AuditLogService.DownloadAuditLogsBody": {
      "type": "object",
      "properties": {
        "auditLogNames": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Required. The name of the audit logs to download. Up to 100 audit logs can be downloaded at the same time."
        }
      },
      "required": [
        "auditLogNames"
      ]
    },
    "AuditLogService.UpdateAuditLogFilterRuleBody": {
      "type": "object",
      "properties": {
        "filters": {
          "type": "array",
          "items": {
            "type": "object",
            "$ref": "#/definitions/AuditLogFilterV1"
          },
          "description": "OPTIONAL. List of filters combined with an OR relationship. Set filters to [{}] will filter all logs."
        },
        "users": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "title": "Required. Database users in the format <user>@<host> or <user> (host defaults to %), e.g., %@%, 4C3z3cdMX8iXks5.root"
        },
        "disabled": {
          "type": "boolean",
          "x-nullable": true,
          "description": "OPTIONAL. Indicates whether the filter rule is disabled."
        }
      }
    },
    "AuditLogV1": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "description": "The name of the audit log."
        },
        "size": {
          "type": "integer",
          "format": "int64",
          "description": "The size in bytes of the audit log."
        },
        "url": {
          "type": "string",
          "description": "download url of the audit log."
        }
      }
    },
    "DownloadAuditLogsResponseV1": {
      "type": "object",
      "properties": {
        "auditLogs": {
          "type": "array",
          "items": {
            "type": "object",
            "$ref": "#/definitions/AuditLogV1"
          },
          "description": "The audit logs with the download url."
        }
      }
    },
    "ListAuditLogFilterRulesResponseV1": {
      "type": "object",
      "properties": {
        "filterRules": {
          "type": "array",
          "items": {
            "type": "object",
            "$ref": "#/definitions/AuditLogFilterRuleV1"
          }
        }
      }
    },
    "ListAuditLogsResponseV1": {
      "type": "object",
      "properties": {
        "auditLogs": {
          "type": "array",
          "items": {
            "type": "object",
            "$ref": "#/definitions/AuditLogV1"
          },
          "description": "The audit logs without the download url."
        },
        "nextPageToken": {
          "type": "string",
          "description": "Token provided to retrieve the next page of results."
        }
      }
    },
    "Status": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        },
        "details": {
          "type": "array",
          "items": {
            "type": "object",
            "$ref": "#/definitions/Any"
          }
        }
      }
    }
  }
}
