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

feat: 新增审计系统 #782

Merged
merged 59 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
92c8605
feat: operation log server 初始化
ZihanChen821 Aug 4, 2023
324e77f
fix
ZihanChen821 Aug 7, 2023
8607a8e
feat: cli增加operation-log service
ZihanChen821 Aug 7, 2023
3ffddca
fix cli and proto
ZihanChen821 Aug 7, 2023
73f3e8d
fix appDirs add operation-log
ZihanChen821 Aug 7, 2023
12b1604
fix entity
ZihanChen821 Aug 7, 2023
49cf402
fix: metaData修改为json
ZihanChen821 Aug 8, 2023
548929c
fix: cli config file
ZihanChen821 Aug 8, 2023
efc707f
add operation type
ZihanChen821 Aug 8, 2023
6b14ad7
fix proto build speed
ZihanChen821 Aug 8, 2023
bcb5e5a
feat: 搜索接口开发
ZihanChen821 Aug 9, 2023
d5c0c76
搜索操作日志接口
ZihanChen821 Aug 9, 2023
1fa1dcc
fix: 搜索过滤功能及代码重构
ZihanChen821 Aug 10, 2023
10cac44
Merge branch 'master' into feat-opeation-log-server
ZihanChen821 Aug 10, 2023
be4ee26
fix packageJson
ZihanChen821 Aug 10, 2023
5bbe9de
feat: 添加其他页面的操作日志
ZihanChen821 Aug 10, 2023
5b2e4ab
注释
ZihanChen821 Aug 10, 2023
b3dae7f
portal-web 新增operation-log client调用
ZihanChen821 Aug 10, 2023
719fbd7
feat 门户系统埋点
ZihanChen821 Aug 11, 2023
dffd247
Merge branch 'master' into feat-opeation-log-server
ZihanChen821 Aug 11, 2023
278199e
feat: 管理系统新增埋点
ZihanChen821 Aug 14, 2023
98dd7ea
feat: 新增登录登出埋点
ZihanChen821 Aug 14, 2023
66c2ff9
test: 增加测试用例
ZihanChen821 Aug 14, 2023
675b913
Merge branch 'master' into feat-opeation-log-server
ZihanChen821 Aug 14, 2023
8ef6926
fix
ZihanChen821 Aug 14, 2023
f8e4a39
feat: 完善cli配置文件
ZihanChen821 Aug 14, 2023
70505c7
添加env: OPERATION_LOG_DEPLOYED
ZihanChen821 Aug 14, 2023
09a4c64
feat: 新增cli 测试用例
ZihanChen821 Aug 15, 2023
f3800cc
refactor: 去除common中配置,收敛到operationLog配置文件内
ZihanChen821 Aug 15, 2023
377a979
增加操作详情展示
ZihanChen821 Aug 15, 2023
c37913c
add config file
ZihanChen821 Aug 15, 2023
58b2885
fix mock api
ZihanChen821 Aug 15, 2023
78aa2ac
新增operation-log文档
ZihanChen821 Aug 15, 2023
841cbfe
fix docs
ZihanChen821 Aug 15, 2023
0abda7e
feat: 新增埋点
ZihanChen821 Aug 15, 2023
b665ee0
Merge branch 'master' into feat-opeation-log-server
ZihanChen821 Aug 16, 2023
ae1e95e
fix
ZihanChen821 Aug 16, 2023
5b85dbb
fix: 展示id以及修复租户过滤user逻辑
ZihanChen821 Aug 16, 2023
de0b7b5
fix operation code
ZihanChen821 Aug 16, 2023
9bc8db2
fix 测试用例
ZihanChen821 Aug 16, 2023
3fd276c
fix api mock
ZihanChen821 Aug 16, 2023
e640723
review: 修改review问题
ZihanChen821 Aug 16, 2023
245042f
Merge branch 'master' into feat-opeation-log-server
ZihanChen821 Aug 16, 2023
4686f29
style: 改文案
ZihanChen821 Aug 16, 2023
c53983e
fix: migration sql
ZihanChen821 Aug 17, 2023
ae4db19
refactor: 修改服务名为audit-server
ZihanChen821 Aug 17, 2023
238ef77
test: fix error
ZihanChen821 Aug 17, 2023
ffb6d59
changeset
ZihanChen821 Aug 18, 2023
feebea8
fix
ZihanChen821 Aug 18, 2023
e6ce06a
fix text
ZihanChen821 Aug 18, 2023
bf86456
fix code review
ZihanChen821 Aug 21, 2023
521f04a
fix
ZihanChen821 Aug 21, 2023
5525534
callLog 加 await
ZihanChen821 Aug 22, 2023
fbcbb6c
Merge branch 'master' into feat-opeation-log-server
ZihanChen821 Aug 22, 2023
0f4c840
update setJobTimeLimit proto
ZihanChen821 Aug 22, 2023
2e3ec96
Merge branch 'master' into feat-opeation-log-server
ZihanChen821 Aug 24, 2023
6e1d097
fix: 修复时间筛选传参错误
ZihanChen821 Aug 25, 2023
8e13e38
Merge branch 'master' into feat-opeation-log-server
ZihanChen821 Aug 27, 2023
02d1eab
lint: 代码格式
ZihanChen821 Aug 28, 2023
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
5 changes: 5 additions & 0 deletions .changeset/breezy-seals-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/grpc-api": minor
---

