Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature]: Support fast SQL auditing #315

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module.exports = {
const res = {};
for (let i = 0; i < 10; i++) {
res[`/v${i}`] = {
target: 'http://10.186.60.56:10001',
target: 'http://124.70.158.246:8889',
secure: false,
changeOrigin: true,
ws: true,
Expand Down
31 changes: 31 additions & 0 deletions src/api/SqlManage/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
GetSqlManageListFilterSourceEnum,
GetSqlManageListFilterAuditLevelEnum,
GetSqlManageListFilterStatusEnum
} from './index.enum';

import { IGetSqlManageListResp } from '../common.d';

export interface IGetSqlManageListParams {
fuzzy_search_sql_fingerprint?: string;

filter_assignee?: string;

filter_instance_name?: string;

filter_source?: GetSqlManageListFilterSourceEnum;

filter_audit_level?: GetSqlManageListFilterAuditLevelEnum;

filter_last_audit_start_time_from?: string;

filter_last_audit_start_time_to?: string;

filter_status?: GetSqlManageListFilterStatusEnum;

page_index: number;

page_size: number;
}

export interface IGetSqlManageListReturn extends IGetSqlManageListResp {}
25 changes: 25 additions & 0 deletions src/api/SqlManage/index.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* tslint:disable no-duplicate-string */

export enum GetSqlManageListFilterSourceEnum {
'audit_plan' = 'audit_plan',

'api_audit' = 'api_audit'
}

export enum GetSqlManageListFilterAuditLevelEnum {
'normal' = 'normal',

'notice' = 'notice',

'warn' = 'warn',

'error' = 'error'
}

export enum GetSqlManageListFilterStatusEnum {
'unhandled' = 'unhandled',

'solved' = 'solved',

'ignored' = 'ignored'
}
28 changes: 28 additions & 0 deletions src/api/SqlManage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* tslint:disable no-identical-functions */
/* tslint:disable no-useless-cast */
/* tslint:disable no-unnecessary-type-assertion */
/* tslint:disable no-big-function */
/* tslint:disable no-duplicate-string */
import ServiceBase from '../Service.base';
import { AxiosRequestConfig } from 'axios';

import { IGetSqlManageListParams, IGetSqlManageListReturn } from './index.d';

class SqlManageService extends ServiceBase {
public GetSqlManageList(
params: IGetSqlManageListParams,
options?: AxiosRequestConfig
) {
const paramsData = this.cloneDeep(params);
const project_name = paramsData.project_name;
delete paramsData.project_name;

return this.get<IGetSqlManageListReturn>(
`/v1/projects/${project_name}/sql_manages`,
paramsData,
options
);
}
}

export default new SqlManageService();
116 changes: 113 additions & 3 deletions src/api/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,14 @@ export interface ICreateRuleTemplateReqV1 {
rule_template_name?: string;
}

export interface ICreateSQLAuditRecordResV1 {
code?: number;

data?: ISQLAuditRecordResData;

message?: string;
}

export interface ICreateSyncInstanceTaskReqV1 {
db_type: string;

Expand Down Expand Up @@ -1229,6 +1237,32 @@ export interface IGetSQLAnalysisDataResItemV1 {
table_metas?: ITableMeta[];
}

export interface IGetSQLAuditRecordResV1 {
code?: number;

data?: ISQLAuditRecord;

message?: string;
}

export interface IGetSQLAuditRecordTagTipsResV1 {
code?: number;

data?: string[];

message?: string;
}

export interface IGetSQLAuditRecordsResV1 {
code?: number;

data?: ISQLAuditRecord[];

message?: string;

total_nums?: number;
}

export interface IGetSQLEInfoResDataV1 {
logo_url?: string;

Expand Down Expand Up @@ -1275,6 +1309,16 @@ export interface IGetSqlExecutionFailPercentResV1 {
message?: string;
}

export interface IGetSqlManageListResp {
code?: number;

data?: ISqlManage[];

message?: string;

total_nums?: number;
}

export interface IGetSyncInstanceTaskListResV1 {
code?: number;

Expand Down Expand Up @@ -2091,6 +2135,34 @@ export interface ISMTPConfigurationResV1 {
smtp_username?: string;
}

export interface ISQLAuditRecord {
created_at?: string;

creator?: string;

instance?: ISQLAuditRecordInstance;

sql_audit_record_id?: string;

sql_audit_status?: string;

tags?: string[];

task?: IAuditTaskResV1;
}

export interface ISQLAuditRecordInstance {
db_host?: string;

db_port?: string;
}

export interface ISQLAuditRecordResData {
sql_audit_record_id?: string;

task?: IAuditTaskResV1;
}

export interface ISQLExplain {
classic_result?: IExplainClassicResult;

Expand Down Expand Up @@ -2141,6 +2213,38 @@ export interface ISqlExecutionFailPercent {
percent?: number;
}

export interface ISqlManage {
appear_num?: number;

assignee?: string;

audit_result?: string;

first_appear_time?: string;

id?: number;

instance?: string;

last_appear_time?: string;

remark?: string;

source?: string;

sql?: string;

sql_fingerprint?: string;

sql_manage_bad_num?: number;

sql_manage_optimized_num?: number;

sql_manage_total_num?: number;

status?: string;
}

export interface IStatisticAuditPlanResV1 {
code?: number;

Expand Down Expand Up @@ -2424,11 +2528,11 @@ export interface IUpdateDingTalkConfigurationReqV1 {
}

export interface IUpdateFeishuConfigurationReqV1 {
app_id?: string;
app_id: string;

app_secret?: string;
app_secret: string;

is_feishu_notification_enabled?: boolean;
is_feishu_notification_enabled: boolean;
}

export interface IUpdateInstanceReqV1 {
Expand Down Expand Up @@ -2507,6 +2611,12 @@ export interface IUpdateSMTPConfigurationReqV1 {
smtp_username?: string;
}

export interface IUpdateSQLAuditRecordReqV1 {
sql_audit_record_id?: string;

tags?: string[];
}

export interface IUpdateSyncInstanceTaskReqV1 {
global_rule_template?: string;

Expand Down
4 changes: 3 additions & 1 deletion src/api/instance/index.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
export enum getInstanceTipListV1FunctionalModuleEnum {
'create_audit_plan' = 'create_audit_plan',

'create_workflow' = 'create_workflow'
'create_workflow' = 'create_workflow',

'sql_manage' = 'sql_manage'
}
73 changes: 73 additions & 0 deletions src/api/sql_audit_record/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { getSQLAuditRecordsV1FilterSqlAuditStatusEnum } from './index.enum';

import {
IGetSQLAuditRecordsResV1,
ICreateSQLAuditRecordResV1,
IGetSQLAuditRecordTagTipsResV1,
IGetSQLAuditRecordResV1,
IUpdateSQLAuditRecordReqV1,
IBaseRes
} from '../common.d';

export interface IGetSQLAuditRecordsV1Params {
fuzzy_search_tags?: string;

filter_sql_audit_status?: getSQLAuditRecordsV1FilterSqlAuditStatusEnum;

filter_instance_name?: string;

filter_create_time_from?: string;

filter_create_time_to?: string;

page_index: number;

page_size: number;

project_name: string;
}

export interface IGetSQLAuditRecordsV1Return extends IGetSQLAuditRecordsResV1 {}

export interface ICreateSQLAuditRecordV1Params {
project_name: string;

instance_name?: string;

instance_schema?: string;

db_type?: string;

sqls?: string;

input_sql_file?: any;

input_mybatis_xml_file?: any;

input_zip_file?: any;
}

export interface ICreateSQLAuditRecordV1Return
extends ICreateSQLAuditRecordResV1 {}

export interface IGetSQLAuditRecordTagTipsV1Params {
project_name: string;
}

export interface IGetSQLAuditRecordTagTipsV1Return
extends IGetSQLAuditRecordTagTipsResV1 {}

export interface IGetSQLAuditRecordV1Params {
project_name: string;

sql_audit_record_id: string;
}

export interface IGetSQLAuditRecordV1Return extends IGetSQLAuditRecordResV1 {}

export interface IUpdateSQLAuditRecordV1Params
extends IUpdateSQLAuditRecordReqV1 {
project_name: string;
}

export interface IUpdateSQLAuditRecordV1Return extends IBaseRes {}
7 changes: 7 additions & 0 deletions src/api/sql_audit_record/index.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* tslint:disable no-duplicate-string */

export enum getSQLAuditRecordsV1FilterSqlAuditStatusEnum {
'auditing' = 'auditing',

'successfully' = 'successfully'
}
Loading