mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
perf: 插件贡献文档及示例
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"extends": [
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:prettier/recommended",
|
||||
"prettier"
|
||||
],
|
||||
"env": {
|
||||
"mocha": true
|
||||
},
|
||||
"rules": {
|
||||
"@typescript-eslint/no-var-requires": "off",
|
||||
"@typescript-eslint/ban-ts-comment": "off",
|
||||
"@typescript-eslint/ban-ts-ignore": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-empty-function": "off",
|
||||
// "no-unused-expressions": "off",
|
||||
"max-len": [0, 160, 2, { "ignoreUrls": true }]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
test/user.secret.ts
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extension": ["ts"],
|
||||
"spec": "test/**/*.test.ts",
|
||||
"require": "ts-node/register"
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
src
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"printWidth": 160
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.20.5](https://github.com/certd/certd/compare/v1.20.2...v1.20.5) (2024-03-11)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 修复腾讯云cdn部署无法选择端点的bug ([154409b](https://github.com/certd/certd/commit/154409b1dfee3ea1caae740ad9c1f99a6e7a9814))
|
||||
|
||||
## [1.20.2](https://github.com/certd/certd/compare/v1.2.1...v1.20.2) (2024-02-28)
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-tencent
|
||||
|
||||
## [1.2.1](https://github.com/certd/certd/compare/v1.2.0...v1.2.1) (2023-12-12)
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-tencent
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-tencent
|
||||
|
||||
# [1.2.0](https://github.com/certd/certd/compare/v1.1.6...v1.2.0) (2023-10-27)
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-tencent
|
||||
|
||||
## [1.1.6](https://github.com/certd/certd/compare/v1.1.5...v1.1.6) (2023-07-10)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 修复上传证书到腾讯云失败的bug ([e950322](https://github.com/certd/certd/commit/e950322232e19d1263b8552eefa5b0150fd7864e))
|
||||
|
||||
## [1.1.5](https://github.com/certd/certd/compare/v1.1.4...v1.1.5) (2023-07-03)
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-tencent
|
||||
|
||||
## [1.1.4](https://github.com/certd/certd/compare/v1.1.3...v1.1.4) (2023-07-03)
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* timeout ([3eeb1f7](https://github.com/certd/certd/commit/3eeb1f77aa2922f3545f3d2067f561d95621d54f))
|
||||
|
||||
## [1.1.3](https://github.com/certd/certd/compare/v1.1.2...v1.1.3) (2023-07-03)
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-tencent
|
||||
|
||||
## [1.1.2](https://github.com/certd/certd/compare/v1.1.1...v1.1.2) (2023-07-03)
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-tencent
|
||||
|
||||
## [1.1.1](https://github.com/certd/certd/compare/v1.1.0...v1.1.1) (2023-06-28)
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-tencent
|
||||
|
||||
# [1.1.0](https://github.com/certd/certd/compare/v1.0.6...v1.1.0) (2023-06-28)
|
||||
|
||||
### Features
|
||||
|
||||
* save files ([671d273](https://github.com/certd/certd/commit/671d273e2f9136d16896536b0ca127cf372f1619))
|
||||
|
||||
## [1.0.6](https://github.com/certd/certd/compare/v1.0.5...v1.0.6) (2023-05-25)
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-tencent
|
||||
|
||||
## [1.0.5](https://github.com/certd/certd/compare/v1.0.4...v1.0.5) (2023-05-25)
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-tencent
|
||||
|
||||
## [1.0.4](https://github.com/certd/certd/compare/v1.0.3...v1.0.4) (2023-05-25)
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-tencent
|
||||
|
||||
## [1.0.3](https://github.com/certd/certd/compare/v1.0.2...v1.0.3) (2023-05-25)
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-tencent
|
||||
|
||||
## [1.0.2](https://github.com/certd/certd/compare/v1.0.1...v1.0.2) (2023-05-24)
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-tencent
|
||||
|
||||
## [1.0.1](https://github.com/certd/certd/compare/v1.0.0...v1.0.1) (2023-05-24)
|
||||
|
||||
**Note:** Version bump only for package @certd/plugin-tencent
|
||||
@@ -0,0 +1,18 @@
|
||||
# 贡献插件
|
||||
|
||||
## 1.复制demo作为你的根目录
|
||||
比如你想做cloudflare的插件,那么你可以复制demo目录,将其命名成cloudflare。
|
||||
|
||||
## 2. access授权
|
||||
如果这是一个新的平台,它应该有授权方式,比如accessKey accessSecret之类的
|
||||
参考`demo/access.ts` 修改为你要做的平台的`access`
|
||||
这样用户就可以在certd后台中创建这种授权凭证了
|
||||
|
||||
## 3. dns-provider
|
||||
如果域名是这个平台进行解析的,那么你需要实现dns-provider
|
||||
参考`demo/dns-provider.ts` 修改为你要做的平台的`dns-provider`
|
||||
|
||||
## 4. deploy-plugin
|
||||
如果这个平台有需要部署证书的地方
|
||||
参考`demo/deploy-plugin.ts` 修改为你要做的平台的`deploy-plugin`
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
//@ts-ignore
|
||||
DYNAMIC_IMPORT_SCRIPT
|
||||
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"name": "@certd/plugin-center",
|
||||
"private": false,
|
||||
"version": "1.20.5",
|
||||
"main": "./src/index.ts",
|
||||
"module": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"publishConfig": {
|
||||
"main": "./dist/bundle.js",
|
||||
"module": "./dist/bundle.mjs",
|
||||
"types": "./dist/d/index.d.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "rollup -c",
|
||||
"build2": "vue-tsc --noEmit && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@certd/pipeline": "^1.20.5",
|
||||
"@certd/plugin-cert": "^1.20.5",
|
||||
"@certd/plugin-util": "^1.20.5",
|
||||
"@rollup/plugin-dynamic-import-vars": "^2.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^23.0.4",
|
||||
"@rollup/plugin-json": "^6.0.0",
|
||||
"@rollup/plugin-node-resolve": "^15.0.1",
|
||||
"@rollup/plugin-replace": "^5.0.5",
|
||||
"@rollup/plugin-terser": "^0.4.3",
|
||||
"@rollup/plugin-typescript": "^11.0.0",
|
||||
"@types/chai": "^4.3.3",
|
||||
"@types/lodash": "^4.14.186",
|
||||
"@types/mocha": "^10.0.0",
|
||||
"@types/node-forge": "^1.3.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.38.1",
|
||||
"@typescript-eslint/parser": "^5.38.1",
|
||||
"axios": "^0.21.1",
|
||||
"chai": "^4.3.6",
|
||||
"dayjs": "^1.9.7",
|
||||
"eslint": "^8.24.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"lodash": "^4.17.20",
|
||||
"log4js": "^6.7.1",
|
||||
"mocha": "^10.1.0",
|
||||
"prettier": "^2.8.8",
|
||||
"rollup": "^3.7.4",
|
||||
"rollup-plugin-visualizer": "^5.8.2",
|
||||
"ts-node": "^10.9.1",
|
||||
"tslib": "^2.5.2",
|
||||
"typescript": "^4.8.4"
|
||||
},
|
||||
"gitHead": "b258e926209fef4cc4d633b0383eb54e26c516f9"
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
const resolve = require("@rollup/plugin-node-resolve");
|
||||
const commonjs = require("@rollup/plugin-commonjs");
|
||||
//const Typescript = require("rollup-plugin-typescript2");
|
||||
const Typescript = require("@rollup/plugin-typescript");
|
||||
const json = require("@rollup/plugin-json");
|
||||
const terser = require("@rollup/plugin-terser");
|
||||
const dynamicImportVars =require ('@rollup/plugin-dynamic-import-vars');
|
||||
const replace =require( '@rollup/plugin-replace')
|
||||
const path = require("path")
|
||||
const fs = require("fs")
|
||||
function dynamicImport(directory) {
|
||||
|
||||
function readFilesRecursively(directory) {
|
||||
let filePaths = [];
|
||||
const files = fs.readdirSync(directory);
|
||||
files.forEach(file => {
|
||||
|
||||
const filePath = directory+"/"+file;
|
||||
const stats = fs.statSync(filePath);
|
||||
if (stats.isDirectory()) {
|
||||
filePaths = filePaths.concat(readFilesRecursively(filePath)); // Recursively read subdirectory and concatenate the results
|
||||
} else if(filePath.endsWith(".ts")) {
|
||||
filePaths.push(filePath); // Add file path to the array
|
||||
}
|
||||
});
|
||||
return filePaths;
|
||||
}
|
||||
|
||||
const files = readFilesRecursively(directory);
|
||||
console.log("files",files)
|
||||
|
||||
return files.filter(file=>file.indexOf("/index.ts")<0).map(file => `import './${file}';`).join('\n');
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
input: "./src/index.ts",
|
||||
output: {
|
||||
file: "dist/bundle.js",
|
||||
format: "cjs",
|
||||
},
|
||||
plugins: [
|
||||
|
||||
// 解析第三方依赖
|
||||
resolve(),
|
||||
// 识别 commonjs 模式第三方依赖
|
||||
commonjs(),
|
||||
Typescript({
|
||||
target: "esnext",
|
||||
rootDir: "src",
|
||||
declaration: true,
|
||||
declarationDir: "dist/d",
|
||||
exclude: ["./node_modules/**", "./src/**/*.vue","./dist/**"],
|
||||
allowSyntheticDefaultImports: true,
|
||||
}),
|
||||
dynamicImportVars({
|
||||
// options
|
||||
}),
|
||||
replace({
|
||||
'DYNAMIC_IMPORT_SCRIPT': dynamicImport("./src") // 替换成你的目录路径
|
||||
}),
|
||||
json(),
|
||||
terser(),
|
||||
],
|
||||
external: [
|
||||
"vue",
|
||||
"lodash",
|
||||
"dayjs",
|
||||
"@certd/acme-client",
|
||||
"@certd/pipeline",
|
||||
"@certd/plugin-cert",
|
||||
"@certd/plugin-aliyun",
|
||||
"@certd/plugin-tencent",
|
||||
"@certd/plugin-huawei",
|
||||
"@certd/plugin-host",
|
||||
"@certd/plugin-tencent",
|
||||
"@certd/plugin-util",
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
import { IsAccess, AccessInput } from "@certd/pipeline";
|
||||
|
||||
/**
|
||||
* 这个注解将注册一个授权配置
|
||||
* 在certd的后台管理系统中,用户可以选择添加此类型的授权
|
||||
*/
|
||||
@IsAccess({
|
||||
name: "demo",
|
||||
title: "授权插件示例",
|
||||
desc: "",
|
||||
})
|
||||
export class DemoAccess {
|
||||
/**
|
||||
* 授权属性配置
|
||||
*/
|
||||
@AccessInput({
|
||||
title: "密钥Id",
|
||||
component: {
|
||||
placeholder: "demoKeyId",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
demoKeyId = "";
|
||||
|
||||
/**
|
||||
* 授权属性配置
|
||||
*/
|
||||
@AccessInput({
|
||||
//标题
|
||||
title: "密钥串",
|
||||
component: {
|
||||
//input组件的placeholder
|
||||
placeholder: "demoKeySecret",
|
||||
},
|
||||
//是否必填
|
||||
required: true,
|
||||
})
|
||||
//属性名称
|
||||
demoKeySecret = "";
|
||||
}
|
||||
|
||||
new DemoAccess();
|
||||
@@ -0,0 +1,79 @@
|
||||
import _ from "lodash";
|
||||
import { CreateRecordOptions, IDnsProvider, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { Autowire, ILogger } from "@certd/pipeline";
|
||||
import { DemoAccess } from "./access";
|
||||
|
||||
// TODO 这里注册一个dnsProvider
|
||||
@IsDnsProvider({
|
||||
//注意这里name,要跟access的name一致
|
||||
name: "demo",
|
||||
title: "Dns提供商Demo",
|
||||
desc: "demo dns provider示例",
|
||||
accessType: "demo",
|
||||
})
|
||||
export class DemoDnsProvider implements IDnsProvider {
|
||||
@Autowire()
|
||||
access!: DemoAccess;
|
||||
@Autowire()
|
||||
logger!: ILogger;
|
||||
|
||||
async onInstance() {
|
||||
const access: any = this.access;
|
||||
this.logger.debug("access",access)
|
||||
//初始化的操作
|
||||
//...
|
||||
}
|
||||
|
||||
async getDomainList():Promise<any[]> {
|
||||
// TODO 这里你要实现一个获取域名列表的方法
|
||||
const access = this.access
|
||||
this.logger.debug("access",access)
|
||||
return []
|
||||
}
|
||||
|
||||
async matchDomain(dnsRecord: string):Promise<any> {
|
||||
const domainList = await this.getDomainList();
|
||||
let domainRecord = null;
|
||||
for (const item of domainList) {
|
||||
//TODO 根据域名去匹配账户中是否有该域名, 这里不一定是item.name 具体要看你要实现的平台的接口而定
|
||||
if (_.endsWith(dnsRecord + ".", item.name)) {
|
||||
domainRecord = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!domainRecord) {
|
||||
this.logger.info("账户中域名列表:",domainList)
|
||||
this.logger.error("找不到域名,请确认账户中是否真的有此域名")
|
||||
throw new Error("can not find Domain:"+dnsRecord);
|
||||
}
|
||||
return domainRecord;
|
||||
}
|
||||
|
||||
|
||||
|
||||
async createRecord(options: CreateRecordOptions): Promise<any> {
|
||||
const { fullRecord, value, type } = options;
|
||||
this.logger.info("添加域名解析:", fullRecord, value,type);
|
||||
//先确定账户中是否有该域名
|
||||
const domainRecord = await this.matchDomain(fullRecord);
|
||||
this.logger.debug("matchDomain:",domainRecord)
|
||||
//TODO 然后调用接口,创建txt类型的dns解析记录
|
||||
// .. 这里调用对应平台的后台接口
|
||||
const access = this.access
|
||||
this.logger.debug("access",access)
|
||||
|
||||
|
||||
|
||||
}
|
||||
async removeRecord(options: RemoveRecordOptions): Promise<any> {
|
||||
const { fullRecord, value, record } = options;
|
||||
this.logger.info("删除域名解析:", fullRecord, value,record);
|
||||
//TODO 这里调用删除txt dns解析记录接口
|
||||
const access = this.access
|
||||
this.logger.debug("access",access)
|
||||
this.logger.info("删除域名解析成功:", fullRecord, value);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO 实例化这个provider,将其自动注册到系统中
|
||||
new DemoDnsProvider();
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './dns-provider'
|
||||
export * from './plugin-test'
|
||||
export * from './access'
|
||||
@@ -0,0 +1,87 @@
|
||||
import { AbstractTaskPlugin, IAccessService, ILogger, IsTaskPlugin, RunStrategy, TaskInput } from "@certd/pipeline";
|
||||
import { CertInfo, CertReader } from "@certd/plugin-cert";
|
||||
|
||||
@IsTaskPlugin({
|
||||
name: "demoTest",
|
||||
title: "Demo测试插件",
|
||||
default: {
|
||||
strategy: {
|
||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||
},
|
||||
},
|
||||
})
|
||||
export class DemoTestPlugin extends AbstractTaskPlugin {
|
||||
|
||||
//测试参数
|
||||
@TaskInput({
|
||||
title: "属性示例",
|
||||
})
|
||||
text!: string;
|
||||
|
||||
//测试参数
|
||||
@TaskInput({
|
||||
title: "选择框",
|
||||
component:{
|
||||
name:"a-select",
|
||||
options:[
|
||||
{value:"1",label:"选项1"},
|
||||
{value:"2",label:"选项2"},
|
||||
]
|
||||
}
|
||||
})
|
||||
select!: string;
|
||||
|
||||
//测试参数
|
||||
@TaskInput({
|
||||
title: "switch",
|
||||
component:{
|
||||
name:"a-switch",
|
||||
}
|
||||
})
|
||||
switch!: boolean;
|
||||
//证书选择,此项必须要有
|
||||
@TaskInput({
|
||||
title: "域名证书",
|
||||
helper: "请选择前置任务输出的域名证书",
|
||||
component: {
|
||||
name: "pi-output-selector",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
cert!: CertInfo;
|
||||
|
||||
//授权选择框
|
||||
@TaskInput({
|
||||
title: "demo授权",
|
||||
helper: "demoAccess授权",
|
||||
component: {
|
||||
name: "pi-access-selector",
|
||||
type: "demoAccess",
|
||||
},
|
||||
rules: [{ required: true, message: "此项必填" }],
|
||||
})
|
||||
accessId!: string;
|
||||
|
||||
accessService!: IAccessService;
|
||||
logger!: ILogger;
|
||||
|
||||
async onInstance() {
|
||||
this.accessService = this.ctx.accessService;
|
||||
this.logger = this.ctx.logger;
|
||||
}
|
||||
async execute(): Promise<void> {
|
||||
const { select, text, cert, accessId } = this;
|
||||
const certReader = new CertReader(cert);
|
||||
const access = await this.accessService.getById(accessId);
|
||||
this.logger.debug("access",access)
|
||||
this.logger.debug("certReader",certReader)
|
||||
this.logger.info("DemoTestPlugin execute");
|
||||
this.logger.info( "text:", text);
|
||||
this.logger.info( "select:", select);
|
||||
this.logger.info( "switch:", this.switch);
|
||||
this.logger.info( "授权id:", accessId);
|
||||
//TODO 这里实现你要部署的执行方法
|
||||
}
|
||||
}
|
||||
//TODO 这里实例化插件,进行注册
|
||||
new DemoTestPlugin();
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./demo"
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
"sourceMap": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"skipLibCheck": true,
|
||||
"experimentalDecorators": true
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue","test/**/*.ts"],
|
||||
}
|
||||
Reference in New Issue
Block a user