新增审计系统,增加 CreateOperationLog 和 GetOperationLogs 接口定义
5 changes: 5 additions & 0 deletions .changeset/cool-tomatoes-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/config": minor
---

新增审计系统配置文件
12 changes: 12 additions & 0 deletions .changeset/dirty-stingrays-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@scow/lib-operation-log": minor
"@scow/audit-server": minor
"@scow/protos": minor
"@scow/portal-web": minor
"@scow/demo-vagrant": minor
"@scow/mis-web": minor
"@scow/cli": minor
"@scow/docs": minor
---

新增审计系统服务,记录门户系统及管理系统操作日志及展示
2 changes: 1 addition & 1 deletion .github/workflows/test-build-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
- name: Upload test converage
uses: codecov/codecov-action@v3
with:
files: ./libs/auth/coverage/lcov.info,./libs/ssh/coverage/lcov.info,./libs/libconfig/coverage/lcov.info,./libs/decimal/coverage/lcov.info,./libs/server/coverage/lcov.info,./apps/cli/coverage/lcov.info,./apps/auth/coverage/lcov.info,./apps/mis-server/coverage/lcov.info,./apps/portal-server/coverage/lcov.info,./apps/gateway/coverage/lcov.info
files: ./libs/auth/coverage/lcov.info,./libs/ssh/coverage/lcov.info,./libs/libconfig/coverage/lcov.info,./libs/decimal/coverage/lcov.info,./libs/server/coverage/lcov.info,./apps/cli/coverage/lcov.info,./apps/auth/coverage/lcov.info,./apps/mis-server/coverage/lcov.info,./apps/portal-server/coverage/lcov.info,./apps/gateway/coverage/lcov.info,./apps/audit-server/coverage/lcov.info

- name: Create Release Pull Request or Publish
id: changesets
Expand Down
1 change: 1 addition & 0 deletions apps/audit-server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @scow/audit-server
1 change: 1 addition & 0 deletions apps/audit-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 审计系统
8 changes: 8 additions & 0 deletions apps/audit-server/config/audit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
db:
host: localhost
port: 3306
user: root
password: mysqlrootpassword
dbName: scow_audit


2 changes: 2 additions & 0 deletions apps/audit-server/env/.env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DB_HOST=localhost
DB_NAME=scow_audit
4 changes: 4 additions & 0 deletions apps/audit-server/env/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LOG_LEVEL=error
PORT=0
DB_HOST=localhost
DB_NAME=scow_audit_${JEST_WORKER_ID}
35 changes: 35 additions & 0 deletions apps/audit-server/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy
* SCOW is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

// jest.config.js
const { pathsToModuleNameMapper } = require("ts-jest");
// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file
// which contains the path mapping (ie the `compilerOptions.paths` option):
const { compilerOptions } = require("./tsconfig");

const dotenv = require("dotenv");

dotenv.config({ path: "env/.env.test" });

/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
rootDir: ".",
preset: "ts-jest",
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: "<rootDir>/" }),
testMatch: [
"<rootDir>/tests/**/*.test.ts?(x)",
],
coverageDirectory: "coverage",
testTimeout: 30000,
coverageReporters: ["lcov"],
setupFilesAfterEnv: ["jest-extended/all"],
};
54 changes: 54 additions & 0 deletions apps/audit-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@scow/audit-server",
"version": "1.0.0",
"description": "",
"private": true,
"main": "build/index.js",
"scripts": {
"dev": "dotenv -e env/.env.dev -- node --watch -r ts-node/register -r tsconfig-paths/register src/index.ts",
"build": "rimraf build && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
"serve": "node build/index.js",
"test": "jest",
"orm": "dotenv -e env/.env.dev -- npx mikro-orm"
},
"files": [
"scripts",
"build",
".npmrc",
"!**/*.map"
],
"keywords": [],
"author": "PKUHPC (https://github.com/PKUHPC)",
"license": "Mulan PSL v2",
"repository": "https://github.com/PKUHPC/SCOW",
"dependencies": {
"@ddadaal/tsgrpc-server": "0.19.4",
"@ddadaal/tsgrpc-common": "0.2.4",
"@ddadaal/tsgrpc-client": "0.17.6",
"@grpc/grpc-js": "1.8.21",
"@mikro-orm/cli": "5.7.14",
"@mikro-orm/core": "5.7.14",
"@mikro-orm/migrations": "5.7.14",
"@mikro-orm/mysql": "5.7.14",
"@scow/config": "workspace:*",
"@scow/lib-config": "workspace:*",
"@scow/lib-decimal": "workspace:*",
"@scow/utils": "workspace:*",
"@scow/protos": "workspace:*",
"pino": "8.15.0",
"pino-pretty": "10.2.0"
},
"devDependencies": {
"@types/google-protobuf": "3.15.6"
},
"mikro-orm": {
"useTsNode": true,
"configPaths": [
"./src/mikro-orm.config.ts",
"./src/mikro-orm.config.js"
]
},
"volta": {
"extends": "../../package.json"
}
}
39 changes: 39 additions & 0 deletions apps/audit-server/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy
* SCOW is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

