mirror of https://github.com/certd/certd
chore: 1
parent
dd20af4ba0
commit
8b7572a9e5
|
@ -98,6 +98,7 @@ export default defineConfig({
|
|||
{ text: "忘记密码", link: "/guide/use/forgotpasswd/" },
|
||||
{ text: "数据备份", link: "/guide/use/backup/" },
|
||||
{ text: "Certd本身的证书更新", link: "/guide/use/https/index.md" },
|
||||
{ text: "js脚本插件使用", link: "/guide/use/custom-script/index.md" },
|
||||
{ text: "如何贡献代码", link: "/guide/development/index.md" },
|
||||
]
|
||||
},
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
# 自定义脚本插件
|
||||
|
||||
## 介绍
|
||||
|
||||
自定义脚本插件是一个通用的插件,可以通过编写脚本来实现各种功能,例如:调用第三方API、执行系统命令、发送邮件等。
|
||||
|
||||
## 使用示例
|
||||
```js
|
||||
const certPem = this.ctx.self.cert.crt
|
||||
const certKey = this.ctx.self.cert.key
|
||||
|
||||
//axios发起http请求上传证书
|
||||
const res = await this.ctx.http.request({
|
||||
url:"your_cert_deploy_url",
|
||||
method:"post",
|
||||
data:{
|
||||
crt : certPem,
|
||||
key : certKey
|
||||
}
|
||||
})
|
||||
this.ctx.logger.info("上传成功",res.data)
|
||||
|
||||
|
||||
```
|
||||
## API
|
||||
|
||||
|
||||
```ts
|
||||
|
||||
type ctx = {
|
||||
CertReader: typeof CertReader;
|
||||
self: CustomScriptPlugin;
|
||||
//流水线定义
|
||||
pipeline: Pipeline;
|
||||
//步骤定义
|
||||
step: Step;
|
||||
//日志
|
||||
logger: Logger;
|
||||
//当前步骤输入参数跟上一次执行比较是否有变化
|
||||
inputChanged: boolean;
|
||||
//授权获取服务
|
||||
accessService: IAccessService;
|
||||
//邮件服务
|
||||
emailService: IEmailService;
|
||||
//cname记录服务
|
||||
cnameProxyService: ICnameProxyService;
|
||||
//插件配置服务
|
||||
pluginConfigService: IPluginConfigService;
|
||||
//流水线上下文
|
||||
pipelineContext: IContext;
|
||||
//用户上下文
|
||||
userContext: IContext;
|
||||
//http请求客户端
|
||||
http: HttpClient; // http.request(AxiosConfig)
|
||||
//文件存储
|
||||
fileStore: FileStore;
|
||||
//上一次执行结果状态
|
||||
lastStatus?: Runnable;
|
||||
//用户取消信号
|
||||
signal: AbortSignal;
|
||||
//工具类
|
||||
utils: typeof utils;
|
||||
//用户信息
|
||||
user: UserInfo;
|
||||
}
|
||||
|
||||
type CertInfo = {
|
||||
crt:string; //fullchain证书,即 cert.pem, cert.crt
|
||||
key:string; // 私钥
|
||||
ic: string; //中间证书
|
||||
pfx: string;//PFX证书,base64编码
|
||||
der: string;//DER证书,base64编码
|
||||
}
|
||||
|
||||
type CustomScriptPlugin = {
|
||||
//可以获取证书
|
||||
cert: CertInfo
|
||||
}
|
||||
|
||||
```
|
Loading…
Reference in New Issue