mirror of
https://github.com/certd/certd.git
synced 2026-04-24 12:27:25 +08:00
feat: 升级midway,支持esm
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
{
|
||||
"extends": "./node_modules/mwts/",
|
||||
"ignorePatterns": ["node_modules", "dist", "test", "jest.config.js", "typings"],
|
||||
"ignorePatterns": ["node_modules", "dist", "test", "typings"],
|
||||
"env": {
|
||||
"jest": true
|
||||
"mocha": true
|
||||
},
|
||||
"rules": {
|
||||
"max-len": ["error", 160],
|
||||
"@typescript-eslint/ban-ts-ignore": "off",
|
||||
"@typescript-eslint/ban-ts-comment": "off"
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ logs/
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
node_modules/
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
coverage/
|
||||
dist/
|
||||
.idea/
|
||||
@@ -13,9 +11,6 @@ run/
|
||||
*.un~
|
||||
.tsbuildinfo
|
||||
.tsbuildinfo.*
|
||||
/data/db.sqlite
|
||||
/pnpm-lock.yaml
|
||||
.serverless
|
||||
data
|
||||
public
|
||||
!public/.gitignore
|
||||
./data
|
||||
|
||||
./test/**/*.js
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extension": ["ts"],
|
||||
"node-option": ["no-warnings", "loader=ts-node/esm"],
|
||||
"spec": ["test/**/*.test.ts"],
|
||||
"require": ["test/setup.ts"]
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
link-workspace-packages=deep
|
||||
link-workspace-packages=true
|
||||
prefer-workspace-packages=true
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"printWidth": 160,
|
||||
"bracketSpacing": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "es5",
|
||||
"arrowParens": "avoid"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
...require('mwts/.prettierrc.json'),
|
||||
"printWidth": 160,
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
module.exports = {
|
||||
...require('mwts/.prettierrc.json')
|
||||
}
|
||||
@@ -1,22 +1,15 @@
|
||||
# fast-server-js
|
||||
|
||||
base on midway
|
||||
# my_midway_project
|
||||
|
||||
## QuickStart
|
||||
|
||||
> nodejs需要16以上
|
||||
|
||||
<!-- add docs here for user -->
|
||||
|
||||
see [midway docs][midway] for more detail.
|
||||
|
||||
### Development
|
||||
|
||||
```bash
|
||||
$ npm i
|
||||
# 如果遇到sqlite安装失败时
|
||||
# 建议使用cnpm
|
||||
# npm install -g cnpm
|
||||
# cnpm install
|
||||
$ npm run dev
|
||||
$ open http://localhost:7001/
|
||||
```
|
||||
@@ -34,8 +27,3 @@ $ npm start
|
||||
|
||||
|
||||
[midway]: https://midwayjs.org
|
||||
|
||||
see [midway docs][ https://midwayjs.org] for more detail.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# fast-server-js
|
||||
# my_midway_project
|
||||
|
||||
## 快速入门
|
||||
|
||||
@@ -27,4 +27,3 @@ $ npm start
|
||||
|
||||
|
||||
[midway]: https://midwayjs.org
|
||||
|
||||
|
||||
+2
-2
@@ -1,2 +1,2 @@
|
||||
const { Bootstrap } = require('@midwayjs/bootstrap');
|
||||
Bootstrap.run();
|
||||
import { Bootstrap } from '@midwayjs/bootstrap';
|
||||
await Bootstrap.run();
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
INSERT INTO sys_settings ("key", title, setting,access) VALUES ("sys.install","安装信息",'{"installTime":'|| (select timestamp from 'flyway_history' where id = 1 )||'}',"private");
|
||||
|
||||
ALTER TABLE sys_user ADD COLUMN password_version integer DEFAULT 1;
|
||||
ALTER TABLE sys_user ADD COLUMN password_salt varchar(36);
|
||||
@@ -1,61 +1,57 @@
|
||||
{
|
||||
"name": "@certd/ui-server",
|
||||
"version": "1.21.0",
|
||||
"description": "fast-server base midway",
|
||||
"name": "my-midway-esm-project",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node ./bootstrap.js",
|
||||
"online": "cross-env NODE_ENV=production node ./bootstrap.js",
|
||||
"online:preview": "NODE_ENV=preview node ./bootstrap.js",
|
||||
"dev": "cross-env NODE_ENV=local midway-bin dev --ts --watchFile='../../core/pipeline/src,../../plugins/'",
|
||||
"dev:preview": "cross-env NODE_ENV=preview midway-bin dev --ts",
|
||||
"db": "cross-env NODE_ENV=syncdb midway-bin dev --ts",
|
||||
"test": "midway-bin test --ts",
|
||||
"cov": "midway-bin cov --ts",
|
||||
"start": "cross-env NODE_ENV=production node ./bootstrap.js",
|
||||
"dev": "cross-env NODE_ENV=local mwtsc --watch --run @midwayjs/mock/app",
|
||||
"test": "cross-env NODE_ENV=unittest mocha",
|
||||
"cov": "cross-env c8 --all --reporter=text --reporter=lcovonly npm run test",
|
||||
"lint": "mwts check",
|
||||
"lint:fix": "mwts fix",
|
||||
"ci": "npm run cov",
|
||||
"build": "midway-bin build -c",
|
||||
"build:preview": "cross-env NODE_ENV=preview midway-bin build -c",
|
||||
"check": "luckyeye",
|
||||
"mig": "typeorm migration:create -n name"
|
||||
"build": "mwtsc --cleanOutDir",
|
||||
"up-mw-deps": "npx midway-version -u -w"
|
||||
},
|
||||
"dependencies": {
|
||||
"@alicloud/cs20151215": "^3.0.3",
|
||||
"@alicloud/openapi-client": "^0.4.0",
|
||||
"@alicloud/pop-core": "^1.7.10",
|
||||
"@certd/acme-client": "^1.21.0",
|
||||
"@certd/lib-huawei": "^1.21.0",
|
||||
"@certd/lib-k8s": "^1.21.0",
|
||||
"@certd/midway-flyway-js": "^1.21.0",
|
||||
"@certd/pipeline": "^1.21.0",
|
||||
"@certd/plugin-cert": "^1.21.0",
|
||||
"@certd/plugin-util": "^1.21.0",
|
||||
"@koa/cors": "^3.4.3",
|
||||
"@midwayjs/bootstrap": "^3.15.0",
|
||||
"@midwayjs/bootstrap": "^3.16.2",
|
||||
"@midwayjs/cache": "^3.14.0",
|
||||
"@midwayjs/cli": "^2.1.1",
|
||||
"@midwayjs/cli-plugin-build": "^2.1.0",
|
||||
"@midwayjs/core": "^3.15.0",
|
||||
"@midwayjs/decorator": "^3.15.0",
|
||||
"@midwayjs/i18n": "^3.15.0",
|
||||
"@midwayjs/koa": "^3.15.0",
|
||||
"@midwayjs/logger": "^3.3.0",
|
||||
"@midwayjs/static-file": "^3.15.0",
|
||||
"@midwayjs/typeorm": "^3.15.0",
|
||||
"@midwayjs/validate": "^3.15.0",
|
||||
"axios": "^0.27.2",
|
||||
"@midwayjs/core": "^3.16.2",
|
||||
"@midwayjs/i18n": "^3.16.4",
|
||||
"@midwayjs/info": "^3.16.4",
|
||||
"@midwayjs/koa": "^3.16.4",
|
||||
"@midwayjs/logger": "^3.1.0",
|
||||
"@midwayjs/static-file": "^3.16.4",
|
||||
"@midwayjs/typeorm": "^3.16.4",
|
||||
"@midwayjs/validate": "^3.16.4",
|
||||
"axios": "^1.7.2",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"cache-manager": "^3.6.3",
|
||||
"dayjs": "^1.11.7",
|
||||
"glob": "^7.2.3",
|
||||
"glob": "^11.0.0",
|
||||
"https-proxy-agent": "^7.0.4",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"js-yaml": "^4.1.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"koa-send": "^5.0.1",
|
||||
"kubernetes-client": "^9.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"lodash-es": "^4.17.21",
|
||||
"log4js": "^6.7.1",
|
||||
"lru-cache": "^10.0.0",
|
||||
"md5": "^2.3.0",
|
||||
"midway-flyway-js": "^3.0.0",
|
||||
"nanoid": "^4.0.0",
|
||||
"node-cron": "^3.0.2",
|
||||
"nodemailer": "^6.9.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
@@ -67,40 +63,31 @@
|
||||
"typeorm": "^0.3.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@midwayjs/luckyeye": "^1.1.0",
|
||||
"@midwayjs/mock": "^3.9.0",
|
||||
"@midwayjs/mwcc": "^0.8.0",
|
||||
"@midwayjs/mock": "^3.16.4",
|
||||
"@types/cache-manager": "^3.4.3",
|
||||
"@types/jest": "^26.0.24",
|
||||
"@types/koa": "2.13.4",
|
||||
"@types/node": "^14.18.35",
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"@types/mocha": "^10.0.1",
|
||||
"@types/node": "16",
|
||||
"@types/nodemailer": "^6.4.8",
|
||||
"@types/ssh2": "^1.11.6",
|
||||
"cross-env": "^6.0.3",
|
||||
"jest": "^26.6.3",
|
||||
"c8": "^8.0.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"mocha": "^10.2.0",
|
||||
"mwts": "^1.3.0",
|
||||
"mwtsc": "^1.4.0",
|
||||
"prettier": "^2.8.8",
|
||||
"ts-jest": "^26.5.6",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsconfig-paths": "^4.1.1",
|
||||
"typescript": "^4.9.4"
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "~5.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
},
|
||||
"midway-bin-clean": [
|
||||
".vscode/.tsbuildinfo",
|
||||
"dist"
|
||||
],
|
||||
"midway-luckyeye": {
|
||||
"packages": [
|
||||
"midway_v2"
|
||||
]
|
||||
"node": ">=16.0.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/fast-crud/fast-server-js"
|
||||
"url": ""
|
||||
},
|
||||
"author": "Greper",
|
||||
"license": "AGPL-3.0"
|
||||
"author": "anonymous",
|
||||
"license": "MIT"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Inject } from '@midwayjs/decorator';
|
||||
import { Inject } from '@midwayjs/core';
|
||||
import { Context } from '@midwayjs/koa';
|
||||
import { Constants } from './constants';
|
||||
import { Constants } from './constants.js';
|
||||
|
||||
export abstract class BaseController {
|
||||
@Inject()
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { ValidateException } from './exception/validation-exception';
|
||||
import * as _ from 'lodash';
|
||||
import { PermissionException } from './exception/permission-exception';
|
||||
import { ValidateException } from './exception/validation-exception.js';
|
||||
import * as _ from 'lodash-es';
|
||||
import { PermissionException } from './exception/permission-exception.js';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Inject } from '@midwayjs/decorator';
|
||||
import { Inject } from '@midwayjs/core';
|
||||
import { TypeORMDataSourceManager } from '@midwayjs/typeorm';
|
||||
import { EntityManager } from 'typeorm/entity-manager/EntityManager';
|
||||
import { EntityManager } from 'typeorm/entity-manager/EntityManager.js';
|
||||
|
||||
/**
|
||||
* 服务基类
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ALL, Body, Post, Query } from '@midwayjs/decorator';
|
||||
import { BaseController } from './base-controller';
|
||||
import { ALL, Body, Post, Query } from '@midwayjs/core';
|
||||
import { BaseController } from './base-controller.js';
|
||||
|
||||
export abstract class CrudController<T> extends BaseController {
|
||||
abstract getService<T>();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Constants } from '../constants';
|
||||
import { BaseException } from './base-exception';
|
||||
import { Constants } from '../constants.js';
|
||||
import { BaseException } from './base-exception.js';
|
||||
/**
|
||||
* 授权异常
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Constants } from '../constants';
|
||||
import { BaseException } from './base-exception';
|
||||
import { Constants } from '../constants.js';
|
||||
import { BaseException } from './base-exception.js';
|
||||
/**
|
||||
* 通用异常
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Constants } from '../constants';
|
||||
import { BaseException } from './base-exception';
|
||||
import { Constants } from '../constants.js';
|
||||
import { BaseException } from './base-exception.js';
|
||||
/**
|
||||
* 授权异常
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Constants } from '../constants';
|
||||
import { BaseException } from './base-exception';
|
||||
import { Constants } from '../constants.js';
|
||||
import { BaseException } from './base-exception.js';
|
||||
/**
|
||||
* 预览模式
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Constants } from '../constants';
|
||||
import { BaseException } from './base-exception';
|
||||
import { Constants } from '../constants.js';
|
||||
import { BaseException } from './base-exception.js';
|
||||
/**
|
||||
* 校验异常
|
||||
*/
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import { join } from 'path';
|
||||
import { FlywayHistory } from 'midway-flyway-js/dist/entity';
|
||||
|
||||
import { MidwayConfig } from '@midwayjs/core';
|
||||
import { UserEntity } from '../modules/authority/entity/user';
|
||||
import { PipelineEntity } from '../modules/pipeline/entity/pipeline';
|
||||
import { join } from 'path';
|
||||
import { dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
// const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
import { FlywayHistory } from '@certd/midway-flyway-js';
|
||||
import { UserEntity } from '../modules/authority/entity/user.js';
|
||||
import { PipelineEntity } from '../modules/pipeline/entity/pipeline.js';
|
||||
//import { logger } from '../utils/logger';
|
||||
// load .env file in process.cwd
|
||||
import { mergeConfig } from './loader';
|
||||
|
||||
import { mergeConfig } from './loader.js';
|
||||
const development = {
|
||||
keys: '',
|
||||
keys: '111',
|
||||
koa: {
|
||||
port: 7001,
|
||||
},
|
||||
@@ -51,14 +54,7 @@ const development = {
|
||||
logging: true,
|
||||
|
||||
// 配置实体模型 或者 entities: '/entity',
|
||||
entities: [
|
||||
'**/modules/*/entity/*.ts',
|
||||
'**/entity/*.js',
|
||||
'**/entity/*.d.ts',
|
||||
PipelineEntity,
|
||||
FlywayHistory,
|
||||
UserEntity,
|
||||
],
|
||||
entities: ['**/modules/*/entity/*.ts', '**/entity/*.js', '**/entity/*.d.ts', PipelineEntity, FlywayHistory, UserEntity],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -83,4 +79,5 @@ const development = {
|
||||
},
|
||||
} as MidwayConfig;
|
||||
mergeConfig(development, 'development');
|
||||
|
||||
export default development;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { MidwayConfig } from '@midwayjs/core';
|
||||
import { mergeConfig } from './loader';
|
||||
import { mergeConfig } from './loader.js';
|
||||
|
||||
const preview = {
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { MidwayConfig } from '@midwayjs/core';
|
||||
import { mergeConfig } from './loader';
|
||||
import { mergeConfig } from './loader.js';
|
||||
|
||||
const production = {
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { MidwayConfig } from '@midwayjs/core';
|
||||
|
||||
export default {
|
||||
koa: {
|
||||
port: null,
|
||||
},
|
||||
} as MidwayConfig;
|
||||
@@ -1,8 +1,7 @@
|
||||
import path from 'path';
|
||||
import _ from 'lodash';
|
||||
|
||||
const yaml = require('js-yaml');
|
||||
const fs = require('fs');
|
||||
import * as _ from 'lodash-es';
|
||||
import yaml from 'js-yaml';
|
||||
import fs from 'fs';
|
||||
|
||||
function parseEnv(defaultConfig: any) {
|
||||
const config = {};
|
||||
|
||||
@@ -1,42 +1,58 @@
|
||||
import * as validateComp from '@midwayjs/validate';
|
||||
import * as productionConfig from './config/config.production';
|
||||
import * as previewConfig from './config/config.preview';
|
||||
import * as defaultConfig from './config/config.default';
|
||||
import { App, Configuration } from '@midwayjs/decorator';
|
||||
import { Configuration, App } from '@midwayjs/core';
|
||||
import * as koa from '@midwayjs/koa';
|
||||
import * as orm from '@midwayjs/typeorm';
|
||||
import * as cache from '@midwayjs/cache';
|
||||
import cors from '@koa/cors';
|
||||
import { join } from 'path';
|
||||
import * as flyway from 'midway-flyway-js';
|
||||
import { ReportMiddleware } from './middleware/report';
|
||||
import { GlobalExceptionMiddleware } from './middleware/global-exception';
|
||||
import { PreviewMiddleware } from './middleware/preview';
|
||||
import { AuthorityMiddleware } from './middleware/authority';
|
||||
import * as validate from '@midwayjs/validate';
|
||||
import * as info from '@midwayjs/info';
|
||||
import * as staticFile from '@midwayjs/static-file';
|
||||
import * as cron from './modules/plugin/cron';
|
||||
import { logger } from './utils/logger';
|
||||
import { ResetPasswdMiddleware } from './middleware/reset-passwd/middleware';
|
||||
import * as cron from './modules/plugin/cron/index.js';
|
||||
import * as flyway from '@certd/midway-flyway-js';
|
||||
import cors from '@koa/cors';
|
||||
import { ReportMiddleware } from './middleware/report.js';
|
||||
import { GlobalExceptionMiddleware } from './middleware/global-exception.js';
|
||||
import { PreviewMiddleware } from './middleware/preview.js';
|
||||
import { AuthorityMiddleware } from './middleware/authority.js';
|
||||
import { logger } from './utils/logger.js';
|
||||
import { ResetPasswdMiddleware } from './middleware/reset-passwd/middleware.js';
|
||||
// import { DefaultErrorFilter } from './filter/default.filter.js';
|
||||
// import { NotFoundFilter } from './filter/notfound.filter.js';
|
||||
import DefaultConfig from './config/config.default.js';
|
||||
import ProductionConfig from './config/config.production.js';
|
||||
import PreviewConfig from './config/config.preview.js';
|
||||
import UnittestConfig from './config/config.unittest.js';
|
||||
|
||||
@Configuration({
|
||||
imports: [koa, orm, cache, flyway, validateComp, cron, staticFile],
|
||||
imports: [
|
||||
koa,
|
||||
orm,
|
||||
cache,
|
||||
flyway,
|
||||
cron,
|
||||
staticFile,
|
||||
validate,
|
||||
{
|
||||
component: info,
|
||||
enabledEnvironment: ['local'],
|
||||
},
|
||||
],
|
||||
importConfigs: [
|
||||
{
|
||||
default: defaultConfig,
|
||||
preview: previewConfig,
|
||||
production: productionConfig,
|
||||
default: DefaultConfig,
|
||||
preview: PreviewConfig,
|
||||
production: ProductionConfig,
|
||||
unittest: UnittestConfig,
|
||||
},
|
||||
],
|
||||
})
|
||||
export class ContainerConfiguration {}
|
||||
@Configuration({
|
||||
conflictCheck: true,
|
||||
importConfigs: [join(__dirname, './config')],
|
||||
})
|
||||
export class ContainerLifeCycle {
|
||||
@App()
|
||||
export class MainConfiguration {
|
||||
@App('koa')
|
||||
app: koa.Application;
|
||||
|
||||
async onReady() {
|
||||
// add middleware
|
||||
this.app.useMiddleware([ReportMiddleware]);
|
||||
// add filter
|
||||
// this.app.useFilter([NotFoundFilter, DefaultErrorFilter]);
|
||||
//跨域
|
||||
this.app.use(
|
||||
cors({
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { MidwayEnvironmentService } from '@midwayjs/core';
|
||||
import { Controller, Get, Inject, Provide } from '@midwayjs/decorator';
|
||||
import { logger } from '../utils/logger';
|
||||
import { Constants } from '../basic/constants';
|
||||
import { Controller, Get, Inject, Provide } from '@midwayjs/core';
|
||||
import { logger } from '../utils/logger.js';
|
||||
import { Constants } from '../basic/constants.js';
|
||||
|
||||
@Provide()
|
||||
@Controller('/hello')
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Catch } from '@midwayjs/core';
|
||||
import { Context } from '@midwayjs/koa';
|
||||
|
||||
@Catch()
|
||||
export class DefaultErrorFilter {
|
||||
async catch(err: Error, ctx: Context) {
|
||||
// 所有的未分类错误会到这里
|
||||
return {
|
||||
success: false,
|
||||
message: err.message,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Catch, httpError, MidwayHttpError } from '@midwayjs/core';
|
||||
import { Context } from '@midwayjs/koa';
|
||||
|
||||
@Catch(httpError.NotFoundError)
|
||||
export class NotFoundFilter {
|
||||
async catch(err: MidwayHttpError, ctx: Context) {
|
||||
// 404 错误会到这里
|
||||
ctx.redirect('/404.html');
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
import { Config, Inject, Provide } from '@midwayjs/decorator';
|
||||
import { Config, Inject, Provide } from '@midwayjs/core';
|
||||
import { IMidwayKoaContext, IWebMiddleware, NextFunction } from '@midwayjs/koa';
|
||||
import * as jwt from 'jsonwebtoken';
|
||||
import { Constants } from '../basic/constants';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { Constants } from '../basic/constants.js';
|
||||
import { MidwayWebRouterService } from '@midwayjs/core';
|
||||
import { RoleService } from '../modules/authority/service/role-service';
|
||||
import { logger } from '../utils/logger';
|
||||
import { RoleService } from '../modules/authority/service/role-service.js';
|
||||
import { logger } from '../utils/logger.js';
|
||||
|
||||
/**
|
||||
* 权限校验
|
||||
*/
|
||||
@Provide()
|
||||
export class AuthorityMiddleware implements IWebMiddleware {
|
||||
@Config('keys')
|
||||
@Config('auth.jwt.secret')
|
||||
private secret: string;
|
||||
@Inject()
|
||||
webRouterService: MidwayWebRouterService;
|
||||
@@ -21,10 +21,7 @@ export class AuthorityMiddleware implements IWebMiddleware {
|
||||
resolve() {
|
||||
return async (ctx: IMidwayKoaContext, next: NextFunction) => {
|
||||
// 查询当前路由是否在路由表中注册
|
||||
const routeInfo = await this.webRouterService.getMatchedRouterInfo(
|
||||
ctx.path,
|
||||
ctx.method
|
||||
);
|
||||
const routeInfo = await this.webRouterService.getMatchedRouterInfo(ctx.path, ctx.method);
|
||||
if (routeInfo == null) {
|
||||
// 404
|
||||
await next();
|
||||
@@ -33,9 +30,7 @@ export class AuthorityMiddleware implements IWebMiddleware {
|
||||
const permission = routeInfo.summary;
|
||||
if (permission == null || permission === '') {
|
||||
ctx.status = 500;
|
||||
ctx.body = Constants.res.serverError(
|
||||
'该路由未配置权限控制:' + ctx.path
|
||||
);
|
||||
ctx.body = Constants.res.serverError('该路由未配置权限控制:' + ctx.path);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -57,6 +52,7 @@ export class AuthorityMiddleware implements IWebMiddleware {
|
||||
try {
|
||||
ctx.user = jwt.verify(token, this.secret);
|
||||
} catch (err) {
|
||||
logger.error('token verify error: ', err);
|
||||
ctx.status = 401;
|
||||
ctx.body = Constants.res.auth;
|
||||
return;
|
||||
@@ -65,8 +61,7 @@ export class AuthorityMiddleware implements IWebMiddleware {
|
||||
if (permission !== Constants.per.authOnly) {
|
||||
//如果不是仅校验登录,还需要校验是否拥有权限
|
||||
const roleIds: number[] = ctx.user.roles;
|
||||
const permissions =
|
||||
await this.roleService.getCachedPermissionSetByRoleIds(roleIds);
|
||||
const permissions = await this.roleService.getCachedPermissionSetByRoleIds(roleIds);
|
||||
|
||||
if (!permissions.has(permission)) {
|
||||
logger.info('not permission: ', ctx.req.url);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Provide } from '@midwayjs/decorator';
|
||||
import { Provide } from '@midwayjs/core';
|
||||
import { IWebMiddleware, IMidwayKoaContext, NextFunction } from '@midwayjs/koa';
|
||||
import { logger } from '../utils/logger';
|
||||
import { Result } from '../basic/result';
|
||||
import { logger } from '../utils/logger.js';
|
||||
import { Result } from '../basic/result.js';
|
||||
|
||||
@Provide()
|
||||
export class GlobalExceptionMiddleware implements IWebMiddleware {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Config, Provide } from '@midwayjs/decorator';
|
||||
import { Config, Provide } from '@midwayjs/core';
|
||||
import { IMidwayKoaContext, NextFunction, IWebMiddleware } from '@midwayjs/koa';
|
||||
import { PreviewException } from '../basic/exception/preview-exception';
|
||||
import { PreviewException } from '../basic/exception/preview-exception.js';
|
||||
|
||||
/**
|
||||
* 预览模式
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { Middleware, IMiddleware } from '@midwayjs/core';
|
||||
import { NextFunction, Context } from '@midwayjs/koa';
|
||||
|
||||
@Middleware()
|
||||
export class ReportMiddleware implements IMiddleware<Context, NextFunction> {
|
||||
resolve() {
|
||||
return async (ctx: Context, next: NextFunction) => {
|
||||
// 控制器前执行的逻辑
|
||||
const startTime = Date.now();
|
||||
// 执行下一个 Web 中间件,最后执行到控制器
|
||||
// 这里可以拿到下一个中间件或者控制器的返回值
|
||||
const result = await next();
|
||||
// 控制器之后执行的逻辑
|
||||
ctx.logger.info(
|
||||
`Report in "src/middleware/report.middleware.ts", rt = ${
|
||||
Date.now() - startTime
|
||||
}ms`
|
||||
);
|
||||
// 返回给上一个中间件的结果
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
static getName(): string {
|
||||
return 'report';
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Provide } from '@midwayjs/decorator';
|
||||
import { Provide } from '@midwayjs/core';
|
||||
import { IWebMiddleware, IMidwayKoaContext, NextFunction } from '@midwayjs/koa';
|
||||
import { logger } from '../utils/logger';
|
||||
import { logger } from '../utils/logger.js';
|
||||
|
||||
@Provide()
|
||||
export class ReportMiddleware implements IWebMiddleware {
|
||||
|
||||
@@ -6,11 +6,11 @@ import {
|
||||
Provide,
|
||||
Scope,
|
||||
ScopeEnum,
|
||||
} from '@midwayjs/decorator';
|
||||
} from '@midwayjs/core';
|
||||
import { IMidwayKoaContext, IWebMiddleware, NextFunction } from '@midwayjs/koa';
|
||||
import { CommonException } from '../../basic/exception/common-exception';
|
||||
import { UserService } from '../../modules/authority/service/user-service';
|
||||
import { logger } from '../../utils/logger';
|
||||
import { CommonException } from '../../basic/exception/common-exception.js';
|
||||
import { UserService } from '../../modules/authority/service/user-service.js';
|
||||
import { logger } from '../../utils/logger.js';
|
||||
|
||||
/**
|
||||
* 重置密码模式
|
||||
|
||||
@@ -6,9 +6,9 @@ import {
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { CrudController } from '../../../basic/crud-controller';
|
||||
import { PermissionService } from '../service/permission-service';
|
||||
} from '@midwayjs/core';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { PermissionService } from '../service/permission-service.js';
|
||||
|
||||
/**
|
||||
* 权限资源
|
||||
|
||||
@@ -6,9 +6,9 @@ import {
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { CrudController } from '../../../basic/crud-controller';
|
||||
import { RoleService } from '../service/role-service';
|
||||
} from '@midwayjs/core';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { RoleService } from '../service/role-service.js';
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
|
||||
@@ -6,12 +6,12 @@ import {
|
||||
Body,
|
||||
Query,
|
||||
ALL,
|
||||
} from '@midwayjs/decorator';
|
||||
import { UserService } from '../service/user-service';
|
||||
import { CrudController } from '../../../basic/crud-controller';
|
||||
import { RoleService } from '../service/role-service';
|
||||
import { PermissionService } from '../service/permission-service';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
} from '@midwayjs/core';
|
||||
import { UserService } from '../service/user-service.js';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { RoleService } from '../service/role-service.js';
|
||||
import { PermissionService } from '../service/permission-service.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
|
||||
@@ -14,6 +14,9 @@ export class UserEntity {
|
||||
@Column({ comment: '密码', length: 100 })
|
||||
password: string;
|
||||
|
||||
@Column({ name: 'password_version', comment: '密码版本' })
|
||||
passwordVersion: number;
|
||||
|
||||
@Column({ name: 'nick_name', comment: '昵称', length: 100, nullable: true })
|
||||
nickName: string;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { EnumItem } from '../../../basic/enum-item';
|
||||
import * as _ from 'lodash';
|
||||
import { EnumItem } from '../../../basic/enum-item.js';
|
||||
import * as _ from 'lodash-es';
|
||||
class ResourceTypes {
|
||||
MENU = new EnumItem('menu', '菜单', 'blue');
|
||||
BTN = new EnumItem('btn', '按钮', 'green');
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { PermissionEntity } from '../entity/permission';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { PermissionEntity } from '../entity/permission.js';
|
||||
|
||||
/**
|
||||
* 权限资源
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { RolePermissionEntity } from '../entity/role-permission';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { RolePermissionEntity } from '../entity/role-permission.js';
|
||||
|
||||
/**
|
||||
* 角色->权限
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { In, Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { RoleEntity } from '../entity/role';
|
||||
import { UserRoleService } from './user-role-service';
|
||||
import { RolePermissionEntity } from '../entity/role-permission';
|
||||
import { PermissionService } from './permission-service';
|
||||
import * as _ from 'lodash';
|
||||
import { RolePermissionService } from './role-permission-service';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { RoleEntity } from '../entity/role.js';
|
||||
import { UserRoleService } from './user-role-service.js';
|
||||
import { RolePermissionEntity } from '../entity/role-permission.js';
|
||||
import { PermissionService } from './permission-service.js';
|
||||
import * as _ from 'lodash-es';
|
||||
import { RolePermissionService } from './role-permission-service.js';
|
||||
import { LRUCache } from 'lru-cache';
|
||||
/**
|
||||
* 角色
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { UserRoleEntity } from '../entity/user-role';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { UserRoleEntity } from '../entity/user-role.js';
|
||||
|
||||
/**
|
||||
* 用户->角色
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { UserEntity } from '../entity/user';
|
||||
import * as _ from 'lodash';
|
||||
import { UserEntity } from '../entity/user.js';
|
||||
import * as _ from 'lodash-es';
|
||||
import md5 from 'md5';
|
||||
import { CommonException } from '../../../basic/exception/common-exception';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { RoleService } from './role-service';
|
||||
import { PermissionService } from './permission-service';
|
||||
import { UserRoleService } from './user-role-service';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { UserRoleEntity } from '../entity/user-role';
|
||||
import { CommonException } from '../../../basic/exception/common-exception.js';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { RoleService } from './role-service.js';
|
||||
import { PermissionService } from './permission-service.js';
|
||||
import { UserRoleService } from './user-role-service.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
import { UserRoleEntity } from '../entity/user-role.js';
|
||||
import { randomText } from 'svg-captcha';
|
||||
import bcrypt from 'bcryptjs';
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
@@ -58,8 +59,9 @@ export class UserService extends BaseService<UserEntity> {
|
||||
if (!_.isEmpty(exists)) {
|
||||
throw new CommonException('用户名已经存在');
|
||||
}
|
||||
const password = param.password ?? randomText(6);
|
||||
param.password = md5(password); // 默认密码 建议未改密码不能登陆
|
||||
const plainPassword = param.password ?? randomText(6);
|
||||
param.passwordVersion = 2;
|
||||
param.password = this.genPassword(plainPassword, param.passwordVersion); // 默认密码 建议未改密码不能登陆
|
||||
await super.add(param);
|
||||
//添加角色
|
||||
if (param.roles && param.roles.length > 0) {
|
||||
@@ -85,7 +87,8 @@ export class UserService extends BaseService<UserEntity> {
|
||||
|
||||
delete param.username;
|
||||
if (!_.isEmpty(param.password)) {
|
||||
param.password = md5(param.password);
|
||||
param.passwordVersion = 2;
|
||||
param.password = this.genPassword(param.password, param.passwordVersion);
|
||||
} else {
|
||||
delete param.password;
|
||||
}
|
||||
@@ -93,15 +96,30 @@ export class UserService extends BaseService<UserEntity> {
|
||||
await this.roleService.updateRoles(param.id, param.roles);
|
||||
}
|
||||
|
||||
private genPassword(plainPassword: any, passwordVersion: number) {
|
||||
if (passwordVersion == null || passwordVersion <= 1) {
|
||||
return md5(plainPassword);
|
||||
}
|
||||
const salt = bcrypt.genSaltSync(10);
|
||||
return bcrypt.hashSync(plainPassword, salt);
|
||||
}
|
||||
|
||||
async findOne(param) {
|
||||
return this.repository.findOne({
|
||||
where: param,
|
||||
});
|
||||
}
|
||||
|
||||
checkPassword(rawPassword: any, md5Password: any) {
|
||||
// logger.info('md5', md5('123456'));
|
||||
return md5(rawPassword) === md5Password;
|
||||
async checkPassword(
|
||||
rawPassword: any,
|
||||
hashPassword: any,
|
||||
passwordVersion: number
|
||||
) {
|
||||
if (passwordVersion == null || passwordVersion <= 1) {
|
||||
return this.genPassword(rawPassword, passwordVersion) === hashPassword;
|
||||
}
|
||||
|
||||
return bcrypt.compareSync(rawPassword, hashPassword); // true
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,8 +145,12 @@ export class UserService extends BaseService<UserEntity> {
|
||||
mobile: user.mobile || '',
|
||||
phoneCode: user.phoneCode || '',
|
||||
status: 1,
|
||||
passwordVersion: 2,
|
||||
});
|
||||
newUser.password = md5(newUser.password);
|
||||
newUser.password = this.genPassword(
|
||||
newUser.password,
|
||||
newUser.passwordVersion
|
||||
);
|
||||
|
||||
await this.transaction(async txManager => {
|
||||
newUser = await txManager.save(newUser);
|
||||
@@ -145,7 +167,12 @@ export class UserService extends BaseService<UserEntity> {
|
||||
|
||||
async changePassword(userId: any, form: any) {
|
||||
const user = await this.info(userId);
|
||||
if (!this.checkPassword(form.password, user.password)) {
|
||||
const passwordChecked = await this.checkPassword(
|
||||
form.password,
|
||||
user.password,
|
||||
user.passwordVersion
|
||||
);
|
||||
if (!passwordChecked) {
|
||||
throw new CommonException('原密码错误');
|
||||
}
|
||||
const param = {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Autoload, Init, Inject, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { logger } from '../../utils/logger.js';
|
||||
import { UserService } from '../authority/service/user-service.js';
|
||||
import { SysSettingsService } from '../system/service/sys-settings-service.js';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { SysInstallInfo } from '../system/service/models.js';
|
||||
|
||||
export type InstallInfo = {
|
||||
installTime: number;
|
||||
instanceId?: string;
|
||||
};
|
||||
|
||||
@Autoload()
|
||||
@Scope(ScopeEnum.Singleton)
|
||||
export class AutoInitSite {
|
||||
@Inject()
|
||||
userService: UserService;
|
||||
|
||||
@Inject()
|
||||
sysSettingsService: SysSettingsService;
|
||||
|
||||
@Init()
|
||||
async init() {
|
||||
logger.info('初始化站点开始');
|
||||
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
||||
if (!installInfo.siteId) {
|
||||
installInfo.siteId = nanoid();
|
||||
await this.sysSettingsService.saveSetting(installInfo);
|
||||
}
|
||||
if (!installInfo.siteId) {
|
||||
installInfo.siteId = nanoid();
|
||||
await this.sysSettingsService.saveSetting(installInfo);
|
||||
}
|
||||
|
||||
logger.info('初始化站点完成');
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Rule, RuleType } from '@midwayjs/validate';
|
||||
import { ALL, Inject } from '@midwayjs/decorator';
|
||||
import { Body } from '@midwayjs/decorator';
|
||||
import { Controller, Post, Provide } from '@midwayjs/decorator';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import { CodeService } from '../service/code-service';
|
||||
import { EmailService } from '../service/email-service';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { ALL, Inject } from '@midwayjs/core';
|
||||
import { Body } from '@midwayjs/core';
|
||||
import { Controller, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { CodeService } from '../service/code-service.js';
|
||||
import { EmailService } from '../service/email-service.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
export class SmsCodeReq {
|
||||
@Rule(RuleType.number().required())
|
||||
phoneCode: number;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Body, Controller, Inject, Post, Provide } from '@midwayjs/decorator';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import { EmailService } from '../service/email-service';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { EmailService } from '../service/email-service.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Rule, RuleType } from '@midwayjs/validate';
|
||||
import { Controller, Get, Inject, Provide } from '@midwayjs/decorator';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { SysSettingsService } from '../../system/service/sys-settings-service';
|
||||
import { Controller, Get, Inject, Provide } from '@midwayjs/core';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
|
||||
import { SysPublicSettings } from '../../system/service/models.js';
|
||||
|
||||
export class SmsCodeReq {
|
||||
@Rule(RuleType.number().required())
|
||||
@@ -28,7 +29,9 @@ export class BasicSettingsController extends BaseController {
|
||||
|
||||
@Get('/public', { summary: Constants.per.guest })
|
||||
public async getSysPublic() {
|
||||
const settings = await this.sysSettingsService.readPublicSettings();
|
||||
const settings = await this.sysSettingsService.getSetting(
|
||||
SysPublicSettings
|
||||
);
|
||||
return this.ok(settings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Inject, Provide } from '@midwayjs/decorator';
|
||||
import { Inject, Provide } from '@midwayjs/core';
|
||||
import { CacheManager } from '@midwayjs/cache';
|
||||
const svgCaptcha = require('svg-captcha');
|
||||
import svgCaptcha from 'svg-captcha';
|
||||
|
||||
// {data: '<svg.../svg>', text: 'abcd'}
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import type { EmailSend } from '@certd/pipeline';
|
||||
import { IEmailService } from '@certd/pipeline';
|
||||
import nodemailer from 'nodemailer';
|
||||
import type SMTPConnection from 'nodemailer/lib/smtp-connection';
|
||||
import { logger } from '../../../utils/logger';
|
||||
import { UserSettingsService } from '../../mine/service/user-settings-service';
|
||||
import { logger } from '../../../utils/logger.js';
|
||||
import { UserSettingsService } from '../../mine/service/user-settings-service.js';
|
||||
|
||||
export type EmailConfig = {
|
||||
host: string;
|
||||
|
||||
@@ -5,10 +5,10 @@ import {
|
||||
Post,
|
||||
Provide,
|
||||
ALL,
|
||||
} from '@midwayjs/decorator';
|
||||
import { LoginService } from '../service/login-service';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
} from '@midwayjs/core';
|
||||
import { LoginService } from '../service/login-service.js';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -5,12 +5,12 @@ import {
|
||||
Inject,
|
||||
Post,
|
||||
Provide,
|
||||
} from '@midwayjs/decorator';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { UserService } from '../../authority/service/user-service';
|
||||
import { UserEntity } from '../../authority/entity/user';
|
||||
import { SysSettingsService } from '../../system/service/sys-settings-service';
|
||||
} from '@midwayjs/core';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
import { UserService } from '../../authority/service/user-service.js';
|
||||
import { UserEntity } from '../../authority/entity/user.js';
|
||||
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Config, Inject, Provide } from '@midwayjs/decorator';
|
||||
import { UserService } from '../../authority/service/user-service';
|
||||
import * as jwt from 'jsonwebtoken';
|
||||
import { CommonException } from '../../../basic/exception/common-exception';
|
||||
import { RoleService } from '../../authority/service/role-service';
|
||||
import { UserEntity } from '../../authority/entity/user';
|
||||
import { Config, Inject, Provide } from '@midwayjs/core';
|
||||
import { UserService } from '../../authority/service/user-service.js';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { CommonException } from '../../../basic/exception/common-exception.js';
|
||||
import { RoleService } from '../../authority/service/role-service.js';
|
||||
import { UserEntity } from '../../authority/entity/user.js';
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
@@ -26,7 +26,7 @@ export class LoginService {
|
||||
if (info == null) {
|
||||
throw new CommonException('用户名或密码错误');
|
||||
}
|
||||
const right = this.userService.checkPassword(user.password, info.password);
|
||||
const right = await this.userService.checkPassword(user.password, info.password, info.passwordVersion);
|
||||
if (!right) {
|
||||
throw new CommonException('用户名或密码错误');
|
||||
}
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
import {
|
||||
ALL,
|
||||
Body,
|
||||
Controller,
|
||||
Inject,
|
||||
Post,
|
||||
Provide,
|
||||
} from '@midwayjs/decorator';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { UserService } from '../../authority/service/user-service';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
import { UserService } from '../../authority/service/user-service.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/decorator";
|
||||
import { CrudController } from "../../../basic/crud-controller";
|
||||
import { Constants } from "../../../basic/constants";
|
||||
import { UserSettingsService } from "../service/user-settings-service";
|
||||
import { UserSettingsEntity } from "../entity/user-settings";
|
||||
import {
|
||||
ALL,
|
||||
Body,
|
||||
Controller,
|
||||
Inject,
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/core';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
import { UserSettingsService } from '../service/user-settings-service.js';
|
||||
import { UserSettingsEntity } from '../entity/user-settings.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { UserSettingsEntity } from '../entity/user-settings';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { UserSettingsEntity } from '../entity/user-settings.js';
|
||||
|
||||
/**
|
||||
* 授权
|
||||
@@ -30,7 +30,10 @@ export class UserSettingsService extends BaseService<UserSettingsEntity> {
|
||||
};
|
||||
}
|
||||
|
||||
async getByKey(key: string, userId: number): Promise<UserSettingsEntity | null> {
|
||||
async getByKey(
|
||||
key: string,
|
||||
userId: number
|
||||
): Promise<UserSettingsEntity | null> {
|
||||
if (!key || !userId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Autoload, Init, Inject, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { PipelineService } from '../service/pipeline-service';
|
||||
import { logger } from '../../../utils/logger';
|
||||
import { Autoload, Init, Inject, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { PipelineService } from '../service/pipeline-service.js';
|
||||
import { logger } from '../../../utils/logger.js';
|
||||
|
||||
@Autoload()
|
||||
@Scope(ScopeEnum.Singleton)
|
||||
|
||||
@@ -6,10 +6,10 @@ import {
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { CrudController } from '../../../basic/crud-controller';
|
||||
import { AccessService } from '../service/access-service';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
} from '@midwayjs/core';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { AccessService } from '../service/access-service.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
|
||||
/**
|
||||
* 授权
|
||||
|
||||
+4
-11
@@ -1,14 +1,7 @@
|
||||
import {
|
||||
ALL,
|
||||
Controller,
|
||||
Inject,
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { DnsProviderService } from '../service/dns-provider-service';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import {Constants} from "../../../basic/constants";
|
||||
import { ALL, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { DnsProviderService } from '../service/dns-provider-service.js';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
|
||||
/**
|
||||
* 插件
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
import {
|
||||
ALL,
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Inject,
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { CrudController } from '../../../basic/crud-controller';
|
||||
import { PipelineEntity } from '../entity/pipeline';
|
||||
import { HistoryService } from '../service/history-service';
|
||||
import { HistoryLogService } from '../service/history-log-service';
|
||||
import { HistoryEntity } from '../entity/history';
|
||||
import { HistoryLogEntity } from '../entity/history-log';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { PipelineService } from '../service/pipeline-service';
|
||||
import { CommonException } from '../../../basic/exception/common-exception';
|
||||
import { PermissionException } from '../../../basic/exception/permission-exception';
|
||||
import { ALL, Body, Controller, Get, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { PipelineEntity } from '../entity/pipeline.js';
|
||||
import { HistoryService } from '../service/history-service.js';
|
||||
import { HistoryLogService } from '../service/history-log-service.js';
|
||||
import { HistoryEntity } from '../entity/history.js';
|
||||
import { HistoryLogEntity } from '../entity/history-log.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
import { PipelineService } from '../service/pipeline-service.js';
|
||||
import { CommonException } from '../../../basic/exception/common-exception.js';
|
||||
import { PermissionException } from '../../../basic/exception/permission-exception.js';
|
||||
import * as fs from 'fs';
|
||||
import { logger } from '../../../utils/logger';
|
||||
import { logger } from '../../../utils/logger.js';
|
||||
|
||||
/**
|
||||
* 证书
|
||||
@@ -53,11 +44,7 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||
const buildQuery = qb => {
|
||||
qb.limit(10);
|
||||
};
|
||||
const listRet = await this.getService().list(
|
||||
body,
|
||||
{ prop: 'id', asc: false },
|
||||
buildQuery
|
||||
);
|
||||
const listRet = await this.getService().list(body, { prop: 'id', asc: false }, buildQuery);
|
||||
return this.ok(listRet);
|
||||
}
|
||||
|
||||
@@ -137,11 +124,7 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||
}
|
||||
|
||||
@Get('/download', { summary: Constants.per.authOnly })
|
||||
async download(
|
||||
@Query('pipelineId') pipelineId,
|
||||
@Query('historyId') historyId,
|
||||
@Query('fileId') fileId
|
||||
) {
|
||||
async download(@Query('pipelineId') pipelineId, @Query('historyId') historyId, @Query('fileId') fileId) {
|
||||
const files = await this.getFiles(historyId, pipelineId);
|
||||
const file = files.find(f => f.id === fileId);
|
||||
if (file == null) {
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
import {
|
||||
ALL,
|
||||
Body,
|
||||
Controller,
|
||||
Inject,
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { CrudController } from '../../../basic/crud-controller';
|
||||
import { PipelineService } from '../service/pipeline-service';
|
||||
import { PipelineEntity } from '../entity/pipeline';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
import { HistoryService } from '../service/history-service';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { PipelineService } from '../service/pipeline-service.js';
|
||||
import { PipelineEntity } from '../entity/pipeline.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
import { HistoryService } from '../service/history-service.js';
|
||||
|
||||
/**
|
||||
* 证书
|
||||
|
||||
@@ -5,10 +5,10 @@ import {
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { BaseController } from '../../../basic/base-controller';
|
||||
import { PluginService } from '../service/plugin-service';
|
||||
import { Constants } from '../../../basic/constants';
|
||||
} from '@midwayjs/core';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { PluginService } from '../service/plugin-service.js';
|
||||
import { Constants } from '../../../basic/constants.js';
|
||||
|
||||
/**
|
||||
* 插件
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { HistoryEntity } from '../history';
|
||||
import { HistoryLogEntity } from '../history-log';
|
||||
import { HistoryEntity } from '../history.js';
|
||||
import { HistoryLogEntity } from '../history-log.js';
|
||||
|
||||
export class HistoryDetail {
|
||||
history: HistoryEntity;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PipelineEntity } from '../pipeline';
|
||||
import { HistoryEntity } from '../history';
|
||||
import { HistoryLogEntity } from '../history-log';
|
||||
import { PipelineEntity } from '../pipeline.js';
|
||||
import { HistoryEntity } from '../history.js';
|
||||
import { HistoryLogEntity } from '../history-log.js';
|
||||
|
||||
export class PipelineDetail {
|
||||
pipeline: PipelineEntity;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { AccessEntity } from '../entity/access';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { AccessEntity } from '../entity/access.js';
|
||||
import { accessRegistry, IAccessService } from '@certd/pipeline';
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { IStorage } from '@certd/pipeline';
|
||||
import { StorageService } from './storage-service';
|
||||
import { StorageService } from './storage-service.js';
|
||||
|
||||
export class DbStorage implements IStorage {
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { dnsProviderRegistry } from '@certd/plugin-cert';
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Singleton)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Provide, Scope, ScopeEnum } from "@midwayjs/decorator";
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { HistoryLogEntity } from '../entity/history-log';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { HistoryLogEntity } from '../entity/history-log.js';
|
||||
|
||||
/**
|
||||
* 证书申请
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { HistoryEntity } from '../entity/history';
|
||||
import { PipelineEntity } from '../entity/pipeline';
|
||||
import { HistoryDetail } from '../entity/vo/history-detail';
|
||||
import { HistoryLogService } from './history-log-service';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { HistoryEntity } from '../entity/history.js';
|
||||
import { PipelineEntity } from '../entity/pipeline.js';
|
||||
import { HistoryDetail } from '../entity/vo/history-detail.js';
|
||||
import { HistoryLogService } from './history-log-service.js';
|
||||
import { FileItem, Pipeline, RunnableCollection } from '@certd/pipeline';
|
||||
import { FileStore } from '@certd/pipeline';
|
||||
import { logger } from '../../../utils/logger';
|
||||
import { logger } from '../../../utils/logger.js';
|
||||
|
||||
/**
|
||||
* 证书申请
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { In, Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { PipelineEntity } from '../entity/pipeline';
|
||||
import { PipelineDetail } from '../entity/vo/pipeline-detail';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { PipelineEntity } from '../entity/pipeline.js';
|
||||
import { PipelineDetail } from '../entity/vo/pipeline-detail.js';
|
||||
import { Executor, Pipeline, ResultType, RunHistory } from '@certd/pipeline';
|
||||
import { AccessService } from './access-service';
|
||||
import { DbStorage } from './db-storage';
|
||||
import { StorageService } from './storage-service';
|
||||
import { Cron } from '../../plugin/cron/cron';
|
||||
import { HistoryService } from './history-service';
|
||||
import { HistoryEntity } from '../entity/history';
|
||||
import { HistoryLogEntity } from '../entity/history-log';
|
||||
import { HistoryLogService } from './history-log-service';
|
||||
import { logger } from '../../../utils/logger';
|
||||
import { EmailService } from '../../basic/service/email-service';
|
||||
import { AccessService } from './access-service.js';
|
||||
import { DbStorage } from './db-storage.js';
|
||||
import { StorageService } from './storage-service.js';
|
||||
import { Cron } from '../../plugin/cron/cron.js';
|
||||
import { HistoryService } from './history-service.js';
|
||||
import { HistoryEntity } from '../entity/history.js';
|
||||
import { HistoryLogEntity } from '../entity/history-log.js';
|
||||
import { HistoryLogService } from './history-log-service.js';
|
||||
import { logger } from '../../../utils/logger.js';
|
||||
import { EmailService } from '../../basic/service/email-service.js';
|
||||
|
||||
const runningTasks: Map<string | number, Executor> = new Map();
|
||||
|
||||
@@ -138,7 +138,11 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
cron: null,
|
||||
job: async () => {
|
||||
logger.info('job准备启动,当前定时器数量:', this.cron.getListSize());
|
||||
await this.run(id, null);
|
||||
try {
|
||||
await this.run(id, null);
|
||||
} catch (e) {
|
||||
logger.error('定时job执行失败:', e);
|
||||
}
|
||||
},
|
||||
});
|
||||
logger.info('定时器数量:', this.cron.getListSize());
|
||||
@@ -230,7 +234,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
await executor.run(historyId, triggerType);
|
||||
} catch (e) {
|
||||
logger.error('执行失败:', e);
|
||||
throw e;
|
||||
// throw e;
|
||||
} finally {
|
||||
runningTasks.delete(historyId);
|
||||
}
|
||||
@@ -242,8 +246,8 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
await executor.cancel();
|
||||
} else {
|
||||
const entity = await this.historyService.info(historyId);
|
||||
if(entity == null){
|
||||
return
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
const pipeline: Pipeline = JSON.parse(entity.pipeline);
|
||||
pipeline.status.status = ResultType.canceled;
|
||||
@@ -295,7 +299,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
const entity: HistoryEntity = new HistoryEntity();
|
||||
entity.id = parseInt(history.id);
|
||||
entity.userId = history.pipeline.userId;
|
||||
entity.status = pipelineEntity.status
|
||||
entity.status = pipelineEntity.status;
|
||||
entity.pipeline = JSON.stringify(history.pipeline);
|
||||
entity.pipelineId = parseInt(history.pipeline.id);
|
||||
await this.historyService.save(entity);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Provide, Scope, ScopeEnum } from "@midwayjs/decorator";
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { pluginRegistry } from '@certd/pipeline';
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Singleton)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { StorageEntity } from '../entity/storage';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { StorageEntity } from '../entity/storage.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Config, Configuration, Logger } from '@midwayjs/decorator';
|
||||
import { Config, Configuration, Logger } from '@midwayjs/core';
|
||||
import { ILogger } from '@midwayjs/logger';
|
||||
import { IMidwayContainer } from '@midwayjs/core';
|
||||
import { Cron } from './cron';
|
||||
import { Cron } from './cron.js';
|
||||
|
||||
// ... (see below) ...
|
||||
@Configuration({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// src/index.ts
|
||||
export { CronConfiguration as Configuration } from './configuration';
|
||||
export { CronConfiguration as Configuration } from './configuration.js';
|
||||
// export * from './controller/user';
|
||||
// export * from './controller/api';
|
||||
// export * from './service/user';
|
||||
|
||||
@@ -6,10 +6,10 @@ import {
|
||||
Post,
|
||||
Provide,
|
||||
Query,
|
||||
} from '@midwayjs/decorator';
|
||||
import { CrudController } from '../../../basic/crud-controller';
|
||||
import { SysSettingsService } from '../service/sys-settings-service';
|
||||
import { SysSettingsEntity } from '../entity/sys-settings';
|
||||
} from '@midwayjs/core';
|
||||
import { CrudController } from '../../../basic/crud-controller.js';
|
||||
import { SysSettingsService } from '../service/sys-settings-service.js';
|
||||
import { SysSettingsEntity } from '../entity/sys-settings.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
export class BaseSettings {
|
||||
static __key__: string;
|
||||
static __title__: string;
|
||||
static __access__ = 'private';
|
||||
|
||||
static getCacheKey() {
|
||||
return 'settings.' + this.__key__;
|
||||
}
|
||||
}
|
||||
export class SysPublicSettings extends BaseSettings {
|
||||
static __key__ = 'sys.public';
|
||||
static __title__ = '系统公共设置';
|
||||
static __access__ = 'public';
|
||||
registerEnabled = false;
|
||||
}
|
||||
|
||||
export class SysPrivateSettings extends BaseSettings {
|
||||
static __title__ = '系统私有设置';
|
||||
static __access__ = 'private';
|
||||
static __key__ = 'sys.private';
|
||||
}
|
||||
|
||||
export class SysInstallInfo extends BaseSettings {
|
||||
static __title__ = '系统安装信息';
|
||||
static __key__ = 'sys.install';
|
||||
static __access__ = 'private';
|
||||
installTime: number;
|
||||
siteId?: string;
|
||||
}
|
||||
@@ -1,17 +1,11 @@
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { SysSettingsEntity } from '../entity/sys-settings';
|
||||
import { BaseService } from '../../../basic/base-service.js';
|
||||
import { SysSettingsEntity } from '../entity/sys-settings.js';
|
||||
import { CacheManager } from '@midwayjs/cache';
|
||||
|
||||
const SYS_PUBLIC_KEY = 'sys.public';
|
||||
const SYS_PRIVATE_KEY = 'sys.private';
|
||||
const CACHE_SYS_PUBLIC_KEY = `settings.${SYS_PUBLIC_KEY}`;
|
||||
const CACHE_SYS_PRIVATE_KEY = `settings.${SYS_PRIVATE_KEY}`;
|
||||
export type SysPublicSettings = {
|
||||
registerEnabled: boolean;
|
||||
};
|
||||
import { BaseSettings, SysPublicSettings } from './models.js';
|
||||
import * as _ from 'lodash-es';
|
||||
|
||||
export type SysPrivateSettings = NonNullable<unknown>;
|
||||
|
||||
@@ -77,67 +71,60 @@ export class SysSettingsService extends BaseService<SysSettingsEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
async getPublicSettings(): Promise<SysPublicSettings> {
|
||||
const key = CACHE_SYS_PUBLIC_KEY;
|
||||
let settings: SysPublicSettings = await this.cache.get(key);
|
||||
async getSetting<T>(type: any): Promise<T> {
|
||||
const key = type.__key__;
|
||||
const cacheKey = type.getCacheKey();
|
||||
let settings: T = await this.cache.get(cacheKey);
|
||||
let settingInstance: T = new type();
|
||||
if (settings == null) {
|
||||
settings = await this.readPublicSettings();
|
||||
await this.cache.set(key, settings);
|
||||
settings = await this.getSettingByKey(key);
|
||||
settingInstance = _.merge(settingInstance, settings);
|
||||
await this.cache.set(key, settingInstance);
|
||||
}
|
||||
return settings;
|
||||
return settingInstance;
|
||||
}
|
||||
|
||||
async readPublicSettings(): Promise<SysPublicSettings> {
|
||||
const key = SYS_PUBLIC_KEY;
|
||||
async saveSetting<T extends BaseSettings>(bean: T) {
|
||||
const type: any = bean.constructor;
|
||||
const key = type.__key__;
|
||||
const cacheKey = type.getCacheKey();
|
||||
|
||||
const entity = await this.getByKey(key);
|
||||
if (!entity) {
|
||||
return {
|
||||
registerEnabled: false,
|
||||
};
|
||||
if (entity) {
|
||||
entity.setting = JSON.stringify(bean);
|
||||
await this.repository.save(entity);
|
||||
} else {
|
||||
const newEntity = new SysSettingsEntity();
|
||||
newEntity.key = key;
|
||||
newEntity.title = type.__title__;
|
||||
newEntity.setting = JSON.stringify(bean);
|
||||
newEntity.access = type.__access__;
|
||||
await this.repository.save(newEntity);
|
||||
}
|
||||
return JSON.parse(entity.setting);
|
||||
|
||||
await this.cache.set(cacheKey, bean);
|
||||
}
|
||||
|
||||
async getPublicSettings(): Promise<SysPublicSettings> {
|
||||
return await this.getSetting(SysPublicSettings);
|
||||
}
|
||||
|
||||
async savePublicSettings(bean: SysPublicSettings) {
|
||||
const key = SYS_PUBLIC_KEY;
|
||||
const entity = await this.getByKey(key);
|
||||
if (entity) {
|
||||
entity.setting = JSON.stringify(bean);
|
||||
await this.repository.save(entity);
|
||||
} else {
|
||||
const newEntity = new SysSettingsEntity();
|
||||
newEntity.key = key;
|
||||
newEntity.title = '系统公共设置';
|
||||
newEntity.setting = JSON.stringify(bean);
|
||||
newEntity.access = 'public';
|
||||
await this.repository.save(newEntity);
|
||||
}
|
||||
await this.cache.del(CACHE_SYS_PRIVATE_KEY);
|
||||
}
|
||||
|
||||
async readPrivateSettings(): Promise<SysPrivateSettings> {
|
||||
const key = SYS_PRIVATE_KEY;
|
||||
const entity = await this.getByKey(key);
|
||||
if (!entity) {
|
||||
return {};
|
||||
}
|
||||
return JSON.parse(entity.setting);
|
||||
await this.saveSetting(bean);
|
||||
}
|
||||
|
||||
async savePrivateSettings(bean: SysPrivateSettings) {
|
||||
const key = SYS_PRIVATE_KEY;
|
||||
this.saveSetting(bean);
|
||||
}
|
||||
|
||||
async updateByKey(key: string, setting: any) {
|
||||
const entity = await this.getByKey(key);
|
||||
if (entity) {
|
||||
entity.setting = JSON.stringify(bean);
|
||||
entity.setting = JSON.stringify(setting);
|
||||
await this.repository.save(entity);
|
||||
} else {
|
||||
const newEntity = new SysSettingsEntity();
|
||||
newEntity.key = key;
|
||||
newEntity.title = '系统私有设置';
|
||||
newEntity.setting = JSON.stringify(bean);
|
||||
newEntity.access = 'private';
|
||||
await this.repository.save(newEntity);
|
||||
throw new Error('该设置不存在');
|
||||
}
|
||||
await this.cache.del(CACHE_SYS_PRIVATE_KEY);
|
||||
await this.cache.del(`settings.${key}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export * from '@certd/plugin-cert';
|
||||
export * from './plugin-aliyun';
|
||||
export * from './plugin-tencent';
|
||||
export * from './plugin-host';
|
||||
export * from './plugin-huawei';
|
||||
export * from './plugin-demo';
|
||||
export * from './plugin-aliyun/index.js';
|
||||
export * from './plugin-tencent/index.js';
|
||||
export * from './plugin-host/index.js';
|
||||
export * from './plugin-huawei/index.js';
|
||||
export * from './plugin-demo/index.js';
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from './aliyun-access';
|
||||
export * from './aliyun-access.js';
|
||||
|
||||
+12
-7
@@ -1,7 +1,12 @@
|
||||
import Core from "@alicloud/pop-core";
|
||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { Autowire, ILogger } from "@certd/pipeline";
|
||||
import { AliyunAccess } from "../access";
|
||||
import Core from '@alicloud/pop-core';
|
||||
import {
|
||||
AbstractDnsProvider,
|
||||
CreateRecordOptions,
|
||||
IsDnsProvider,
|
||||
RemoveRecordOptions,
|
||||
} from '@certd/plugin-cert';
|
||||
import { Autowire, ILogger } from '@certd/pipeline';
|
||||
import { AliyunAccess } from '../access/index.js';
|
||||
|
||||
@IsDnsProvider({
|
||||
name: 'aliyun',
|
||||
@@ -9,7 +14,7 @@ import { AliyunAccess } from "../access";
|
||||
desc: '阿里云DNS解析提供商',
|
||||
accessType: 'aliyun',
|
||||
})
|
||||
export class AliyunDnsProvider extends AbstractDnsProvider{
|
||||
export class AliyunDnsProvider extends AbstractDnsProvider {
|
||||
client: any;
|
||||
@Autowire()
|
||||
access!: AliyunAccess;
|
||||
@@ -86,8 +91,8 @@ export class AliyunDnsProvider extends AbstractDnsProvider{
|
||||
// }
|
||||
|
||||
async createRecord(options: CreateRecordOptions): Promise<any> {
|
||||
const { fullRecord, value, type,domain } = options;
|
||||
this.logger.info('添加域名解析:', fullRecord, value,domain);
|
||||
const { fullRecord, value, type, domain } = options;
|
||||
this.logger.info('添加域名解析:', fullRecord, value, domain);
|
||||
// const domain = await this.matchDomain(fullRecord);
|
||||
const rr = fullRecord.replace('.' + domain, '');
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
import './aliyun-dns-provider';
|
||||
import './aliyun-dns-provider.js';
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './access/index';
|
||||
export * from './dns-provider/index';
|
||||
export * from './plugin/index';
|
||||
export * from './access/index.js';
|
||||
export * from './dns-provider/index.js';
|
||||
export * from './plugin/index.js';
|
||||
|
||||
+3
-3
@@ -9,9 +9,9 @@ import {
|
||||
} from '@certd/pipeline';
|
||||
// @ts-ignore
|
||||
import { ROAClient } from '@alicloud/pop-core';
|
||||
import { AliyunAccess } from '../../access';
|
||||
import { K8sClient } from '@certd/plugin-util';
|
||||
import { appendTimeSuffix } from '../../utils';
|
||||
import { AliyunAccess } from '../../access/index.js';
|
||||
import { K8sClient } from '@certd/lib-k8s';
|
||||
import { appendTimeSuffix } from '../../utils/index.js';
|
||||
import { CertInfo } from '@certd/plugin-cert';
|
||||
|
||||
@IsTaskPlugin({
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
import dayjs from 'dayjs';
|
||||
import Core from '@alicloud/pop-core';
|
||||
import RPCClient from '@alicloud/pop-core';
|
||||
import { AliyunAccess } from '../../access';
|
||||
import { AliyunAccess } from '../../access/index.js';
|
||||
|
||||
@IsTaskPlugin({
|
||||
name: 'DeployCertToAliyunCDN',
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './deploy-to-cdn/index';
|
||||
export * from './deploy-to-ack-ingress/index';
|
||||
export * from './upload-to-aliyun/index';
|
||||
export * from './deploy-to-cdn/index.js';
|
||||
export * from './deploy-to-ack-ingress/index.js';
|
||||
export * from './upload-to-aliyun/index.js';
|
||||
|
||||
@@ -7,8 +7,8 @@ import {
|
||||
TaskOutput,
|
||||
} from '@certd/pipeline';
|
||||
import Core from '@alicloud/pop-core';
|
||||
import { AliyunAccess } from '../../access';
|
||||
import { appendTimeSuffix, checkRet, ZoneOptions } from '../../utils';
|
||||
import { AliyunAccess } from '../../access/index.js';
|
||||
import { appendTimeSuffix, checkRet, ZoneOptions } from '../../utils/index.js';
|
||||
import { Logger } from 'log4js';
|
||||
|
||||
@IsTaskPlugin({
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { Autowire, HttpClient, ILogger } from "@certd/pipeline";
|
||||
import { CloudflareAccess } from "./access";
|
||||
import {
|
||||
AbstractDnsProvider,
|
||||
CreateRecordOptions,
|
||||
IsDnsProvider,
|
||||
RemoveRecordOptions,
|
||||
} from '@certd/plugin-cert';
|
||||
import { Autowire, HttpClient, ILogger } from '@certd/pipeline';
|
||||
import { CloudflareAccess } from './access.js';
|
||||
|
||||
export type CloudflareRecord = {
|
||||
id: string;
|
||||
@@ -15,7 +20,6 @@ export type CloudflareRecord = {
|
||||
modified_on: string;
|
||||
};
|
||||
|
||||
|
||||
// 这里通过IsDnsProvider注册一个dnsProvider
|
||||
@IsDnsProvider({
|
||||
name: 'cloudflare',
|
||||
@@ -24,94 +28,96 @@ export type CloudflareRecord = {
|
||||
// 这里是对应的 cloudflare的access类型名称
|
||||
accessType: 'cloudflare',
|
||||
})
|
||||
export class CloudflareDnsProvider extends AbstractDnsProvider<CloudflareRecord>{
|
||||
export class CloudflareDnsProvider extends AbstractDnsProvider<CloudflareRecord> {
|
||||
// 通过Autowire传递context
|
||||
@Autowire()
|
||||
logger! : ILogger;
|
||||
logger!: ILogger;
|
||||
access!: CloudflareAccess;
|
||||
http!: HttpClient;
|
||||
async onInstance() {
|
||||
//一些初始化的操作
|
||||
// 也可以通过ctx成员变量传递context, 与Autowire效果一样
|
||||
this.access = this.ctx.access as CloudflareAccess;
|
||||
this.http = this.ctx.http
|
||||
this.http = this.ctx.http;
|
||||
}
|
||||
|
||||
|
||||
async getZoneId(domain:string){
|
||||
async getZoneId(domain: string) {
|
||||
const url = `https://api.cloudflare.com/client/v4/zones?name=${domain}`;
|
||||
const res = await this.doRequestApi(url,null,"get");
|
||||
return res.result[0].id
|
||||
const res = await this.doRequestApi(url, null, 'get');
|
||||
return res.result[0].id;
|
||||
}
|
||||
|
||||
|
||||
private async doRequestApi(url: string,data:any = null,method:string="post") {
|
||||
const res = await this.http.request<any,any>({
|
||||
url,
|
||||
method,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${this.access.apiToken}`,
|
||||
},
|
||||
data
|
||||
});
|
||||
if (!res.success) {
|
||||
throw new Error(`${JSON.stringify(res.errors)}`);
|
||||
}
|
||||
return res
|
||||
private async doRequestApi(url: string, data: any = null, method = 'post') {
|
||||
const res = await this.http.request<any, any>({
|
||||
url,
|
||||
method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${this.access.apiToken}`,
|
||||
},
|
||||
data,
|
||||
});
|
||||
if (!res.success) {
|
||||
throw new Error(`${JSON.stringify(res.errors)}`);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建dns解析记录,用于验证域名所有权
|
||||
* 创建dns解析记录,用于验证域名所有权
|
||||
*/
|
||||
async createRecord(options: CreateRecordOptions): Promise<CloudflareRecord> {
|
||||
|
||||
/**
|
||||
* fullRecord: '_acme-challenge.test.example.com',
|
||||
* value: 一串uuid
|
||||
* type: 'TXT',
|
||||
* domain: 'example.com'
|
||||
*/
|
||||
const { fullRecord, value, type,domain } = options;
|
||||
this.logger.info('添加域名解析:', fullRecord, value, type,domain);
|
||||
const { fullRecord, value, type, domain } = options;
|
||||
this.logger.info('添加域名解析:', fullRecord, value, type, domain);
|
||||
|
||||
const zoneId = await this.getZoneId(domain);
|
||||
this.logger.info('获取zoneId成功:',zoneId)
|
||||
this.logger.info('获取zoneId成功:', zoneId);
|
||||
|
||||
// 给domain下创建txt类型的dns解析记录,fullRecord
|
||||
let url = `https://api.cloudflare.com/client/v4/zones/${zoneId}/dns_records`;
|
||||
const url = `https://api.cloudflare.com/client/v4/zones/${zoneId}/dns_records`;
|
||||
const res = await this.doRequestApi(url, {
|
||||
content: value,
|
||||
name: fullRecord,
|
||||
type: type,
|
||||
ttl: 60,
|
||||
})
|
||||
content: value,
|
||||
name: fullRecord,
|
||||
type: type,
|
||||
ttl: 60,
|
||||
});
|
||||
const record = res.result as CloudflareRecord;
|
||||
this.logger.info(`添加域名解析成功:fullRecord=${fullRecord},value=${value}`);
|
||||
this.logger.info(`dns解析记录:${JSON.stringify(record)}`,)
|
||||
this.logger.info(
|
||||
`添加域名解析成功:fullRecord=${fullRecord},value=${value}`
|
||||
);
|
||||
this.logger.info(`dns解析记录:${JSON.stringify(record)}`);
|
||||
|
||||
//本接口需要返回本次创建的dns解析记录,这个记录会在删除的时候用到
|
||||
return record
|
||||
return record;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除dns解析记录,清理申请痕迹
|
||||
* @param options
|
||||
*/
|
||||
async removeRecord(options: RemoveRecordOptions<CloudflareRecord>): Promise<void> {
|
||||
async removeRecord(
|
||||
options: RemoveRecordOptions<CloudflareRecord>
|
||||
): Promise<void> {
|
||||
const { fullRecord, value, record } = options;
|
||||
this.logger.info('删除域名解析:', fullRecord, value);
|
||||
if(!record){
|
||||
if (!record) {
|
||||
this.logger.info('record不存在');
|
||||
return
|
||||
return;
|
||||
}
|
||||
//这里调用删除txt dns解析记录接口
|
||||
const zoneId = record.zone_id;
|
||||
const recordId = record.id;
|
||||
let url = `https://api.cloudflare.com/client/v4/zones/${zoneId}/dns_records/${recordId}`;
|
||||
await this.doRequestApi(url,null,"delete")
|
||||
this.logger.info(`删除域名解析成功:fullRecord=${fullRecord},value=${value}`);
|
||||
const url = `https://api.cloudflare.com/client/v4/zones/${zoneId}/dns_records/${recordId}`;
|
||||
await this.doRequestApi(url, null, 'delete');
|
||||
this.logger.info(
|
||||
`删除域名解析成功:fullRecord=${fullRecord},value=${value}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './dns-provider';
|
||||
export * from './plugins';
|
||||
export * from './access';
|
||||
export * from './dns-provider.js';
|
||||
export * from './plugins/index.js';
|
||||
export * from './access.js';
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from './plugin-deploy-to-cdn';
|
||||
export * from './plugin-deploy-to-cdn.js';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IsAccess, AccessInput, IAccess } from "@certd/pipeline";
|
||||
import { IsAccess, AccessInput, IAccess } from '@certd/pipeline';
|
||||
|
||||
/**
|
||||
* 这个注解将注册一个授权配置
|
||||
@@ -9,7 +9,7 @@ import { IsAccess, AccessInput, IAccess } from "@certd/pipeline";
|
||||
title: '授权插件示例',
|
||||
desc: '',
|
||||
})
|
||||
export class DemoAccess implements IAccess{
|
||||
export class DemoAccess implements IAccess {
|
||||
/**
|
||||
* 授权属性配置
|
||||
*/
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { Autowire, HttpClient, ILogger } from "@certd/pipeline";
|
||||
import { DemoAccess } from "./access";
|
||||
|
||||
import {
|
||||
AbstractDnsProvider,
|
||||
CreateRecordOptions,
|
||||
IsDnsProvider,
|
||||
RemoveRecordOptions,
|
||||
} from '@certd/plugin-cert';
|
||||
import { Autowire, HttpClient, ILogger } from '@certd/pipeline';
|
||||
import { DemoAccess } from './access.js';
|
||||
|
||||
type DemoRecord = {
|
||||
// 这里定义Record记录的数据结构,跟对应云平台接口返回值一样即可,一般是拿到id就行,用于删除txt解析记录,清理申请痕迹
|
||||
// id:string
|
||||
}
|
||||
};
|
||||
|
||||
// 这里通过IsDnsProvider注册一个dnsProvider
|
||||
@IsDnsProvider({
|
||||
name: "demo",
|
||||
title: "Dns提供商Demo",
|
||||
desc: "dns provider示例",
|
||||
name: 'demo',
|
||||
title: 'Dns提供商Demo',
|
||||
desc: 'dns provider示例',
|
||||
// 这里是对应的云平台的access类型名称
|
||||
accessType: "demo"
|
||||
accessType: 'demo',
|
||||
})
|
||||
export class DemoDnsProvider extends AbstractDnsProvider<DemoRecord> {
|
||||
// 通过Autowire注入工具对象
|
||||
@@ -27,12 +31,11 @@ export class DemoDnsProvider extends AbstractDnsProvider<DemoRecord> {
|
||||
async onInstance() {
|
||||
// 也可以通过ctx成员变量传递context, 与Autowire效果一样
|
||||
this.http = this.ctx.http;
|
||||
this.logger.debug("access", this.access);
|
||||
this.logger.debug('access', this.access);
|
||||
//初始化的操作
|
||||
//...
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建dns解析记录,用于验证域名所有权
|
||||
*/
|
||||
@@ -45,7 +48,7 @@ export class DemoDnsProvider extends AbstractDnsProvider<DemoRecord> {
|
||||
* domain: 'example.com'
|
||||
*/
|
||||
const { fullRecord, value, type, domain } = options;
|
||||
this.logger.info("添加域名解析:", fullRecord, value, type, domain);
|
||||
this.logger.info('添加域名解析:', fullRecord, value, type, domain);
|
||||
|
||||
// 调用创建dns解析记录的对应的云端接口,创建txt类型的dns解析记录
|
||||
// 请根据实际接口情况调用,例如:
|
||||
@@ -64,7 +67,7 @@ export class DemoDnsProvider extends AbstractDnsProvider<DemoRecord> {
|
||||
*/
|
||||
async removeRecord(options: RemoveRecordOptions<DemoRecord>): Promise<void> {
|
||||
const { fullRecord, value, record } = options;
|
||||
this.logger.info("删除域名解析:", fullRecord, value, record);
|
||||
this.logger.info('删除域名解析:', fullRecord, value, record);
|
||||
//这里调用删除txt dns解析记录接口
|
||||
//请根据实际接口情况调用,例如:
|
||||
|
||||
@@ -75,7 +78,7 @@ export class DemoDnsProvider extends AbstractDnsProvider<DemoRecord> {
|
||||
// })
|
||||
//
|
||||
|
||||
this.logger.info("删除域名解析成功:", fullRecord, value);
|
||||
this.logger.info('删除域名解析成功:', fullRecord, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './dns-provider';
|
||||
export * from './plugins';
|
||||
export * from './access';
|
||||
export * from './dns-provider.js';
|
||||
export * from './plugins/index.js';
|
||||
export * from './access.js';
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from './plugin-test';
|
||||
export * from './plugin-test.js';
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from './ssh-access';
|
||||
export * from './ssh-access.js';
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './access';
|
||||
export * from './lib/ssh';
|
||||
export * from './plugin';
|
||||
export * from './access/index.js';
|
||||
export * from './lib/ssh.js';
|
||||
export * from './plugin/index.js';
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
// @ts-ignore
|
||||
import ssh2, { ConnectConfig } from 'ssh2';
|
||||
import path from 'path';
|
||||
import _ from 'lodash';
|
||||
import * as _ from 'lodash-es';
|
||||
import { ILogger } from '@certd/pipeline';
|
||||
import iconv from 'iconv-lite';
|
||||
import {SshAccess} from "../access";
|
||||
import { SshAccess } from '../access/index.js';
|
||||
export class AsyncSsh2Client {
|
||||
conn: ssh2.Client;
|
||||
logger: ILogger;
|
||||
connConf: ssh2.ConnectConfig;
|
||||
windows:boolean = false;
|
||||
encoding:string;
|
||||
windows = false;
|
||||
encoding: string;
|
||||
constructor(connConf: SshAccess, logger: ILogger) {
|
||||
this.connConf = connConf;
|
||||
this.logger = logger;
|
||||
@@ -19,7 +19,7 @@ export class AsyncSsh2Client {
|
||||
}
|
||||
|
||||
convert(buffer: Buffer) {
|
||||
if(this.encoding){
|
||||
if (this.encoding) {
|
||||
return iconv.decode(buffer, this.encoding);
|
||||
}
|
||||
return buffer.toString();
|
||||
@@ -31,6 +31,7 @@ export class AsyncSsh2Client {
|
||||
const conn = new ssh2.Client();
|
||||
conn
|
||||
.on('error', (err: any) => {
|
||||
this.logger.error('连接失败', err);
|
||||
reject(err);
|
||||
})
|
||||
.on('ready', () => {
|
||||
@@ -77,7 +78,7 @@ export class AsyncSsh2Client {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
let data: string = '';
|
||||
let data = '';
|
||||
stream
|
||||
.on('close', (code: any, signal: any) => {
|
||||
this.logger.info(`[${this.connConf.host}][close]:code:${code}`);
|
||||
@@ -88,13 +89,13 @@ export class AsyncSsh2Client {
|
||||
}
|
||||
})
|
||||
.on('data', (ret: Buffer) => {
|
||||
const out = this.convert(ret)
|
||||
data += out
|
||||
const out = this.convert(ret);
|
||||
data += out;
|
||||
this.logger.info(`[${this.connConf.host}][info]: ` + out.trimEnd());
|
||||
})
|
||||
.stderr.on('data', (ret:Buffer) => {
|
||||
const err = this.convert(ret)
|
||||
data += err
|
||||
.stderr.on('data', (ret: Buffer) => {
|
||||
const err = this.convert(ret);
|
||||
data += err;
|
||||
this.logger.info(`[${this.connConf.host}][error]: ` + err.trimEnd());
|
||||
});
|
||||
});
|
||||
@@ -103,9 +104,7 @@ export class AsyncSsh2Client {
|
||||
|
||||
async shell(script: string | string[]): Promise<string[]> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
this.logger.info(
|
||||
`执行shell脚本:[${this.connConf.host}][shell]: ` + script
|
||||
);
|
||||
this.logger.info(`执行shell脚本:[${this.connConf.host}][shell]: ` + script);
|
||||
this.conn.shell((err: Error, stream: any) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
@@ -118,15 +117,15 @@ export class AsyncSsh2Client {
|
||||
resolve(output);
|
||||
})
|
||||
.on('data', (ret: Buffer) => {
|
||||
const data = this.convert(ret)
|
||||
const data = this.convert(ret);
|
||||
this.logger.info('' + data);
|
||||
output.push(data);
|
||||
})
|
||||
.stderr.on('data', (ret:Buffer) => {
|
||||
const data = this.convert(ret)
|
||||
.stderr.on('data', (ret: Buffer) => {
|
||||
const data = this.convert(ret);
|
||||
output.push(data);
|
||||
this.logger.info(`[${this.connConf.host}][error]: ` + data);
|
||||
});
|
||||
});
|
||||
stream.end(script + '\nexit\n');
|
||||
});
|
||||
});
|
||||
@@ -161,15 +160,15 @@ export class SshClient {
|
||||
const sftp = await conn.getSftp();
|
||||
this.logger.info('开始上传');
|
||||
for (const transport of transports) {
|
||||
let filePath = path.dirname(transport.remotePath);
|
||||
const filePath = path.dirname(transport.remotePath);
|
||||
let mkdirCmd = `mkdir -p ${filePath} `;
|
||||
if(conn.windows){
|
||||
if(filePath.indexOf("/") > -1){
|
||||
this.logger.info("--------------------------")
|
||||
this.logger.info("请注意:windows下,文件目录分隔应该写成\\而不是/")
|
||||
this.logger.info("--------------------------")
|
||||
if (conn.windows) {
|
||||
if (filePath.indexOf('/') > -1) {
|
||||
this.logger.info('--------------------------');
|
||||
this.logger.info('请注意:windows下,文件目录分隔应该写成\\而不是/');
|
||||
this.logger.info('--------------------------');
|
||||
}
|
||||
const spec = await conn.exec(`echo %COMSPEC%`);
|
||||
const spec = await conn.exec('echo %COMSPEC%');
|
||||
if (spec.toString().trim() === '%COMSPEC%') {
|
||||
mkdirCmd = `New-Item -ItemType Directory -Path "${filePath}" -Force`;
|
||||
} else {
|
||||
@@ -184,10 +183,7 @@ export class SshClient {
|
||||
});
|
||||
}
|
||||
|
||||
async exec(options: {
|
||||
connectConf: SshAccess;
|
||||
script: string | Array<string>;
|
||||
}) {
|
||||
async exec(options: { connectConf: SshAccess; script: string | Array<string> }) {
|
||||
let { script } = options;
|
||||
const { connectConf } = options;
|
||||
if (_.isArray(script)) {
|
||||
@@ -203,10 +199,7 @@ export class SshClient {
|
||||
});
|
||||
}
|
||||
|
||||
async shell(options: {
|
||||
connectConf: SshAccess;
|
||||
script: string;
|
||||
}): Promise<string[]> {
|
||||
async shell(options: { connectConf: SshAccess; script: string }): Promise<string[]> {
|
||||
const { connectConf, script } = options;
|
||||
return await this._call({
|
||||
connectConf,
|
||||
@@ -216,10 +209,7 @@ export class SshClient {
|
||||
});
|
||||
}
|
||||
|
||||
async _call(options: {
|
||||
connectConf: SshAccess;
|
||||
callable: any;
|
||||
}): Promise<string[]> {
|
||||
async _call(options: { connectConf: SshAccess; callable: any }): Promise<string[]> {
|
||||
const { connectConf, callable } = options;
|
||||
const conn = new AsyncSsh2Client(connectConf, this.logger);
|
||||
await conn.connect();
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
RunStrategy,
|
||||
TaskInput,
|
||||
} from '@certd/pipeline';
|
||||
import { SshClient } from '../../lib/ssh';
|
||||
import { SshClient } from '../../lib/ssh.js';
|
||||
|
||||
@IsTaskPlugin({
|
||||
name: 'hostShellExecute',
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from './host-shell-execute';
|
||||
export * from './upload-to-host';
|
||||
export * from './host-shell-execute/index.js';
|
||||
export * from './upload-to-host/index.js';
|
||||
|
||||
@@ -7,10 +7,10 @@ import {
|
||||
TaskInput,
|
||||
TaskOutput,
|
||||
} from '@certd/pipeline';
|
||||
import { SshClient } from '../../lib/ssh';
|
||||
import { SshClient } from '../../lib/ssh.js';
|
||||
import { CertInfo, CertReader } from '@certd/plugin-cert';
|
||||
import * as fs from 'fs';
|
||||
import {SshAccess} from "../../access";
|
||||
import { SshAccess } from '../../access/index.js';
|
||||
|
||||
@IsTaskPlugin({
|
||||
name: 'uploadCertToHost',
|
||||
@@ -113,7 +113,7 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
|
||||
throw new Error('主机登录授权配置不能为空');
|
||||
}
|
||||
this.logger.info('准备上传到服务器');
|
||||
const connectConf:SshAccess = await this.accessService.getById(accessId);
|
||||
const connectConf: SshAccess = await this.accessService.getById(accessId);
|
||||
const sshClient = new SshClient(this.logger);
|
||||
await sshClient.uploadFiles({
|
||||
connectConf,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user