import { Server } from "@ddadaal/tsgrpc-server";
import { omitConfigSpec } from "@scow/lib-config";
import { readVersionFile } from "@scow/utils/build/version";
import { config } from "src/config/env";
import { plugins } from "src/plugins";
import { operationLogServiceServer } from "src/services/operationLog";
import { logger } from "src/utils/logger";

export async function createServer() {

const server = new Server({
host: config.HOST,
port: config.PORT,

logger,
});

server.logger.info({ version: readVersionFile() }, "@scow/audit-server: ");
server.logger.info({ config: omitConfigSpec(config) }, "Loaded env config");

for (const plugin of plugins) {
await server.register(plugin);
}
await server.register(operationLogServiceServer);

return server;
}
18 changes: 18 additions & 0 deletions apps/audit-server/src/config/audit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy
* SCOW is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

import { getAuditConfig } from "@scow/config/build/audit";
import { logger } from "src/utils/logger";

export const auditConfig = getAuditConfig(undefined, logger);


27 changes: 27 additions & 0 deletions apps/audit-server/src/config/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy
* SCOW is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

import { bool, envConfig, host, port, str } from "@scow/lib-config";

export const config = envConfig({
HOST: host({ default: "0.0.0.0", desc: "监听地址" }),
PORT: port({ default: 5000, desc: "监听端口" }),
LOG_LEVEL: str({
default: "info",
desc: "日志等级",
}),
LOG_PRETTY: bool({ desc: "以可读的方式输出log", default: false }),

DB_NAME: str({ desc: "存放系统数据的数据库名,将会覆写配置文件。用于测试", default: undefined }),
DB_PASSWORD: str({ desc: "审计系统数据库密码,将会覆写配置文件", default: undefined }),
});

63 changes: 63 additions & 0 deletions apps/audit-server/src/entities/OperationLog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy
* SCOW is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

import { Entity, Enum, PrimaryKey, Property } from "@mikro-orm/core";
import { CURRENT_TIMESTAMP, DATETIME_TYPE } from "src/utils/orm";

export enum OperationResult {
UNKNOWN = "UNKNOWN",
SUCCESS = "SUCCESS",
FAIL = "FAIL",
}

@Entity()
export class OperationLog {
@PrimaryKey()
id!: number;

@Property()
operatorUserId!: string;

@Property()
operatorIp!: string;

@Property({ columnType: DATETIME_TYPE, defaultRaw: CURRENT_TIMESTAMP })
operationTime?: Date;

@Enum({ items: () => OperationResult, comment: Object.values(OperationResult).join(", ") })
operationResult: OperationResult;

@Property({ type: "json", nullable: true })
metaData?: { [key: string]: any; };

constructor(init: {
operationLogId?: number;
operatorUserId: string;
operatorIp: string;
operationTime?: Date;
operationResult: OperationResult;
metaData: { [key: string]: any };
}) {
if (init.operationLogId) {
this.id = init.operationLogId;
}
this.operatorUserId = init.operatorUserId;
this.operatorIp = init.operatorIp;
if (init.operationTime) {
this.operationTime = init.operationTime;
}
this.operationResult = init.operationResult;
this.metaData = init.metaData;
}

}

17 changes: 17 additions & 0 deletions apps/audit-server/src/entities/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy
* SCOW is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

import { OperationLog } from "src/entities/OperationLog";

export const entities = [
OperationLog,
];
44 changes: 44 additions & 0 deletions apps/audit-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy
* SCOW is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

import { createServer } from "src/app";
import { migrationUp } from "src/tasks/migrationUp";

async function main() {

const server = await createServer();

const args = process.argv.slice(1);

// run tasks
if (args.length > 1) {
const [_scriptName, command] = args;

const logger = server.logger.child({ task: command });

switch (command) {

case "migrationUp":
await migrationUp(server.ext.orm);
break;
default:
logger.error("Unexpected task name %s", command);
process.exit(1);
}

process.exit(0);
}

await server.start();
}

main();
Loading