chore: format

This commit is contained in:
xiaojunnuo
2026-05-31 01:41:33 +08:00
parent acd440106b
commit 4b57a0d729
557 changed files with 12530 additions and 14039 deletions
@@ -1,16 +1,16 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { Constants, CrudController } from '@certd/lib-server';
import { AccessService } from '@certd/lib-server';
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
import { AccessDefine } from '@certd/pipeline';
import { ApiTags } from '@midwayjs/swagger';
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
import { Constants, CrudController } from "@certd/lib-server";
import { AccessService } from "@certd/lib-server";
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
import { AccessDefine } from "@certd/pipeline";
import { ApiTags } from "@midwayjs/swagger";
/**
* 授权
*/
@Provide()
@ApiTags(['pipeline-access'])
@Controller('/api/pi/access')
@ApiTags(["pipeline-access"])
@Controller("/api/pi/access")
export class AccessController extends CrudController<AccessService> {
@Inject()
service: AccessService;
@@ -21,18 +21,18 @@ export class AccessController extends CrudController<AccessService> {
return this.service;
}
@Post('/page', { description: Constants.per.authOnly, summary: "查询授权配置分页列表" })
@Post("/page", { description: Constants.per.authOnly, summary: "查询授权配置分页列表" })
async page(@Body(ALL) body) {
const { projectId, userId } = await this.getProjectUserIdRead()
const { projectId, userId } = await this.getProjectUserIdRead();
body.query = body.query ?? {};
delete body.query.userId;
body.query.userId = userId;
body.query.projectId = projectId;
let name = body.query?.name;
const name = body.query?.name;
delete body.query.name;
const buildQuery = qb => {
if (name) {
qb.andWhere('name like :name', { name: `%${name.trim()}%` });
qb.andWhere("name like :name", { name: `%${name.trim()}%` });
}
};
const res = await this.service.page({
@@ -44,60 +44,60 @@ export class AccessController extends CrudController<AccessService> {
return this.ok(res);
}
@Post('/list', { description: Constants.per.authOnly, summary: "查询授权配置列表" })
@Post("/list", { description: Constants.per.authOnly, summary: "查询授权配置列表" })
async list(@Body(ALL) body) {
const { projectId, userId } = await this.getProjectUserIdRead()
const { projectId, userId } = await this.getProjectUserIdRead();
body.query = body.query ?? {};
body.query.userId = userId;
body.query.projectId = projectId;
return super.list(body);
}
@Post('/add', { description: Constants.per.authOnly, summary: "添加授权配置" })
@Post("/add", { description: Constants.per.authOnly, summary: "添加授权配置" })
async add(@Body(ALL) bean) {
const { projectId, userId } = await this.getProjectUserIdWrite()
const { projectId, userId } = await this.getProjectUserIdWrite();
bean.userId = userId;
bean.projectId = projectId;
return super.add(bean);
}
@Post('/update', { description: Constants.per.authOnly, summary: "更新授权配置" })
@Post("/update", { description: Constants.per.authOnly, summary: "更新授权配置" })
async update(@Body(ALL) bean) {
await this.checkOwner(this.getService(), bean.id, "write");
delete bean.userId;
delete bean.projectId;
return super.update(bean);
}
@Post('/info', { description: Constants.per.authOnly, summary: "查询授权配置详情" })
async info(@Query('id') id: number) {
@Post("/info", { description: Constants.per.authOnly, summary: "查询授权配置详情" })
async info(@Query("id") id: number) {
await this.checkOwner(this.getService(), id, "read");
return super.info(id);
}
@Post('/delete', { description: Constants.per.authOnly, summary: "删除授权配置" })
async delete(@Query('id') id: number) {
@Post("/delete", { description: Constants.per.authOnly, summary: "删除授权配置" })
async delete(@Query("id") id: number) {
await this.checkOwner(this.getService(), id, "write");
return super.delete(id);
}
@Post('/define', { description: Constants.per.authOnly, summary: "查询授权插件定义" })
async define(@Query('type') type: string) {
@Post("/define", { description: Constants.per.authOnly, summary: "查询授权插件定义" })
async define(@Query("type") type: string) {
const access = this.service.getDefineByType(type);
return this.ok(access);
}
@Post('/getSecretPlain', { description: Constants.per.authOnly, summary: "获取授权配置明文密钥" })
@Post("/getSecretPlain", { description: Constants.per.authOnly, summary: "获取授权配置明文密钥" })
async getSecretPlain(@Body(ALL) body: { id: number; key: string }) {
const {userId, projectId} = await this.checkOwner(this.getService(), body.id, "read");
const value = await this.service.getById(body.id, userId, projectId);
const { userId, projectId } = await this.checkOwner(this.getService(), body.id, "read");
const value = await this.service.getById(body.id, userId, projectId);
return this.ok(value[body.key]);
}
@Post('/accessTypeDict', { description: Constants.per.authOnly, summary: "查询授权类型字典" })
@Post("/accessTypeDict", { description: Constants.per.authOnly, summary: "查询授权类型字典" })
async getAccessTypeDict() {
let list: AccessDefine[] = this.service.getDefineList();
list = list.sort((a,b) => {
return (a.order??10) - (b.order??10);
list = list.sort((a, b) => {
return (a.order ?? 10) - (b.order ?? 10);
});
const dict = [];
for (const item of list) {
@@ -110,17 +110,17 @@ export class AccessController extends CrudController<AccessService> {
return this.ok(dict);
}
@Post('/simpleInfo', { description: Constants.per.authOnly, summary: "查询授权配置简单信息" })
async simpleInfo(@Query('id') id: number) {
@Post("/simpleInfo", { description: Constants.per.authOnly, summary: "查询授权配置简单信息" })
async simpleInfo(@Query("id") id: number) {
// await this.authService.checkUserIdButAllowAdmin(this.ctx, this.service, id);
// await this.checkOwner(this.getService(), id, "read",true);
const res = await this.service.getSimpleInfo(id);
return this.ok(res);
}
@Post('/getDictByIds', { description: Constants.per.authOnly, summary: "根据ID列表获取授权配置字典" })
async getDictByIds(@Body('ids') ids: number[]) {
const { userId, projectId } = await this.getProjectUserIdRead()
@Post("/getDictByIds", { description: Constants.per.authOnly, summary: "根据ID列表获取授权配置字典" })
async getDictByIds(@Body("ids") ids: number[]) {
const { userId, projectId } = await this.getProjectUserIdRead();
const res = await this.service.getSimpleByIds(ids, userId, projectId);
return this.ok(res);
}
@@ -1,64 +1,60 @@
import { Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { PipelineService } from '../../../modules/pipeline/service/pipeline-service.js';
import { BaseController, Constants, PermissionException } from '@certd/lib-server';
import { StorageService } from '../../../modules/pipeline/service/storage-service.js';
import { Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
import { PipelineService } from "../../../modules/pipeline/service/pipeline-service.js";
import { BaseController, Constants, PermissionException } from "@certd/lib-server";
import { StorageService } from "../../../modules/pipeline/service/storage-service.js";
import { CertReader } from "@certd/plugin-cert";
import { UserSettingsService } from '../../../modules/mine/service/user-settings-service.js';
import { UserGrantSetting } from '../../../modules/mine/service/models.js';
import { ApiTags } from '@midwayjs/swagger';
import { UserSettingsService } from "../../../modules/mine/service/user-settings-service.js";
import { UserGrantSetting } from "../../../modules/mine/service/models.js";
import { ApiTags } from "@midwayjs/swagger";
@Provide()
@Controller('/api/pi/cert')
@ApiTags(['pipeline-cert'])
@Controller("/api/pi/cert")
@ApiTags(["pipeline-cert"])
export class CertController extends BaseController {
@Inject()
pipelineService: PipelineService;
@Inject()
storeService: StorageService;
@Inject()
userSettingsService: UserSettingsService;
@Post('/get', { description: Constants.per.authOnly, summary: "获取证书" })
async getCert(@Query('id') id: number) {
const {userId} = await this.getProjectUserIdRead()
@Post("/get", { description: Constants.per.authOnly, summary: "获取证书" })
async getCert(@Query("id") id: number) {
const { userId } = await this.getProjectUserIdRead();
const pipleinUserId = await this.pipelineService.getPipelineUserId(id);
if (pipleinUserId !== userId) {
// 如果是管理员,检查用户是否有授权管理员查看
const isAdmin = await this.isAdmin()
const isAdmin = await this.isAdmin();
if (!isAdmin) {
throw new PermissionException();
}
// 是否允许管理员查看
const setting = await this.userSettingsService.getSetting<UserGrantSetting>(pipleinUserId,null, UserGrantSetting, false);
const setting = await this.userSettingsService.getSetting<UserGrantSetting>(pipleinUserId, null, UserGrantSetting, false);
if (setting?.allowAdminViewCerts !== true) {
//不允许管理员查看
throw new PermissionException("该流水线的用户还未授权管理员查看证书,请先让用户在”设置->授权委托“中打开开关");
}
}
const privateVars = await this.storeService.getPipelinePrivateVars(id);
const certInfo = privateVars.cert;
if (certInfo?.crt) {
const certReader = new CertReader(certInfo);
certInfo.detail = certReader.detail
certInfo.detail = certReader.detail;
}
return this.ok(certInfo);
}
@Post('/readCertDetail', { description: Constants.per.authOnly, summary: "读取证书详情" })
async readCertDetail(@Body('crt') crt: string) {
@Post("/readCertDetail", { description: Constants.per.authOnly, summary: "读取证书详情" })
async readCertDetail(@Body("crt") crt: string) {
if (!crt) {
throw new Error('crt is required');
throw new Error("crt is required");
}
const certDetail = CertReader.readCertDetail(crt)
const certDetail = CertReader.readCertDetail(crt);
return this.ok(certDetail);
}
}
@@ -1,26 +1,26 @@
import { ALL, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { DnsProviderService } from '../../../modules/pipeline/service/dns-provider-service.js';
import { BaseController } from '@certd/lib-server';
import { Constants } from '@certd/lib-server';
import { ApiTags } from '@midwayjs/swagger';
import { ALL, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
import { DnsProviderService } from "../../../modules/pipeline/service/dns-provider-service.js";
import { BaseController } from "@certd/lib-server";
import { Constants } from "@certd/lib-server";
import { ApiTags } from "@midwayjs/swagger";
/**
* 插件
*/
@Provide()
@Controller('/api/pi/dnsProvider')
@ApiTags(['pipeline-dns-provider'])
@Controller("/api/pi/dnsProvider")
@ApiTags(["pipeline-dns-provider"])
export class DnsProviderController extends BaseController {
@Inject()
service: DnsProviderService;
@Post('/list', { description: Constants.per.authOnly, summary: "查询DNS提供商列表" })
@Post("/list", { description: Constants.per.authOnly, summary: "查询DNS提供商列表" })
async list(@Query(ALL) query: any) {
const list = this.service.getList();
return this.ok(list);
}
@Post('/dnsProviderTypeDict', { description: Constants.per.authOnly, summary: "查询DNS提供商类型字典" })
@Post("/dnsProviderTypeDict", { description: Constants.per.authOnly, summary: "查询DNS提供商类型字典" })
async getDnsProviderTypeDict() {
const list = this.service.getList();
const dict = [];
@@ -1,27 +1,17 @@
import {ALL, Body, Controller, Inject, Post, Provide} from '@midwayjs/core';
import {AccessGetter, AccessService, BaseController, Constants} from '@certd/lib-server';
import {
AccessRequestHandleReq,
IAccessService,
ITaskPlugin,
newAccess,
newNotification,
NotificationRequestHandleReq,
pluginRegistry,
PluginRequestHandleReq,
TaskInstanceContext,
} from '@certd/pipeline';
import {EmailService} from '../../../modules/basic/service/email-service.js';
import {http, HttpRequestConfig, logger, mergeUtils, utils} from '@certd/basic';
import {NotificationService} from '../../../modules/pipeline/service/notification-service.js';
import {TaskServiceBuilder} from "../../../modules/pipeline/service/getter/task-service-getter.js";
import { cloneDeep } from 'lodash-es';
import { ApiTags } from '@midwayjs/swagger';
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
import { ALL, Body, Controller, Inject, Post, Provide } from "@midwayjs/core";
import { AccessGetter, AccessService, BaseController, Constants } from "@certd/lib-server";
import { AccessRequestHandleReq, IAccessService, ITaskPlugin, newAccess, newNotification, NotificationRequestHandleReq, pluginRegistry, PluginRequestHandleReq, TaskInstanceContext } from "@certd/pipeline";
import { EmailService } from "../../../modules/basic/service/email-service.js";
import { http, HttpRequestConfig, logger, mergeUtils, utils } from "@certd/basic";
import { NotificationService } from "../../../modules/pipeline/service/notification-service.js";
import { TaskServiceBuilder } from "../../../modules/pipeline/service/getter/task-service-getter.js";
import { cloneDeep } from "lodash-es";
import { ApiTags } from "@midwayjs/swagger";
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
@Provide()
@Controller('/api/pi/handle')
@ApiTags(['pipeline-handle'])
@Controller("/api/pi/handle")
@ApiTags(["pipeline-handle"])
export class HandleController extends BaseController {
@Inject()
accessService: AccessService;
@@ -38,28 +28,28 @@ export class HandleController extends BaseController {
@Inject()
notificationService: NotificationService;
@Post('/access', { description: Constants.per.authOnly, summary: "处理授权请求" })
@Post("/access", { description: Constants.per.authOnly, summary: "处理授权请求" })
async accessRequest(@Body(ALL) body: AccessRequestHandleReq) {
let {projectId,userId} = await this.getProjectUserIdRead()
if (body.fromType === 'sys') {
let { projectId, userId } = await this.getProjectUserIdRead();
if (body.fromType === "sys") {
//系统级别的请求
const pass = await this.authService.checkPermission(this.ctx, "sys:settings:view");
if (!pass) {
throw new Error('权限不足');
throw new Error("权限不足");
}
projectId = null
userId = 0
projectId = null;
userId = 0;
}
let inputAccess = body.input;
if (body.record.id > 0) {
const oldEntity = await this.accessService.info(body.record.id);
if (oldEntity) {
if (oldEntity.userId !== userId && oldEntity.userId !== this.getUserId()) {
throw new Error('您没有权限使用该授权');
throw new Error("您没有权限使用该授权");
}
if (oldEntity.projectId && oldEntity.projectId !== projectId) {
throw new Error('您没有权限使用该授权(projectId不匹配)');
throw new Error("您没有权限使用该授权(projectId不匹配)");
}
const param: any = {
type: body.typeName,
@@ -69,8 +59,8 @@ export class HandleController extends BaseController {
inputAccess = this.accessService.decryptAccessEntity(param);
}
}
const accessGetter = new AccessGetter(userId,projectId, this.accessService.getById.bind(this.accessService));
const access = await newAccess(body.typeName, inputAccess,accessGetter);
const accessGetter = new AccessGetter(userId, projectId, this.accessService.getById.bind(this.accessService));
const access = await newAccess(body.typeName, inputAccess, accessGetter);
// mergeUtils.merge(access, body.input);
const res = await access.onRequest(body);
@@ -78,7 +68,7 @@ export class HandleController extends BaseController {
return this.ok(res);
}
@Post('/notification', { description: Constants.per.authOnly, summary: "处理通知请求" })
@Post("/notification", { description: Constants.per.authOnly, summary: "处理通知请求" })
async notificationRequest(@Body(ALL) body: NotificationRequestHandleReq) {
const input = body.input;
@@ -94,9 +84,9 @@ export class HandleController extends BaseController {
return this.ok(res);
}
@Post('/plugin', { description: Constants.per.authOnly, summary: "处理插件请求" })
@Post("/plugin", { description: Constants.per.authOnly, summary: "处理插件请求" })
async pluginRequest(@Body(ALL) body: PluginRequestHandleReq) {
const {projectId,userId} = await this.getProjectUserIdRead()
const { projectId, userId } = await this.getProjectUserIdRead();
const pluginDefine = pluginRegistry.get(body.typeName);
const pluginCls = await pluginDefine.target();
if (pluginCls == null) {
@@ -117,14 +107,14 @@ export class HandleController extends BaseController {
});
};
const taskServiceGetter = this.taskServiceBuilder.create({userId,projectId})
const taskServiceGetter = this.taskServiceBuilder.create({ userId, projectId });
const accessGetter = await taskServiceGetter.get<IAccessService>("accessService")
const accessGetter = await taskServiceGetter.get<IAccessService>("accessService");
//@ts-ignore
const taskCtx: TaskInstanceContext = {
pipeline: undefined,
step: undefined,
define: cloneDeep( pluginDefine.define),
define: cloneDeep(pluginDefine.define),
lastStatus: undefined,
http,
download,
@@ -136,7 +126,7 @@ export class HandleController extends BaseController {
userContext: undefined,
fileStore: undefined,
signal: undefined,
user: {id:userId,role:"user"},
user: { id: userId, role: "user" },
projectId,
// pipelineContext: this.pipelineContext,
// userContext: this.contextFactory.getContext('user', this.options.userId),
@@ -147,7 +137,7 @@ export class HandleController extends BaseController {
// }),
// signal: this.abort.signal,
utils,
serviceGetter:taskServiceGetter
serviceGetter: taskServiceGetter,
};
instance.setCtx(taskCtx);
mergeUtils.merge(plugin, body.input);
@@ -18,8 +18,8 @@ import { ApiTags } from "@midwayjs/swagger";
* 证书
*/
@Provide()
@Controller('/api/pi/history')
@ApiTags(['pipeline-history'])
@Controller("/api/pi/history")
@ApiTags(["pipeline-history"])
export class HistoryController extends CrudController<HistoryService> {
@Inject()
service: HistoryService;
@@ -41,10 +41,10 @@ export class HistoryController extends CrudController<HistoryService> {
return this.service;
}
@Post('/page', { description: Constants.per.authOnly, summary: "查询流水线执行历史分页列表" })
@Post("/page", { description: Constants.per.authOnly, summary: "查询流水线执行历史分页列表" })
async page(@Body(ALL) body: any) {
const { projectId, userId } = await this.getProjectUserIdRead()
body.query.projectId = projectId
const { projectId, userId } = await this.getProjectUserIdRead();
body.query.projectId = projectId;
const isAdmin = await this.authService.isAdmin(this.ctx);
const publicSettings = await this.sysSettingsService.getPublicSettings();
@@ -64,7 +64,7 @@ export class HistoryController extends CrudController<HistoryService> {
const pipelines = await this.pipelineService.list({
query: pipelineQuery,
buildQuery: qb => {
qb.andWhere('title like :title', { title: `%${pipelineTitle}%` });
qb.andWhere("title like :title", { title: `%${pipelineTitle}%` });
},
});
pipelineIds = pipelines.map(p => p.id);
@@ -88,14 +88,14 @@ export class HistoryController extends CrudController<HistoryService> {
return this.ok(res);
}
@Post('/list', { description: Constants.per.authOnly, summary: "查询流水线执行历史列表" })
@Post("/list", { description: Constants.per.authOnly, summary: "查询流水线执行历史列表" })
async list(@Body(ALL) body) {
const { projectId, userId } = await this.getProjectUserIdRead()
if (!body){
body = {}
const { projectId, userId } = await this.getProjectUserIdRead();
if (!body) {
body = {};
}
if (projectId){
body.projectId = projectId
if (projectId) {
body.projectId = projectId;
}
const isAdmin = this.authService.isAdmin(this.ctx);
@@ -111,7 +111,7 @@ export class HistoryController extends CrudController<HistoryService> {
};
const withDetail = body.withDetail;
delete body.withDetail;
let select: any = null
let select: any = null;
if (!withDetail) {
select = {
pipeline: true, // 后面这里改成false
@@ -129,9 +129,9 @@ export class HistoryController extends CrudController<HistoryService> {
}
const listRet = await this.getService().list({
query: body,
sort: { prop: 'id', asc: false },
sort: { prop: "id", asc: false },
buildQuery,
select
select,
});
for (const item of listRet) {
@@ -144,92 +144,92 @@ export class HistoryController extends CrudController<HistoryService> {
//@ts-ignore
item.version = json.version;
item.status = json.status.result
item.status = json.status.result;
delete item.pipeline;
}
return this.ok(listRet);
}
@Post('/add', { description: Constants.per.authOnly, summary: "添加流水线执行历史" })
@Post("/add", { description: Constants.per.authOnly, summary: "添加流水线执行历史" })
async add(@Body(ALL) bean: PipelineEntity) {
const { projectId, userId } = await this.getProjectUserIdRead()
bean.projectId = projectId
const { projectId, userId } = await this.getProjectUserIdRead();
bean.projectId = projectId;
bean.userId = userId;
return super.add(bean);
}
@Post('/update', { description: Constants.per.authOnly, summary: "更新流水线执行历史" })
@Post("/update", { description: Constants.per.authOnly, summary: "更新流水线执行历史" })
async update(@Body(ALL) bean) {
await this.checkOwner(this.getService(), bean.id,"write",true);
await this.checkOwner(this.getService(), bean.id, "write", true);
delete bean.userId;
delete bean.projectId;
return super.update(bean);
}
@Post('/save', { description: Constants.per.authOnly, summary: "保存流水线执行历史" })
@Post("/save", { description: Constants.per.authOnly, summary: "保存流水线执行历史" })
async save(@Body(ALL) bean: HistoryEntity) {
const { projectId,userId } = await this.getProjectUserIdWrite()
const { projectId, userId } = await this.getProjectUserIdWrite();
bean.userId = userId;
bean.projectId = projectId;
if (bean.id > 0) {
//修改
delete bean.projectId;
delete bean.userId;
await this.checkOwner(this.getService(), bean.id,"write",true);
await this.checkOwner(this.getService(), bean.id, "write", true);
}
await this.service.save(bean);
return this.ok(bean.id);
}
@Post('/saveLog', { description: Constants.per.authOnly, summary: "保存流水线执行日志" })
@Post("/saveLog", { description: Constants.per.authOnly, summary: "保存流水线执行日志" })
async saveLog(@Body(ALL) bean: HistoryLogEntity) {
const { projectId,userId } = await this.getProjectUserIdWrite()
const { projectId, userId } = await this.getProjectUserIdWrite();
bean.projectId = projectId;
bean.userId = userId;
if (bean.id > 0) {
//修改
delete bean.projectId;
delete bean.userId;
await this.checkOwner(this.logService, bean.id,"write",true);
await this.checkOwner(this.logService, bean.id, "write", true);
}
await this.logService.save(bean);
return this.ok(bean.id);
}
@Post('/delete', { description: Constants.per.authOnly, summary: "删除流水线执行历史" })
async delete(@Query('id') id: number) {
await this.checkOwner(this.getService(), id,"write",true);
@Post("/delete", { description: Constants.per.authOnly, summary: "删除流水线执行历史" })
async delete(@Query("id") id: number) {
await this.checkOwner(this.getService(), id, "write", true);
await super.delete(id);
return this.ok();
}
@Post('/deleteByIds', { description: Constants.per.authOnly, summary: "批量删除流水线执行历史" })
@Post("/deleteByIds", { description: Constants.per.authOnly, summary: "批量删除流水线执行历史" })
async deleteByIds(@Body(ALL) body: any) {
let {userId} = await this.checkOwner(this.getService(), body.ids,"write",true);
let { userId } = await this.checkOwner(this.getService(), body.ids, "write", true);
const isAdmin = await this.authService.isAdmin(this.ctx);
userId = isAdmin ? null : userId;
await this.getService().deleteByIds(body.ids, userId);
return this.ok();
}
@Post('/detail', { description: Constants.per.authOnly, summary: "查询流水线执行历史详情" })
async detail(@Query('id') id: number) {
await this.checkOwner(this.getService(), id,"read",true);
@Post("/detail", { description: Constants.per.authOnly, summary: "查询流水线执行历史详情" })
async detail(@Query("id") id: number) {
await this.checkOwner(this.getService(), id, "read", true);
const detail = await this.service.detail(id);
return this.ok(detail);
}
@Post('/logs', { description: Constants.per.authOnly, summary: "查询流水线执行日志" })
async logs(@Query('id') id: number) {
await this.checkOwner(this.logService, id,"read",true);
@Post("/logs", { description: Constants.per.authOnly, summary: "查询流水线执行日志" })
async logs(@Query("id") id: number) {
await this.checkOwner(this.logService, id, "read", true);
const logInfo = await this.logService.info(id);
return this.ok(logInfo);
}
@Post('/files', { description: Constants.per.authOnly, summary: "查询流水线执行文件" })
async files(@Query('pipelineId') pipelineId: number, @Query('historyId') historyId: number) {
@Post("/files", { description: Constants.per.authOnly, summary: "查询流水线执行文件" })
async files(@Query("pipelineId") pipelineId: number, @Query("historyId") historyId: number) {
const files = await this.getFiles(historyId, pipelineId);
return this.ok(files);
}
@@ -243,24 +243,24 @@ export class HistoryController extends CrudController<HistoryService> {
history = await this.service.getLastHistory(pipelineId);
}
if (history == null) {
throw new CommonException('流水线还未运行过');
throw new CommonException("流水线还未运行过");
}
const {projectId} = await this.getProjectUserIdRead()
const { projectId } = await this.getProjectUserIdRead();
if (projectId) {
//enterprise模式
if(history.projectId !== projectId){
throw new PermissionException("您没有权限下载该流水线证书,请先加入该项目:"+history.projectId);
if (history.projectId !== projectId) {
throw new PermissionException("您没有权限下载该流水线证书,请先加入该项目:" + history.projectId);
}
//有权限下载
}else if (history.userId !== this.getUserId()) {
} else if (history.userId !== this.getUserId()) {
// 如果是管理员,检查用户是否有授权管理员查看
const isAdmin = await this.isAdmin()
const isAdmin = await this.isAdmin();
if (!isAdmin) {
throw new PermissionException();
}
// 是否允许管理员查看
const setting = await this.userSettingsService.getSetting<UserGrantSetting>(history.userId, null, UserGrantSetting, false);
if (setting?.allowAdminViewCerts!==true) {
if (setting?.allowAdminViewCerts !== true) {
//不允许管理员查看
throw new PermissionException("该流水线的用户还未授权管理员下载证书,请先让用户在”设置->授权委托“中打开开关");
}
@@ -269,12 +269,12 @@ export class HistoryController extends CrudController<HistoryService> {
return await this.service.getFiles(history);
}
@Get('/download', { description: Constants.per.authOnly, summary: "下载流水线执行文件" })
async download(@Query('pipelineId') pipelineId: number, @Query('historyId') historyId: number, @Query('fileId') fileId: string) {
@Get("/download", { description: Constants.per.authOnly, summary: "下载流水线执行文件" })
async download(@Query("pipelineId") pipelineId: number, @Query("historyId") historyId: number, @Query("fileId") fileId: string) {
const files = await this.getFiles(historyId, pipelineId);
const file = files.find(f => f.id === fileId);
if (file == null) {
throw new CommonException('file not found');
throw new CommonException("file not found");
}
// koa send file
// 下载文件的名称
@@ -284,7 +284,7 @@ export class HistoryController extends CrudController<HistoryService> {
logger.info(`download:${path}`);
// 以流的形式下载文件
this.ctx.attachment(path);
this.ctx.set('Content-Type', 'application/octet-stream');
this.ctx.set("Content-Type", "application/octet-stream");
return fs.createReadStream(path);
}
@@ -1,17 +1,17 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { Constants, CrudController, ValidateException } from '@certd/lib-server';
import { NotificationService } from '../../../modules/pipeline/service/notification-service.js';
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
import { NotificationDefine } from '@certd/pipeline';
import { checkPlus } from '@certd/plus-core';
import { ApiTags } from '@midwayjs/swagger';
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
import { Constants, CrudController, ValidateException } from "@certd/lib-server";
import { NotificationService } from "../../../modules/pipeline/service/notification-service.js";
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
import { NotificationDefine } from "@certd/pipeline";
import { checkPlus } from "@certd/plus-core";
import { ApiTags } from "@midwayjs/swagger";
/**
* 通知
*/
@Provide()
@Controller('/api/pi/notification')
@ApiTags(['pipeline-notification'])
@Controller("/api/pi/notification")
@ApiTags(["pipeline-notification"])
export class NotificationController extends CrudController<NotificationService> {
@Inject()
service: NotificationService;
@@ -22,14 +22,14 @@ export class NotificationController extends CrudController<NotificationService>
return this.service;
}
@Post('/page', { description: Constants.per.authOnly, summary: "查询通知配置分页列表" })
@Post("/page", { description: Constants.per.authOnly, summary: "查询通知配置分页列表" })
async page(@Body(ALL) body) {
const {projectId,userId} = await this.getProjectUserIdRead();
const { projectId, userId } = await this.getProjectUserIdRead();
body.query = body.query ?? {};
delete body.query.userId;
body.query.projectId = projectId;
const buildQuery = qb => {
qb.andWhere('user_id = :userId', { userId: userId});
qb.andWhere("user_id = :userId", { userId: userId });
};
const res = await this.service.page({
query: body.query,
@@ -40,24 +40,24 @@ export class NotificationController extends CrudController<NotificationService>
return this.ok(res);
}
@Post('/list', { description: Constants.per.authOnly, summary: "查询通知配置列表" })
@Post("/list", { description: Constants.per.authOnly, summary: "查询通知配置列表" })
async list(@Body(ALL) body) {
const {projectId,userId} = await this.getProjectUserIdRead();
const { projectId, userId } = await this.getProjectUserIdRead();
body.query = body.query ?? {};
body.query.userId = userId;
body.query.projectId = projectId;
return super.list(body);
}
@Post('/add', { description: Constants.per.authOnly, summary: "添加通知配置" })
@Post("/add", { description: Constants.per.authOnly, summary: "添加通知配置" })
async add(@Body(ALL) bean) {
const {projectId,userId} = await this.getProjectUserIdRead();
const { projectId, userId } = await this.getProjectUserIdRead();
bean.userId = userId;
bean.projectId = projectId;
const type = bean.type;
const define: NotificationDefine = this.service.getDefineByType(type);
if (!define) {
throw new ValidateException('通知类型不存在');
throw new ValidateException("通知类型不存在");
}
if (define.needPlus) {
checkPlus();
@@ -65,18 +65,18 @@ export class NotificationController extends CrudController<NotificationService>
return super.add(bean);
}
@Post('/update', { description: Constants.per.authOnly, summary: "更新通知配置" })
@Post("/update", { description: Constants.per.authOnly, summary: "更新通知配置" })
async update(@Body(ALL) bean) {
await this.checkOwner(this.getService(), bean.id,"write");
await this.checkOwner(this.getService(), bean.id, "write");
const old = await this.service.info(bean.id);
if (!old) {
throw new ValidateException('通知配置不存在');
throw new ValidateException("通知配置不存在");
}
if (old.type !== bean.type) {
const type = bean.type;
const define: NotificationDefine = this.service.getDefineByType(type);
if (!define) {
throw new ValidateException('通知类型不存在');
throw new ValidateException("通知类型不存在");
}
if (define.needPlus) {
checkPlus();
@@ -86,25 +86,25 @@ export class NotificationController extends CrudController<NotificationService>
delete bean.projectId;
return super.update(bean);
}
@Post('/info', { description: Constants.per.authOnly, summary: "查询通知配置详情" })
async info(@Query('id') id: number) {
await this.checkOwner(this.getService(), id,"read");
@Post("/info", { description: Constants.per.authOnly, summary: "查询通知配置详情" })
async info(@Query("id") id: number) {
await this.checkOwner(this.getService(), id, "read");
return super.info(id);
}
@Post('/delete', { description: Constants.per.authOnly, summary: "删除通知配置" })
async delete(@Query('id') id: number) {
await this.checkOwner(this.getService(), id,"write");
@Post("/delete", { description: Constants.per.authOnly, summary: "删除通知配置" })
async delete(@Query("id") id: number) {
await this.checkOwner(this.getService(), id, "write");
return super.delete(id);
}
@Post('/define', { description: Constants.per.authOnly, summary: "查询通知插件定义" })
async define(@Query('type') type: string) {
@Post("/define", { description: Constants.per.authOnly, summary: "查询通知插件定义" })
async define(@Query("type") type: string) {
const notification = this.service.getDefineByType(type);
return this.ok(notification);
}
@Post('/getTypeDict', { description: Constants.per.authOnly, summary: "查询通知类型字典" })
@Post("/getTypeDict", { description: Constants.per.authOnly, summary: "查询通知类型字典" })
async getTypeDict() {
const list: any = this.service.getDefineList();
let dict = [];
@@ -125,48 +125,48 @@ export class NotificationController extends CrudController<NotificationService>
return this.ok(dict);
}
@Post('/simpleInfo', { description: Constants.per.authOnly, summary: "查询通知配置简单信息" })
async simpleInfo(@Query('id') id: number) {
const {projectId,userId} = await this.getProjectUserIdRead();
@Post("/simpleInfo", { description: Constants.per.authOnly, summary: "查询通知配置简单信息" })
async simpleInfo(@Query("id") id: number) {
const { projectId, userId } = await this.getProjectUserIdRead();
if (id === 0) {
//获取默认
const res = await this.service.getDefault(userId,projectId);
const res = await this.service.getDefault(userId, projectId);
if (!res) {
throw new ValidateException('默认通知配置不存在');
throw new ValidateException("默认通知配置不存在");
}
const simple = await this.service.getSimpleInfo(res.id);
return this.ok(simple);
}
await this.checkOwner(this.getService(), id,"read",true);
await this.checkOwner(this.getService(), id, "read", true);
const res = await this.service.getSimpleInfo(id);
return this.ok(res);
}
@Post('/getDefaultId', { description: Constants.per.authOnly, summary: "查询默认通知配置ID" })
@Post("/getDefaultId", { description: Constants.per.authOnly, summary: "查询默认通知配置ID" })
async getDefaultId() {
const {projectId,userId} = await this.getProjectUserIdRead();
const res = await this.service.getDefault(userId,projectId);
const { projectId, userId } = await this.getProjectUserIdRead();
const res = await this.service.getDefault(userId, projectId);
return this.ok(res?.id);
}
@Post('/setDefault', { description: Constants.per.authOnly, summary: "设置默认通知配置" })
async setDefault(@Query('id') id: number) {
const {projectId,userId} = await this.getProjectUserIdRead();
await this.checkOwner(this.getService(), id,"write");
const res = await this.service.setDefault(id, userId,projectId);
@Post("/setDefault", { description: Constants.per.authOnly, summary: "设置默认通知配置" })
async setDefault(@Query("id") id: number) {
const { projectId, userId } = await this.getProjectUserIdRead();
await this.checkOwner(this.getService(), id, "write");
const res = await this.service.setDefault(id, userId, projectId);
return this.ok(res);
}
@Post('/getOrCreateDefault', { description: Constants.per.authOnly, summary: "获取或创建默认通知配置" })
async getOrCreateDefault(@Body('email') email: string) {
const {projectId,userId} = await this.getProjectUserIdRead();
const res = await this.service.getOrCreateDefault(email, userId,projectId);
@Post("/getOrCreateDefault", { description: Constants.per.authOnly, summary: "获取或创建默认通知配置" })
async getOrCreateDefault(@Body("email") email: string) {
const { projectId, userId } = await this.getProjectUserIdRead();
const res = await this.service.getOrCreateDefault(email, userId, projectId);
return this.ok(res);
}
@Post('/options', { description: Constants.per.authOnly, summary: "查询通知配置选项" })
@Post("/options", { description: Constants.per.authOnly, summary: "查询通知配置选项" })
async options() {
const {projectId,userId} = await this.getProjectUserIdRead();
const { projectId, userId } = await this.getProjectUserIdRead();
const res = await this.service.list({
query: {
userId: userId,
@@ -1,13 +1,12 @@
import { Constants, CrudController, SysSettingsService } from '@certd/lib-server';
import { isPlus } from '@certd/plus-core';
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { ApiProperty, ApiTags } from '@midwayjs/swagger';
import { SiteInfoService } from '../../../modules/monitor/index.js';
import { HistoryService } from '../../../modules/pipeline/service/history-service.js';
import { PipelineService } from '../../../modules/pipeline/service/pipeline-service.js';
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
import { PipelineEntity } from '../../../modules/pipeline/entity/pipeline.js';
import { Constants, CrudController, SysSettingsService } from "@certd/lib-server";
import { isPlus } from "@certd/plus-core";
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
import { ApiProperty, ApiTags } from "@midwayjs/swagger";
import { SiteInfoService } from "../../../modules/monitor/index.js";
import { HistoryService } from "../../../modules/pipeline/service/history-service.js";
import { PipelineService } from "../../../modules/pipeline/service/pipeline-service.js";
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
import { PipelineEntity } from "../../../modules/pipeline/entity/pipeline.js";
const pipelineExample = `
// 流水线配置示例,实际传送时要去掉注释
@@ -67,50 +66,50 @@ const pipelineExample = `
"notificationId": 0, // 通知ID 0为使用默认通知
}
],
}`
}`;
export class PipelineSaveDTO {
@ApiProperty({ description: 'Id,修改时必传' })
id: number;
userId: number;
@ApiProperty({ description: '标题' })
title: string;
@ApiProperty({ description: '流水线详细配置,json格式的字符串', example: pipelineExample })
content: string;
@ApiProperty({ description: "Id,修改时必传" })
id: number;
userId: number;
@ApiProperty({ description: "标题" })
title: string;
@ApiProperty({ description: "流水线详细配置,json格式的字符串", example: pipelineExample })
content: string;
@ApiProperty({ description: '保留历史版本数量' })
keepHistoryCount: number;
@ApiProperty({ description: '分组ID' })
groupId: number;
@ApiProperty({ description: '备注' })
remark: string;
@ApiProperty({ description: '状态' })
status: string;
@ApiProperty({ description: '是否禁用' })
disabled: boolean;
@ApiProperty({ description: '类型' })
type: string;
webhookKey: string;
@ApiProperty({ description: '来源' })
from: string;
@ApiProperty({ description: '排序' })
order: number;
@ApiProperty({ description: '项目ID' })
projectId: number;
@ApiProperty({ description: '流水线有效期,单位秒' })
validTime: number;
@ApiProperty({ description: '是否增加证书监控' })
addToMonitorEnabled: boolean
@ApiProperty({ description: '增加证书监控的域名,逗号分隔' })
addToMonitorDomains: string
@ApiProperty({ description: "保留历史版本数量" })
keepHistoryCount: number;
@ApiProperty({ description: "分组ID" })
groupId: number;
@ApiProperty({ description: "备注" })
remark: string;
@ApiProperty({ description: "状态" })
status: string;
@ApiProperty({ description: "是否禁用" })
disabled: boolean;
@ApiProperty({ description: "类型" })
type: string;
webhookKey: string;
@ApiProperty({ description: "来源" })
from: string;
@ApiProperty({ description: "排序" })
order: number;
@ApiProperty({ description: "项目ID" })
projectId: number;
@ApiProperty({ description: "流水线有效期,单位秒" })
validTime: number;
@ApiProperty({ description: "是否增加证书监控" })
addToMonitorEnabled: boolean;
@ApiProperty({ description: "增加证书监控的域名,逗号分隔" })
addToMonitorDomains: string;
}
/**
* 证书
*/
@Provide()
@ApiTags(['pipeline'])
@Controller('/api/pi/pipeline')
@ApiTags(["pipeline"])
@Controller("/api/pi/pipeline")
export class PipelineController extends CrudController<PipelineService> {
@Inject()
service: PipelineService;
@@ -124,19 +123,18 @@ export class PipelineController extends CrudController<PipelineService> {
@Inject()
siteInfoService: SiteInfoService;
getService() {
return this.service;
}
@Post('/page', { description: Constants.per.authOnly, summary: "查询流水线分页列表" })
@Post("/page", { description: Constants.per.authOnly, summary: "查询流水线分页列表" })
async page(@Body(ALL) body) {
const isAdmin = await this.authService.isAdmin(this.ctx);
const publicSettings = await this.sysSettingsService.getPublicSettings();
const { projectId, userId } = await this.getProjectUserIdRead()
body.query.projectId = projectId
let onlyOther = false
const { projectId, userId } = await this.getProjectUserIdRead();
body.query.projectId = projectId;
let onlyOther = false;
if (isAdmin) {
if (publicSettings.managerOtherUserPipeline) {
//管理员管理 其他用户
@@ -157,14 +155,14 @@ export class PipelineController extends CrudController<PipelineService> {
const buildQuery = qb => {
if (title) {
qb.andWhere('(title like :title or content like :content)', { title: `%${title}%`, content: `%${title}%` });
qb.andWhere("(title like :title or content like :content)", { title: `%${title}%`, content: `%${title}%` });
}
if (onlyOther) {
qb.andWhere('user_id != :userId', { userId: this.getUserId() });
qb.andWhere("user_id != :userId", { userId: this.getUserId() });
}
};
if (!body.sort || !body.sort?.prop) {
body.sort = { prop: 'order', asc: false };
body.sort = { prop: "order", asc: false };
}
const pageRet = await this.getService().page({
@@ -176,31 +174,30 @@ export class PipelineController extends CrudController<PipelineService> {
return this.ok(pageRet);
}
@Post('/getSimpleByIds', { description: Constants.per.authOnly, summary: "根据ID列表获取流水线简单信息" })
@Post("/getSimpleByIds", { description: Constants.per.authOnly, summary: "根据ID列表获取流水线简单信息" })
async getSimpleById(@Body(ALL) body) {
const { projectId, userId } = await this.getProjectUserIdRead()
const { projectId, userId } = await this.getProjectUserIdRead();
const ret = await this.getService().getSimplePipelines(body.ids, userId, projectId);
return this.ok(ret);
}
@Post('/add', { description: Constants.per.authOnly })
@Post("/add", { description: Constants.per.authOnly })
async add(@Body(ALL) bean: PipelineEntity) {
return await this.save(bean as any);
}
@Post('/update', { description: Constants.per.authOnly })
async update(@Body(ALL) bean:PipelineEntity) {
await this.checkOwner(this.getService(), bean.id,"write",true);
await this.service.update(bean as any);
return this.ok({});
@Post("/update", { description: Constants.per.authOnly })
async update(@Body(ALL) bean: PipelineEntity) {
await this.checkOwner(this.getService(), bean.id, "write", true);
await this.service.update(bean as any);
return this.ok({});
}
@Post('/save', { description: Constants.per.authOnly, summary: '新增/更新流水线' })
@Post("/save", { description: Constants.per.authOnly, summary: "新增/更新流水线" })
async save(@Body() bean: PipelineSaveDTO) {
const { userId ,projectId} = await this.getProjectUserIdWrite()
const { userId, projectId } = await this.getProjectUserIdWrite();
if (bean.id > 0) {
const {userId,projectId} = await this.checkOwner(this.getService(), bean.id,"write",true);
const { userId, projectId } = await this.checkOwner(this.getService(), bean.id, "write", true);
bean.userId = userId;
bean.projectId = projectId;
} else {
@@ -210,7 +207,7 @@ export class PipelineController extends CrudController<PipelineService> {
if (!this.isAdmin()) {
// 非管理员用户 不允许设置流水线有效期
delete bean.validTime
delete bean.validTime;
}
const { version } = await this.service.save(bean as any);
@@ -229,63 +226,62 @@ export class PipelineController extends CrudController<PipelineService> {
return this.ok({ id: bean.id, version: version });
}
@Post('/delete', { description: Constants.per.authOnly, summary: "删除流水线" })
async delete(@Query('id') id: number) {
await this.checkOwner(this.getService(), id,"write",true);
@Post("/delete", { description: Constants.per.authOnly, summary: "删除流水线" })
async delete(@Query("id") id: number) {
await this.checkOwner(this.getService(), id, "write", true);
await this.service.delete(id);
return this.ok({});
}
@Post('/disabled', { description: Constants.per.authOnly, summary: "禁用流水线" })
@Post("/disabled", { description: Constants.per.authOnly, summary: "禁用流水线" })
async disabled(@Body(ALL) bean) {
await this.checkOwner(this.getService(), bean.id,"write",true);
await this.checkOwner(this.getService(), bean.id, "write", true);
delete bean.userId;
delete bean.projectId;
await this.service.disabled(bean.id, bean.disabled);
return this.ok({});
}
@Post('/detail', { description: Constants.per.authOnly, summary: "查询流水线详情" })
async detail(@Query('id') id: number) {
await this.checkOwner(this.getService(), id,"read",true);
@Post("/detail", { description: Constants.per.authOnly, summary: "查询流水线详情" })
async detail(@Query("id") id: number) {
await this.checkOwner(this.getService(), id, "read", true);
const detail = await this.service.detail(id);
return this.ok(detail);
}
@Post('/trigger', { description: Constants.per.authOnly, summary: "触发流水线执行" })
async trigger(@Query('id') id: number, @Query('stepId') stepId?: string) {
await this.checkOwner(this.getService(), id,"write",true);
@Post("/trigger", { description: Constants.per.authOnly, summary: "触发流水线执行" })
async trigger(@Query("id") id: number, @Query("stepId") stepId?: string) {
await this.checkOwner(this.getService(), id, "write", true);
await this.service.trigger(id, stepId, true);
return this.ok({});
}
@Post('/cancel', { description: Constants.per.authOnly, summary: "取消流水线执行" })
async cancel(@Query('historyId') historyId: number) {
await this.checkOwner(this.historyService, historyId,"write",true);
@Post("/cancel", { description: Constants.per.authOnly, summary: "取消流水线执行" })
async cancel(@Query("historyId") historyId: number) {
await this.checkOwner(this.historyService, historyId, "write", true);
await this.service.cancel(historyId);
return this.ok({});
}
@Post('/count', { description: Constants.per.authOnly, summary: "查询流水线数量" })
@Post("/count", { description: Constants.per.authOnly, summary: "查询流水线数量" })
async count() {
const { userId } = await this.getProjectUserIdRead()
const { userId } = await this.getProjectUserIdRead();
const count = await this.service.count({ userId: userId });
return this.ok({ count });
}
private async checkPermissionCall(callback:any){
let { projectId ,userId} = await this.getProjectUserIdWrite()
if(projectId){
return await callback({userId,projectId});
private async checkPermissionCall(callback: any) {
let { projectId, userId } = await this.getProjectUserIdWrite();
if (projectId) {
return await callback({ userId, projectId });
}
const isAdmin = await this.authService.isAdmin(this.ctx);
userId = isAdmin ? undefined : userId;
return await callback({userId});
return await callback({ userId });
}
@Post('/batchDelete', { description: Constants.per.authOnly, summary: "批量删除流水线" })
async batchDelete(@Body('ids') ids: number[]) {
@Post("/batchDelete", { description: Constants.per.authOnly, summary: "批量删除流水线" })
async batchDelete(@Body("ids") ids: number[]) {
// let { projectId ,userId} = await this.getProjectUserIdWrite()
// if(projectId){
// await this.service.batchDelete(ids, null,projectId);
@@ -295,16 +291,14 @@ export class PipelineController extends CrudController<PipelineService> {
// userId = isAdmin ? undefined : userId;
// await this.service.batchDelete(ids, userId);
// return this.ok({});
await this.checkPermissionCall(async ({userId,projectId})=>{
await this.service.batchDelete(ids, userId,projectId);
})
return this.ok({})
await this.checkPermissionCall(async ({ userId, projectId }) => {
await this.service.batchDelete(ids, userId, projectId);
});
return this.ok({});
}
@Post('/batchUpdateGroup', { description: Constants.per.authOnly, summary: "批量更新流水线分组" })
async batchUpdateGroup(@Body('ids') ids: number[], @Body('groupId') groupId: number) {
@Post("/batchUpdateGroup", { description: Constants.per.authOnly, summary: "批量更新流水线分组" })
async batchUpdateGroup(@Body("ids") ids: number[], @Body("groupId") groupId: number) {
// let { projectId ,userId} = await this.getProjectUserIdWrite()
// if(projectId){
// await this.service.batchUpdateGroup(ids, groupId, null,projectId);
@@ -314,15 +308,14 @@ export class PipelineController extends CrudController<PipelineService> {
// const isAdmin = await this.authService.isAdmin(this.ctx);
// userId = isAdmin ? undefined : this.getUserId();
// await this.service.batchUpdateGroup(ids, groupId, userId);
await this.checkPermissionCall(async ({userId,projectId})=>{
await this.service.batchUpdateGroup(ids, groupId, userId,projectId);
})
await this.checkPermissionCall(async ({ userId, projectId }) => {
await this.service.batchUpdateGroup(ids, groupId, userId, projectId);
});
return this.ok({});
}
@Post('/batchUpdateTrigger', { description: Constants.per.authOnly, summary: "批量更新流水线触发器" })
async batchUpdateTrigger(@Body('ids') ids: number[], @Body('trigger') trigger: any) {
@Post("/batchUpdateTrigger", { description: Constants.per.authOnly, summary: "批量更新流水线触发器" })
async batchUpdateTrigger(@Body("ids") ids: number[], @Body("trigger") trigger: any) {
// let { projectId ,userId} = await this.getProjectUserIdWrite()
// if(projectId){
// await this.service.batchUpdateTrigger(ids, trigger, null,projectId);
@@ -332,54 +325,53 @@ export class PipelineController extends CrudController<PipelineService> {
// const isAdmin = await this.authService.isAdmin(this.ctx);
// userId = isAdmin ? undefined : this.getUserId();
// await this.service.batchUpdateTrigger(ids, trigger, userId);
await this.checkPermissionCall(async ({userId,projectId})=>{
await this.service.batchUpdateTrigger(ids, trigger, userId,projectId);
})
await this.checkPermissionCall(async ({ userId, projectId }) => {
await this.service.batchUpdateTrigger(ids, trigger, userId, projectId);
});
return this.ok({});
}
@Post('/batchUpdateNotification', { description: Constants.per.authOnly, summary: "批量更新流水线通知" })
async batchUpdateNotification(@Body('ids') ids: number[], @Body('notification') notification: any) {
@Post("/batchUpdateNotification", { description: Constants.per.authOnly, summary: "批量更新流水线通知" })
async batchUpdateNotification(@Body("ids") ids: number[], @Body("notification") notification: any) {
// const isAdmin = await this.authService.isAdmin(this.ctx);
// const userId = isAdmin ? undefined : this.getUserId();
// await this.service.batchUpdateNotifications(ids, notification, userId);
await this.checkPermissionCall(async ({userId,projectId})=>{
await this.service.batchUpdateNotifications(ids, notification, userId,projectId);
})
await this.checkPermissionCall(async ({ userId, projectId }) => {
await this.service.batchUpdateNotifications(ids, notification, userId, projectId);
});
return this.ok({});
}
@Post('/batchUpdateCertApplyOptions', { description: Constants.per.authOnly, summary: "批量更新证书申请任务配置" })
async batchUpdateCertApplyOptions(@Body('ids') ids: number[], @Body('options') options: any) {
await this.checkPermissionCall(async ({userId,projectId})=>{
await this.service.batchUpdateCertApplyOptions(ids, options, userId,projectId);
})
@Post("/batchUpdateCertApplyOptions", { description: Constants.per.authOnly, summary: "批量更新证书申请任务配置" })
async batchUpdateCertApplyOptions(@Body("ids") ids: number[], @Body("options") options: any) {
await this.checkPermissionCall(async ({ userId, projectId }) => {
await this.service.batchUpdateCertApplyOptions(ids, options, userId, projectId);
});
return this.ok({});
}
@Post('/batchRerun', { description: Constants.per.authOnly, summary: "批量重新运行流水线" })
async batchRerun(@Body('ids') ids: number[], @Body('force') force: boolean) {
await this.checkPermissionCall(async ({userId,projectId})=>{
await this.service.batchRerun(ids, force,userId,projectId);
})
@Post("/batchRerun", { description: Constants.per.authOnly, summary: "批量重新运行流水线" })
async batchRerun(@Body("ids") ids: number[], @Body("force") force: boolean) {
await this.checkPermissionCall(async ({ userId, projectId }) => {
await this.service.batchRerun(ids, force, userId, projectId);
});
return this.ok({});
}
@Post('/batchTransfer', { description: Constants.per.authOnly, summary: "批量迁移流水线" })
async batchTransfer(@Body('ids') ids: number[], @Body('toProjectId') toProjectId: number) {
await this.checkPermissionCall(async ({})=>{
@Post("/batchTransfer", { description: Constants.per.authOnly, summary: "批量迁移流水线" })
async batchTransfer(@Body("ids") ids: number[], @Body("toProjectId") toProjectId: number) {
await this.checkPermissionCall(async ({}) => {
await this.service.batchTransfer(ids, toProjectId);
})
});
return this.ok({});
}
@Post('/refreshWebhookKey', { description: Constants.per.authOnly, summary: "刷新Webhook密钥" })
async refreshWebhookKey(@Body('id') id: number) {
await this.checkOwner(this.getService(), id,"write",true);
@Post("/refreshWebhookKey", { description: Constants.per.authOnly, summary: "刷新Webhook密钥" })
async refreshWebhookKey(@Body("id") id: number) {
await this.checkOwner(this.getService(), id, "write", true);
const res = await this.service.refreshWebhookKey(id);
return this.ok({
webhookKey: res,
});
}
}
@@ -1,15 +1,15 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { Constants, CrudController } from '@certd/lib-server';
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
import { PipelineGroupService } from '../../../modules/pipeline/service/pipeline-group-service.js';
import { ApiTags } from '@midwayjs/swagger';
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
import { Constants, CrudController } from "@certd/lib-server";
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
import { PipelineGroupService } from "../../../modules/pipeline/service/pipeline-group-service.js";
import { ApiTags } from "@midwayjs/swagger";
/**
* 通知
*/
@Provide()
@Controller('/api/pi/pipeline/group')
@ApiTags(['pipeline-group'])
@Controller("/api/pi/pipeline/group")
@ApiTags(["pipeline-group"])
export class PipelineGroupController extends CrudController<PipelineGroupService> {
@Inject()
service: PipelineGroupService;
@@ -20,14 +20,14 @@ export class PipelineGroupController extends CrudController<PipelineGroupService
return this.service;
}
@Post('/page', { description: Constants.per.authOnly, summary: "查询流水线分组分页列表" })
@Post("/page", { description: Constants.per.authOnly, summary: "查询流水线分组分页列表" })
async page(@Body(ALL) body: any) {
const {projectId,userId} = await this.getProjectUserIdRead();
const { projectId, userId } = await this.getProjectUserIdRead();
body.query = body.query ?? {};
delete body.query.userId;
body.query.projectId = projectId;
const buildQuery = qb => {
qb.andWhere('user_id = :userId', { userId: userId });
qb.andWhere("user_id = :userId", { userId: userId });
};
const res = await this.service.page({
query: body.query,
@@ -38,45 +38,45 @@ export class PipelineGroupController extends CrudController<PipelineGroupService
return this.ok(res);
}
@Post('/list', { description: Constants.per.authOnly, summary: "查询流水线分组列表" })
@Post("/list", { description: Constants.per.authOnly, summary: "查询流水线分组列表" })
async list(@Body(ALL) body: any) {
const {projectId,userId} = await this.getProjectUserIdRead();
const { projectId, userId } = await this.getProjectUserIdRead();
body.query = body.query ?? {};
body.query.userId = userId;
body.query.projectId = projectId;
return await super.list(body);
}
@Post('/add', { description: Constants.per.authOnly, summary: "添加流水线分组" })
@Post("/add", { description: Constants.per.authOnly, summary: "添加流水线分组" })
async add(@Body(ALL) bean: any) {
const {projectId,userId} = await this.getProjectUserIdRead();
const { projectId, userId } = await this.getProjectUserIdRead();
bean.userId = userId;
bean.projectId = projectId;
return await super.add(bean);
}
@Post('/update', { description: Constants.per.authOnly, summary: "更新流水线分组" })
@Post("/update", { description: Constants.per.authOnly, summary: "更新流水线分组" })
async update(@Body(ALL) bean) {
await this.checkOwner(this.getService(), bean.id, "write");
delete bean.userId;
delete bean.projectId;
return await super.update(bean);
}
@Post('/info', { description: Constants.per.authOnly, summary: "查询流水线分组详情" })
async info(@Query('id') id: number) {
@Post("/info", { description: Constants.per.authOnly, summary: "查询流水线分组详情" })
async info(@Query("id") id: number) {
await this.checkOwner(this.getService(), id, "read");
return await super.info(id);
}
@Post('/delete', { description: Constants.per.authOnly, summary: "删除流水线分组" })
async delete(@Query('id') id: number) {
@Post("/delete", { description: Constants.per.authOnly, summary: "删除流水线分组" })
async delete(@Query("id") id: number) {
await this.checkOwner(this.getService(), id, "write");
return await super.delete(id);
}
@Post('/all', { description: Constants.per.authOnly, summary: "查询所有流水线分组" })
@Post("/all", { description: Constants.per.authOnly, summary: "查询所有流水线分组" })
async all() {
const {projectId,userId} = await this.getProjectUserIdRead();
const { projectId, userId } = await this.getProjectUserIdRead();
const list: any = await this.service.find({
where: {
userId: userId,
@@ -1,16 +1,16 @@
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';
import {pluginGroups} from "@certd/pipeline";
import { ApiTags } from '@midwayjs/swagger';
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";
import { pluginGroups } from "@certd/pipeline";
import { ApiTags } from "@midwayjs/swagger";
/**
* 插件
*/
@Provide()
@Controller('/api/pi/plugin')
@ApiTags(['pipeline-plugin'])
@Controller("/api/pi/plugin")
@ApiTags(["pipeline-plugin"])
export class PluginController extends BaseController {
@Inject()
service: PluginService;
@@ -18,39 +18,39 @@ export class PluginController extends BaseController {
@Inject()
pluginConfigService: PluginConfigService;
@Post('/list', { description: Constants.per.authOnly, summary: "查询插件列表" })
@Post("/list", { description: Constants.per.authOnly, summary: "查询插件列表" })
async list(@Query(ALL) query: any) {
const list = await this.service.getEnabledBuiltInList();
return this.ok(list);
}
@Post('/groups', { description: Constants.per.authOnly, summary: "查询插件分组" })
@Post("/groups", { description: Constants.per.authOnly, summary: "查询插件分组" })
async groups(@Query(ALL) query: any) {
const group = await this.service.getEnabledBuildInGroup();
return this.ok(group);
}
@Post('/groupsList', { description: Constants.per.authOnly, summary: "查询插件分组列表" })
@Post("/groupsList", { description: Constants.per.authOnly, summary: "查询插件分组列表" })
async groupsList(@Query(ALL) query: any) {
const groups = pluginGroups
const groupsList:any = []
const groups = pluginGroups;
const groupsList: any = [];
for (const key in groups) {
const group = {
...groups[key]
}
delete group.plugins
groupsList.push(group)
...groups[key],
};
delete group.plugins;
groupsList.push(group);
}
return this.ok(groupsList);
}
@Post('/getDefineByType', { description: Constants.per.authOnly, summary: "根据类型获取插件定义" })
async getDefineByType(@Body('type') type: string) {
@Post("/getDefineByType", { description: Constants.per.authOnly, summary: "根据类型获取插件定义" })
async getDefineByType(@Body("type") type: string) {
const define = await this.service.getDefineByType(type);
return this.ok(define);
}
@Post('/config', { description: Constants.per.authOnly, summary: "获取插件配置" })
@Post("/config", { description: Constants.per.authOnly, summary: "获取插件配置" })
async config(@Body(ALL) body: { id?: number; name?: string; type: string }) {
const config = await this.pluginConfigService.getPluginConfig(body);
return this.ok(config);
@@ -1,16 +1,16 @@
import { Constants, CrudController } from '@certd/lib-server';
import { DomainParser } from '@certd/plugin-cert';
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { Constants, CrudController } from "@certd/lib-server";
import { DomainParser } from "@certd/plugin-cert";
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
import { SubDomainService } from "../../../modules/pipeline/service/sub-domain-service.js";
import { TaskServiceBuilder } from '../../../modules/pipeline/service/getter/task-service-getter.js';
import { ApiTags } from '@midwayjs/swagger';
import { TaskServiceBuilder } from "../../../modules/pipeline/service/getter/task-service-getter.js";
import { ApiTags } from "@midwayjs/swagger";
/**
* 子域名托管
*/
@Provide()
@Controller('/api/pi/subDomain')
@ApiTags(['pipeline-subdomain'])
@Controller("/api/pi/subDomain")
@ApiTags(["pipeline-subdomain"])
export class SubDomainController extends CrudController<SubDomainService> {
@Inject()
service: SubDomainService;
@@ -22,25 +22,24 @@ export class SubDomainController extends CrudController<SubDomainService> {
return this.service;
}
@Post('/parseDomain', { description: Constants.per.authOnly, summary: "解析域名" })
async parseDomain(@Body("fullDomain") fullDomain:string) {
const {projectId,userId} = await this.getProjectUserIdRead();
@Post("/parseDomain", { description: Constants.per.authOnly, summary: "解析域名" })
async parseDomain(@Body("fullDomain") fullDomain: string) {
const { projectId, userId } = await this.getProjectUserIdRead();
const taskService = this.taskServiceBuilder.create({ userId: userId, projectId: projectId });
const subDomainGetter = await taskService.getSubDomainsGetter();
const domainParser = new DomainParser(subDomainGetter)
const domain = await domainParser.parse(fullDomain)
const domainParser = new DomainParser(subDomainGetter);
const domain = await domainParser.parse(fullDomain);
return this.ok(domain);
}
@Post('/page', { description: Constants.per.authOnly, summary: "查询子域名分页列表" })
@Post("/page", { description: Constants.per.authOnly, summary: "查询子域名分页列表" })
async page(@Body(ALL) body) {
const {userId,projectId} = await this.getProjectUserIdRead();
const { userId, projectId } = await this.getProjectUserIdRead();
body.query = body.query ?? {};
delete body.query.userId;
body.query.projectId = projectId;
const buildQuery = qb => {
qb.andWhere('user_id = :userId', { userId: userId });
qb.andWhere("user_id = :userId", { userId: userId });
};
const res = await this.service.page({
query: body.query,
@@ -51,45 +50,45 @@ export class SubDomainController extends CrudController<SubDomainService> {
return this.ok(res);
}
@Post('/list', { description: Constants.per.authOnly, summary: "查询子域名列表" })
@Post("/list", { description: Constants.per.authOnly, summary: "查询子域名列表" })
async list(@Body(ALL) body) {
const {userId,projectId} = await this.getProjectUserIdRead();
const { userId, projectId } = await this.getProjectUserIdRead();
body.query = body.query ?? {};
body.query.userId = userId;
body.query.projectId = projectId;
return super.list(body);
}
@Post('/add', { description: Constants.per.authOnly, summary: "添加子域名" })
@Post("/add", { description: Constants.per.authOnly, summary: "添加子域名" })
async add(@Body(ALL) bean) {
const {userId,projectId} = await this.getProjectUserIdRead();
const { userId, projectId } = await this.getProjectUserIdRead();
bean.userId = userId;
bean.projectId = projectId;
return super.add(bean);
}
@Post('/update', { description: Constants.per.authOnly, summary: "更新子域名" })
@Post("/update", { description: Constants.per.authOnly, summary: "更新子域名" })
async update(@Body(ALL) bean) {
await this.checkOwner(this.getService(), bean.id, "write");
delete bean.userId;
delete bean.projectId;
return super.update(bean);
}
@Post('/info', { description: Constants.per.authOnly, summary: "查询子域名详情" })
async info(@Query('id') id: number) {
@Post("/info", { description: Constants.per.authOnly, summary: "查询子域名详情" })
async info(@Query("id") id: number) {
await this.checkOwner(this.getService(), id, "read");
return super.info(id);
}
@Post('/delete', { description: Constants.per.authOnly, summary: "删除子域名" })
async delete(@Query('id') id: number) {
@Post("/delete", { description: Constants.per.authOnly, summary: "删除子域名" })
async delete(@Query("id") id: number) {
await this.checkOwner(this.getService(), id, "write");
return super.delete(id);
}
@Post('/batchDelete', { description: Constants.per.authOnly, summary: "批量删除子域名" })
async batchDelete(@Body('ids') ids: number[]) {
const {userId,projectId} = await this.getProjectUserIdWrite();
@Post("/batchDelete", { description: Constants.per.authOnly, summary: "批量删除子域名" })
async batchDelete(@Body("ids") ids: number[]) {
const { userId, projectId } = await this.getProjectUserIdWrite();
await this.service.batchDelete(ids, userId, projectId);
return this.ok({});
}
@@ -1,15 +1,15 @@
import {ALL, Body, Controller, Inject, Post, Provide, Query} from '@midwayjs/core';
import {Constants, CrudController} from '@certd/lib-server';
import { TemplateService } from '../../../modules/pipeline/service/template-service.js';
import { checkPlus } from '@certd/plus-core';
import { ApiTags } from '@midwayjs/swagger';
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
import { Constants, CrudController } from "@certd/lib-server";
import { TemplateService } from "../../../modules/pipeline/service/template-service.js";
import { checkPlus } from "@certd/plus-core";
import { ApiTags } from "@midwayjs/swagger";
/**
* 流水线模版
*/
@Provide()
@Controller('/api/pi/template')
@ApiTags(['pipeline-template'])
@Controller("/api/pi/template")
@ApiTags(["pipeline-template"])
export class TemplateController extends CrudController<TemplateService> {
@Inject()
service: TemplateService;
@@ -18,17 +18,15 @@ export class TemplateController extends CrudController<TemplateService> {
return this.service;
}
@Post('/page', { description: Constants.per.authOnly, summary: "查询流水线模版分页列表" })
@Post("/page", { description: Constants.per.authOnly, summary: "查询流水线模版分页列表" })
async page(@Body(ALL) body) {
body.query = body.query ?? {};
delete body.query.userId;
const { projectId, userId } = await this.getProjectUserIdRead()
body.query.projectId = projectId
const { projectId, userId } = await this.getProjectUserIdRead();
body.query.projectId = projectId;
const buildQuery = qb => {
qb.andWhere('user_id = :userId', { userId: userId });
qb.andWhere("user_id = :userId", { userId: userId });
};
const res = await this.service.page({
query: body.query,
@@ -39,63 +37,63 @@ export class TemplateController extends CrudController<TemplateService> {
return this.ok(res);
}
@Post('/list', { description: Constants.per.authOnly, summary: "查询流水线模版列表" })
@Post("/list", { description: Constants.per.authOnly, summary: "查询流水线模版列表" })
async list(@Body(ALL) body) {
body.query = body.query ?? {};
const { projectId, userId } = await this.getProjectUserIdRead()
body.query.projectId = projectId
body.query.userId = userId
const { projectId, userId } = await this.getProjectUserIdRead();
body.query.projectId = projectId;
body.query.userId = userId;
return super.list(body);
}
@Post('/add', { description: Constants.per.authOnly, summary: "添加流水线模版" })
@Post("/add", { description: Constants.per.authOnly, summary: "添加流水线模版" })
async add(@Body(ALL) bean) {
const { projectId, userId } = await this.getProjectUserIdRead()
const { projectId, userId } = await this.getProjectUserIdRead();
bean.userId = userId;
bean.projectId = projectId
checkPlus()
bean.projectId = projectId;
checkPlus();
return super.add(bean);
}
@Post('/update', { description: Constants.per.authOnly, summary: "更新流水线模版" })
@Post("/update", { description: Constants.per.authOnly, summary: "更新流水线模版" })
async update(@Body(ALL) bean) {
await this.checkOwner(this.service, bean.id, "write");
delete bean.userId;
delete bean.projectId;
return super.update(bean);
}
@Post('/info', { description: Constants.per.authOnly, summary: "查询流水线模版详情" })
async info(@Query('id') id: number) {
await this.checkOwner(this.service, id, "read");
@Post("/info", { description: Constants.per.authOnly, summary: "查询流水线模版详情" })
async info(@Query("id") id: number) {
await this.checkOwner(this.service, id, "read");
return super.info(id);
}
@Post('/delete', { description: Constants.per.authOnly, summary: "删除流水线模版" })
async delete(@Query('id') id: number) {
const { userId ,projectId } = await this.getProjectUserIdWrite()
await this.service.batchDelete([id], userId,projectId);
@Post("/delete", { description: Constants.per.authOnly, summary: "删除流水线模版" })
async delete(@Query("id") id: number) {
const { userId, projectId } = await this.getProjectUserIdWrite();
await this.service.batchDelete([id], userId, projectId);
return this.ok({});
}
@Post('/batchDelete', { description: Constants.per.authOnly, summary: "批量删除流水线模版" })
async batchDelete(@Body('ids') ids: number[]) {
const { userId ,projectId } = await this.getProjectUserIdWrite()
await this.service.batchDelete(ids, userId,projectId);
@Post("/batchDelete", { description: Constants.per.authOnly, summary: "批量删除流水线模版" })
async batchDelete(@Body("ids") ids: number[]) {
const { userId, projectId } = await this.getProjectUserIdWrite();
await this.service.batchDelete(ids, userId, projectId);
return this.ok({});
}
@Post('/detail', { description: Constants.per.authOnly, summary: "查询流水线模版详情" })
async detail(@Query('id') id: number) {
const { userId ,projectId } = await this.getProjectUserIdRead()
const detail = await this.service.detail(id, userId,projectId);
@Post("/detail", { description: Constants.per.authOnly, summary: "查询流水线模版详情" })
async detail(@Query("id") id: number) {
const { userId, projectId } = await this.getProjectUserIdRead();
const detail = await this.service.detail(id, userId, projectId);
return this.ok(detail);
}
@Post('/createPipelineByTemplate', { description: Constants.per.authOnly, summary: "根据模版创建流水线" })
@Post("/createPipelineByTemplate", { description: Constants.per.authOnly, summary: "根据模版创建流水线" })
async createPipelineByTemplate(@Body(ALL) body: any) {
const { userId ,projectId } = await this.getProjectUserIdWrite()
const { userId, projectId } = await this.getProjectUserIdWrite();
body.userId = userId;
body.projectId = projectId
checkPlus()
body.projectId = projectId;
checkPlus();
const res = await this.service.createPipelineByTemplate(body);
return this.ok(res);
}