perf: EAB授权支持绑定邮箱,支持公共EAB设置

This commit is contained in:
xiaojunnuo
2024-10-14 03:17:10 +08:00
parent e8b617b80c
commit 07043aff0c
32 changed files with 374 additions and 57 deletions
@@ -24,7 +24,7 @@ export class CnameRecordController extends CrudController<CnameRecordService> {
const bq = qb => {
if (domain) {
qb.where('domain like :domain', { domain: `%${domain}%` });
qb.andWhere('domain like :domain', { domain: `%${domain}%` });
}
};
@@ -21,7 +21,7 @@ export class AccessController extends CrudController<AccessService> {
body.query = body.query ?? {};
delete body.query.userId;
const buildQuery = qb => {
qb.where('user_id = :userId', { userId: this.getUserId() });
qb.andWhere('user_id = :userId', { userId: this.getUserId() });
};
const res = await this.service.page({
query: body.query,
@@ -51,7 +51,7 @@ export class HistoryController extends CrudController<HistoryService> {
const pipelines = await this.pipelineService.list({
query: pipelineQuery,
buildQuery: qb => {
qb.where('title like :title', { title: `%${pipelineTitle}%` });
qb.andWhere('title like :title', { title: `%${pipelineTitle}%` });
},
});
pipelineIds = pipelines.map(p => p.id);
@@ -59,7 +59,7 @@ export class HistoryController extends CrudController<HistoryService> {
const buildQuery = qb => {
if (pipelineIds) {
qb.where({
qb.andWhere({
pipelineId: In(pipelineIds),
});
}
@@ -37,7 +37,7 @@ export class PipelineController extends CrudController<PipelineService> {
const buildQuery = qb => {
if (title) {
qb.where('title like :title', { title: `%${title}%` });
qb.andWhere('title like :title', { title: `%${title}%` });
}
};
if (!body.sort || !body.sort?.prop) {
@@ -1,6 +1,7 @@
import { ALL, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { BaseController, Constants } from '@certd/lib-server';
import { PluginService } from '../../modules/plugin/service/plugin-service.js';
import { PluginConfigService } from '../../modules/plugin/service/plugin-config-service.js';
/**
* 插件
@@ -11,6 +12,9 @@ export class PluginController extends BaseController {
@Inject()
service: PluginService;
@Inject()
pluginConfigService: PluginConfigService;
@Post('/list', { summary: Constants.per.authOnly })
async list(@Query(ALL) query: any) {
query.userId = this.getUserId();
@@ -24,4 +28,10 @@ export class PluginController extends BaseController {
const group = await this.service.getEnabledBuildInGroup();
return this.ok(group);
}
@Post('/config', { summary: Constants.per.authOnly })
async config(@Body(ALL) body: { id?: number; name?: string; type: string }) {
const config = await this.pluginConfigService.getPluginConfig(body);
return this.ok(config);
}
}
@@ -3,6 +3,7 @@ import { merge } from 'lodash-es';
import { CrudController } from '@certd/lib-server';
import { PluginService } from '../../../modules/plugin/service/plugin-service.js';
import { checkComm } from '@certd/pipeline';
import { CommPluginConfig, PluginConfigService } from '../../../modules/plugin/service/plugin-config-service.js';
/**
* 插件
@@ -13,6 +14,9 @@ export class PluginController extends CrudController<PluginService> {
@Inject()
service: PluginService;
@Inject()
pluginConfigService: PluginConfigService;
getService() {
checkComm();
return this.service;
@@ -65,4 +69,15 @@ export class PluginController extends CrudController<PluginService> {
await this.service.setDisabled(body);
return this.ok();
}
@Post('/getCommPluginConfigs', { summary: 'sys:settings:edit' })
async getCommPluginConfigs() {
const res = await this.pluginConfigService.getCommPluginConfig();
return this.ok(res);
}
@Post('/saveCommPluginConfigs', { summary: 'sys:settings:edit' })
async saveCommPluginConfigs(@Body(ALL) body: CommPluginConfig) {
const res = await this.pluginConfigService.saveCommPluginConfig(body);
return this.ok(res);
}
}
@@ -1,10 +1,10 @@
import { Config, Inject, Provide, Scope, ScopeEnum, sleep } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { In, Repository } from 'typeorm';
import { BaseService, PageReq } from '@certd/lib-server';
import { BaseService, NeedVIPException, PageReq } from '@certd/lib-server';
import { PipelineEntity } from '../entity/pipeline.js';
import { PipelineDetail } from '../entity/vo/pipeline-detail.js';
import { Executor, isPlus, Pipeline, ResultType, RunHistory, UserInfo } from '@certd/pipeline';
import { Executor, isPlus, logger, Pipeline, ResultType, RunHistory, UserInfo } from '@certd/pipeline';
import { AccessService } from './access-service.js';
import { DbStorage } from './db-storage.js';
import { StorageService } from './storage-service.js';
@@ -13,14 +13,12 @@ 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 '@certd/pipeline';
import { EmailService } from '../../basic/service/email-service.js';
import { NeedVIPException } from '@certd/lib-server';
import { UserService } from '../../sys/authority/service/user-service.js';
import { AccessGetter } from './access-getter.js';
import { CnameRecordService } from '../../cname/service/cname-record-service.js';
import { CnameProxyService } from './cname-proxy-service.js';
import { PluginConfigService } from './plugin-config-service.js';
import { PluginConfigGetter } from '../../plugin/service/plugin-config-getter.js';
const runningTasks: Map<string | number, Executor> = new Map();
const freeCount = 10;
@@ -47,7 +45,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
historyLogService: HistoryLogService;
@Inject()
pluginConfigService: PluginConfigService;
pluginConfigGetter: PluginConfigGetter;
@Inject()
userService: UserService;
@@ -360,7 +358,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
onChanged,
accessService: accessGetter,
cnameProxyService,
pluginConfigService: this.pluginConfigService,
pluginConfigService: this.pluginConfigGetter,
storage: new DbStorage(userId, this.storageService),
emailService: this.emailService,
fileRootDir: this.certdConfig.fileRootDir,
@@ -1,13 +0,0 @@
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { IPluginConfigService } from '@certd/pipeline';
/**
* 授权
*/
@Provide()
@Scope(ScopeEnum.Singleton)
export class PluginConfigService implements IPluginConfigService {
getPluginConfig(pluginName: string) {
return Promise.resolve({});
}
}
@@ -23,7 +23,7 @@ export class PluginEntity {
@Column({ comment: '配置', length: 40960 })
setting: string;
@Column({ comment: '系统配置', length: 40960 })
@Column({ name: 'sys_setting', comment: '系统配置', length: 40960 })
sysSetting: string;
@Column({ comment: '脚本', length: 40960 })
@@ -0,0 +1,22 @@
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { IPluginConfigService, PluginConfig } from '@certd/pipeline';
import { PluginConfigService } from './plugin-config-service.js';
@Provide()
@Scope(ScopeEnum.Singleton)
export class PluginConfigGetter implements IPluginConfigService {
@Inject()
pluginConfigService: PluginConfigService;
async getPluginConfig(pluginName: string): Promise<PluginConfig> {
const res = await this.pluginConfigService.getPluginConfig({
name: pluginName,
type: 'builtIn',
});
return {
name: res.name,
disabled: res.disabled,
sysSetting: res.sysSetting,
};
}
}
@@ -0,0 +1,79 @@
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { PluginService } from './plugin-service.js';
export type PluginConfig = {
name: string;
disabled: boolean;
sysSetting: {
input?: Record<string, any>;
};
};
export type CommPluginConfig = {
CertApply?: PluginConfig;
};
export type PluginFindReq = {
id?: number;
name?: string;
type: string;
};
@Provide()
@Scope(ScopeEnum.Singleton)
export class PluginConfigService {
@Inject()
pluginService: PluginService;
async getCommPluginConfig() {
const configs: CommPluginConfig = {};
configs.CertApply = await this.getPluginConfig({
name: 'CertApply',
type: 'builtIn',
});
return configs;
}
async saveCommPluginConfig(body: CommPluginConfig) {
const certApplyConfig = body.CertApply;
const CertApply = await this.pluginService.getRepository().findOne({
where: { name: 'CertApply' },
});
if (!CertApply) {
await this.pluginService.add({
name: 'CertApply',
sysSetting: JSON.stringify(certApplyConfig),
type: 'builtIn',
disabled: false,
});
} else {
await this.pluginService.getRepository().update({ name: 'CertApply' }, { sysSetting: JSON.stringify(certApplyConfig) });
}
}
async get(req: PluginFindReq) {
if (!req.name && !req.id) {
throw new Error('plugin s name or id is required');
}
return await this.pluginService.getRepository().findOne({
where: {
id: req.id,
name: req.name,
type: req.type,
},
});
}
async getPluginConfig(req: PluginFindReq) {
const plugin = await this.get(req);
let sysSetting: any = {};
if (plugin && plugin.sysSetting) {
sysSetting = JSON.parse(plugin.sysSetting);
}
return {
name: plugin.name,
disabled: plugin.disabled,
sysSetting,
};
}
}