mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 04:05:59 +00:00
SYNC: missing audit logs
This commit is contained in:
committed by
Diflow
parent
527c9c8e6e
commit
d3fffd9530
@@ -267,7 +267,9 @@ module.exports = {
|
|||||||
schemaName: select?.from?.name?.schemaName,
|
schemaName: select?.from?.name?.schemaName,
|
||||||
pureName: select?.from?.name?.pureName,
|
pureName: select?.from?.name?.pureName,
|
||||||
sumint1: response?.rows?.length,
|
sumint1: response?.rows?.length,
|
||||||
sessionParam: `${select?.from?.name?.schemaName || '0'}::${select?.from?.name?.pureName}`,
|
sessionParam: `${conid}::${database}::${select?.from?.name?.schemaName || '0'}::${
|
||||||
|
select?.from?.name?.pureName
|
||||||
|
}`,
|
||||||
sessionGroup: auditLogSessionGroup,
|
sessionGroup: auditLogSessionGroup,
|
||||||
message: `Loaded table data from ${select?.from?.name?.pureName}`,
|
message: `Loaded table data from ${select?.from?.name?.pureName}`,
|
||||||
});
|
});
|
||||||
@@ -279,10 +281,22 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
runScript_meta: true,
|
runScript_meta: true,
|
||||||
async runScript({ conid, database, sql, useTransaction }, req) {
|
async runScript({ conid, database, sql, useTransaction, logMessage }, req) {
|
||||||
testConnectionPermission(conid, req);
|
testConnectionPermission(conid, req);
|
||||||
logger.info({ conid, database, sql }, 'Processing script');
|
logger.info({ conid, database, sql }, 'Processing script');
|
||||||
const opened = await this.ensureOpened(conid, database);
|
const opened = await this.ensureOpened(conid, database);
|
||||||
|
sendToAuditLog(req, {
|
||||||
|
category: 'dbop',
|
||||||
|
component: 'DatabaseConnectionsController',
|
||||||
|
event: 'sql.runscript',
|
||||||
|
action: 'runscript',
|
||||||
|
severity: 'info',
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
detail: sql,
|
||||||
|
message: logMessage || `Running SQL script`,
|
||||||
|
});
|
||||||
|
|
||||||
const res = await this.sendRequest(opened, { msgtype: 'runScript', sql, useTransaction });
|
const res = await this.sendRequest(opened, { msgtype: 'runScript', sql, useTransaction });
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
@@ -291,16 +305,53 @@ module.exports = {
|
|||||||
async runOperation({ conid, database, operation, useTransaction }, req) {
|
async runOperation({ conid, database, operation, useTransaction }, req) {
|
||||||
testConnectionPermission(conid, req);
|
testConnectionPermission(conid, req);
|
||||||
logger.info({ conid, database, operation }, 'Processing operation');
|
logger.info({ conid, database, operation }, 'Processing operation');
|
||||||
|
|
||||||
|
sendToAuditLog(req, {
|
||||||
|
category: 'dbop',
|
||||||
|
component: 'DatabaseConnectionsController',
|
||||||
|
event: 'sql.runoperation',
|
||||||
|
action: operation.type,
|
||||||
|
severity: 'info',
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
detail: operation,
|
||||||
|
message: `Running DB operation: ${operation.type}`,
|
||||||
|
});
|
||||||
|
|
||||||
const opened = await this.ensureOpened(conid, database);
|
const opened = await this.ensureOpened(conid, database);
|
||||||
const res = await this.sendRequest(opened, { msgtype: 'runOperation', operation, useTransaction });
|
const res = await this.sendRequest(opened, { msgtype: 'runOperation', operation, useTransaction });
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
collectionData_meta: true,
|
collectionData_meta: true,
|
||||||
async collectionData({ conid, database, options }, req) {
|
async collectionData({ conid, database, options, auditLogSessionGroup }, req) {
|
||||||
testConnectionPermission(conid, req);
|
testConnectionPermission(conid, req);
|
||||||
const opened = await this.ensureOpened(conid, database);
|
const opened = await this.ensureOpened(conid, database);
|
||||||
const res = await this.sendRequest(opened, { msgtype: 'collectionData', options });
|
const res = await this.sendRequest(
|
||||||
|
opened,
|
||||||
|
{ msgtype: 'collectionData', options },
|
||||||
|
{
|
||||||
|
auditLogger:
|
||||||
|
auditLogSessionGroup && options?.pureName
|
||||||
|
? response => {
|
||||||
|
sendToAuditLog(req, {
|
||||||
|
category: 'dbop',
|
||||||
|
component: 'DatabaseConnectionsController',
|
||||||
|
event: 'nosql.collectionData',
|
||||||
|
action: 'select',
|
||||||
|
severity: 'info',
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
pureName: options?.pureName,
|
||||||
|
sumint1: response?.result?.rows?.length,
|
||||||
|
sessionParam: `${conid}::${database}::${options?.pureName}`,
|
||||||
|
sessionGroup: auditLogSessionGroup,
|
||||||
|
message: `Loaded collection data ${options?.pureName}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
}
|
||||||
|
);
|
||||||
return res.result || null;
|
return res.result || null;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -532,7 +583,7 @@ module.exports = {
|
|||||||
database,
|
database,
|
||||||
sessionParam: `${conid}::${database}`,
|
sessionParam: `${conid}::${database}`,
|
||||||
sessionGroup: 'getStructure',
|
sessionGroup: 'getStructure',
|
||||||
message: `Loaded database structure for ${database}`
|
message: `Loaded database structure for ${database}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
return opened.structure;
|
return opened.structure;
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ export class PerspectiveDataLoader {
|
|||||||
pureName,
|
pureName,
|
||||||
aggregate,
|
aggregate,
|
||||||
},
|
},
|
||||||
|
auditLogSessionGroup: 'perspective',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.errorMessage) return response;
|
if (response.errorMessage) return response;
|
||||||
@@ -286,6 +287,7 @@ export class PerspectiveDataLoader {
|
|||||||
conid: props.databaseConfig.conid,
|
conid: props.databaseConfig.conid,
|
||||||
database: props.databaseConfig.database,
|
database: props.databaseConfig.database,
|
||||||
options,
|
options,
|
||||||
|
auditLogSessionGroup: 'perspective',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.errorMessage) return response;
|
if (response.errorMessage) return response;
|
||||||
@@ -359,6 +361,7 @@ export class PerspectiveDataLoader {
|
|||||||
conid: props.databaseConfig.conid,
|
conid: props.databaseConfig.conid,
|
||||||
database: props.databaseConfig.database,
|
database: props.databaseConfig.database,
|
||||||
options,
|
options,
|
||||||
|
auditLogSessionGroup: 'perspective',
|
||||||
});
|
});
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
@@ -86,6 +86,7 @@
|
|||||||
condition: buildConditionForGrid(props),
|
condition: buildConditionForGrid(props),
|
||||||
sort: buildSortForGrid(props),
|
sort: buildSortForGrid(props),
|
||||||
},
|
},
|
||||||
|
auditLogSessionGroup: 'data-grid',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.errorMessage) return response;
|
if (response.errorMessage) return response;
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
<script context="module" lang="ts">
|
<script context="module" lang="ts">
|
||||||
export async function saveScriptToDatabase({ conid, database }, sql, syncModel = true) {
|
export async function saveScriptToDatabase({ conid, database }, sql, syncModel = true, logMessage = null) {
|
||||||
const resp = await apiCall('database-connections/run-script', {
|
const resp = await apiCall('database-connections/run-script', {
|
||||||
conid,
|
conid,
|
||||||
database,
|
database,
|
||||||
sql,
|
sql,
|
||||||
|
logMessage,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { errorMessage } = resp || {};
|
const { errorMessage } = resp || {};
|
||||||
|
|||||||
Reference in New Issue
Block a user