diff --git a/doc/dev/development.md b/doc/dev/development.md index dc6920e1..ba918ac0 100644 --- a/doc/dev/development.md +++ b/doc/dev/development.md @@ -3,7 +3,7 @@ ## 1.本地调试运行 -安装依赖包: +### 克隆代码 ```shell # 克隆代码 @@ -11,22 +11,38 @@ git clone https://github.com/certd/certd #进入项目目录 cd certd +``` +### 修改pnpm-workspace.yaml文件 +重要:否则无法正确加载专业版的access和plugin +```yaml +# pnpm-workspace.yaml +packages: + - 'packages/**' # <--------------注释掉这一行,PR时不要提交此修改 + - 'packages/ui/**' +``` + +### 安装依赖和初始化: +```shell +# 安装pnpm,如果提示npm命令不存在,就需要先安装nodejs +npm install -g pnpm@8.15.7 --registry=https://registry.npmmirror.com + +# 使用国内镜像源,如果有代理,就不需要 +pnpm config set registry https://registry.npmmirror.com # 安装依赖 -npm install -g pnpm@8.15.7 pnpm install # 初始化构建 npm run init ``` -启动 server: +### 启动 server: ```shell cd packages/ui/certd-server npm run dev ``` -启动 client: +### 启动 client: ```shell cd packages/ui/certd-client npm run dev @@ -48,7 +64,7 @@ npm run dev 这样用户就可以在`certd`后台中创建这种授权凭证了 ### 3. dns-provider -如果域名是这个平台进行解析的,那么你需要实现dns-provider +如果域名是这个平台进行解析的,那么你需要实现dns-provider,(申请证书需要) 参考`plugin-cloudflare/dns-provider.ts` 修改为你要做的平台的`dns-provider` ### 4. plugin-deploy @@ -66,7 +82,7 @@ export * from './plugins/plugin-deploy-to-xx' 在`./src/plugins/index.ts`中增加`import` ```ts -export * from "./plugin-cloudflare" +export * from "./plugin-cloudflare.js" ``` ## 重启服务进行调试 diff --git a/packages/ui/certd-server/src/plugins/index.ts b/packages/ui/certd-server/src/plugins/index.ts index 49d2300e..9f59a4b6 100644 --- a/packages/ui/certd-server/src/plugins/index.ts +++ b/packages/ui/certd-server/src/plugins/index.ts @@ -10,3 +10,4 @@ export * from './plugin-west/index.js'; export * from './plugin-doge/index.js'; export * from './plugin-qiniu/index.js'; export * from './plugin-jdcloud/index.js'; +export * from './plugin-woai/index.js'; diff --git a/packages/ui/certd-server/src/plugins/plugin-woai/access.ts b/packages/ui/certd-server/src/plugins/plugin-woai/access.ts new file mode 100644 index 00000000..b04cd8e5 --- /dev/null +++ b/packages/ui/certd-server/src/plugins/plugin-woai/access.ts @@ -0,0 +1,28 @@ +import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline'; + +@IsAccess({ + name: 'woai', + title: '我爱云授权', + desc: '我爱云CDN', +}) +export class WoaiAccess extends BaseAccess { + @AccessInput({ + title: '账号', + component: { + placeholder: '我爱云的账号', + }, + required: true, + }) + username = ''; + @AccessInput({ + title: '密码', + component: { + placeholder: '我爱云的密码', + }, + required: true, + encrypt: true, + }) + password = ''; +} + +new WoaiAccess(); diff --git a/packages/ui/certd-server/src/plugins/plugin-woai/index.ts b/packages/ui/certd-server/src/plugins/plugin-woai/index.ts new file mode 100644 index 00000000..fdad254f --- /dev/null +++ b/packages/ui/certd-server/src/plugins/plugin-woai/index.ts @@ -0,0 +1,2 @@ +export * from './plugins/index.js'; +export * from './access.js'; diff --git a/packages/ui/certd-server/src/plugins/plugin-woai/plugins/index.ts b/packages/ui/certd-server/src/plugins/plugin-woai/plugins/index.ts new file mode 100644 index 00000000..cd1308a9 --- /dev/null +++ b/packages/ui/certd-server/src/plugins/plugin-woai/plugins/index.ts @@ -0,0 +1 @@ +export * from './plugin-deploy-to-cdn.js'; diff --git a/packages/ui/certd-server/src/plugins/plugin-woai/plugins/plugin-deploy-to-cdn.ts b/packages/ui/certd-server/src/plugins/plugin-woai/plugins/plugin-deploy-to-cdn.ts new file mode 100644 index 00000000..f76e612e --- /dev/null +++ b/packages/ui/certd-server/src/plugins/plugin-woai/plugins/plugin-deploy-to-cdn.ts @@ -0,0 +1,94 @@ +import {AbstractTaskPlugin, HttpClient, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput} from '@certd/pipeline'; +import {CertInfo} from '@certd/plugin-cert'; +import {WoaiAccess} from '../access.js'; + +@IsTaskPlugin({ + name: 'woaiCloud', + title: '部署证书到我爱云 CDN', + desc: '部署证书到我爱云CDN', + icon: 'clarity:plugin-line', + group: pluginGroups.other.key, + default: { + strategy: { + runStrategy: RunStrategy.SkipWhenSucceed, + }, + }, +}) +export class WoaiCdnPlugin extends AbstractTaskPlugin { + @TaskInput({ + title: '证书ID', + helper: '请填写 证书列表 中的证书的ID', + component: {name: 'a-input'}, + required: true, + }) + certId!: string; + @TaskInput({ + title: '域名证书', + helper: '请选择前置任务输出的域名证书', + component: { + name: 'pi-output-selector', + from: ['CertApply', 'CertApplyLego'], + }, + required: true, + }) + cert!: CertInfo; + @TaskInput({ + title: 'Access授权', + helper: '我爱云的用户、密码授权', + component: { + name: 'pi-access-selector', + type: 'woai', + }, + required: true, + }) + accessId!: string; + http!: HttpClient; + private readonly baseApi = 'https://console.edeg.51vs.club'; + + async onInstance() { + this.http = this.ctx.http; + } + + private async doRequestApi(url: string, data: any = null, method = 'post', token: string | null = null) { + const headers = { + 'Content-Type': 'application/json', + ...(token ? {'Token': token} : {}), + }; + const res = await this.http.request({ + url, + method, + data, + headers, + }); + if (res.code !== 200) { + throw new Error(`${JSON.stringify(res.message)}`); + } + return res; + } + + async execute(): Promise { + const {certId, cert, accessId} = this; + const access = (await this.accessService.getById(accessId)) as WoaiAccess; + // 登录获取token + const loginResponse = await this.doRequestApi(`${this.baseApi}/account/login`, { + username: access.username, + password: access.password, + }); + const token = loginResponse.data.token; + this.logger.info('登录成功,获取到Token:', token); + // 更新证书 + const editCertResponse = await this.doRequestApi( + `${this.baseApi}/certificate/edit`, + { + id: certId, + cert: cert.crt, + key: cert.key, + }, + 'post', + token + ); + this.logger.info('证书更新成功:', editCertResponse.message); + } +} + +new WoaiCdnPlugin(); diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index c1368ed9..ef8aed88 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,5 +1,5 @@ packages: - # all packages in subdirs of packages/ and components/ - - 'packages/**' - # exclude packages that are inside test directories + - 'packages/**' # <--------------开发插件请注释掉这一行,PR时本修改不要提交 + - 'packages/ui/**' - '!**/test/**' +