mirror of
https://github.com/certd/certd.git
synced 2026-07-14 17:53:28 +08:00
chore: format
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import {AccessInput, BaseAccess, IsAccess} from "@certd/pipeline";
|
||||
import {HttpRequestConfig} from "@certd/basic";
|
||||
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
|
||||
import { HttpRequestConfig } from "@certd/basic";
|
||||
import { CertInfo } from "@certd/plugin-cert";
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
@IsAccess({
|
||||
@@ -10,56 +9,52 @@ import { CertInfo } from "@certd/plugin-cert";
|
||||
title: "雨云授权",
|
||||
desc: "https://app.rainyun.com/",
|
||||
icon: "svg:icon-rainyun",
|
||||
order: 100
|
||||
order: 100,
|
||||
})
|
||||
export class RainyunAccess extends BaseAccess {
|
||||
|
||||
|
||||
@AccessInput({
|
||||
title: "ApiKey",
|
||||
component: {
|
||||
placeholder: "api-key",
|
||||
name: "a-input",
|
||||
vModel: "value"
|
||||
vModel: "value",
|
||||
},
|
||||
helper:"https://app.rainyun.com/account/settings/api-key",
|
||||
helper: "https://app.rainyun.com/account/settings/api-key",
|
||||
encrypt: true,
|
||||
required: true
|
||||
required: true,
|
||||
})
|
||||
apiKey!: string;
|
||||
|
||||
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "TestRequest"
|
||||
action: "TestRequest",
|
||||
},
|
||||
helper: "点击测试接口是否正常"
|
||||
helper: "点击测试接口是否正常",
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
async onTestRequest() {
|
||||
await this.getDomainList({limit:1});
|
||||
return "ok"
|
||||
await this.getDomainList({ limit: 1 });
|
||||
return "ok";
|
||||
}
|
||||
|
||||
// {"columnFilters":{"domains.Domain":"domain"},"sort":[],"page":1,"perPage":20}
|
||||
async getDomainList(req:{offset?:number,limit?:number,query?:string}){
|
||||
async getDomainList(req: { offset?: number; limit?: number; query?: string }) {
|
||||
const size = req.limit ?? 20;
|
||||
const offset = req.offset ?? 0;
|
||||
let page = Math.floor(offset / size);
|
||||
if(offset % size === 0 ){
|
||||
page++
|
||||
if (offset % size === 0) {
|
||||
page++;
|
||||
}
|
||||
const options ={
|
||||
const options = {
|
||||
page: page,
|
||||
perPage: size,
|
||||
columnFilters: {
|
||||
"domains.Domain": req.query??""
|
||||
"domains.Domain": req.query ?? "",
|
||||
},
|
||||
}
|
||||
};
|
||||
const res = await this.doRequest({
|
||||
url: `/product/domain/?options=${encodeURIComponent(JSON.stringify(options))}`,
|
||||
method: "GET",
|
||||
@@ -69,23 +64,21 @@ export class RainyunAccess extends BaseAccess {
|
||||
total: res.TotalRecords,
|
||||
list: res.Records || [],
|
||||
limit: size,
|
||||
offset: offset
|
||||
}
|
||||
offset: offset,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
async getCertList(req:{pageNo?:number,pageSize?:number,query?:string}){
|
||||
async getCertList(req: { pageNo?: number; pageSize?: number; query?: string }) {
|
||||
const pageNo = req.pageNo ?? 1;
|
||||
const pageSize = req.pageSize ?? 20;
|
||||
const options ={
|
||||
const options = {
|
||||
columnFilters: {
|
||||
Domain: req.query??""
|
||||
Domain: req.query ?? "",
|
||||
},
|
||||
sort:[],
|
||||
sort: [],
|
||||
page: pageNo,
|
||||
perPage: pageSize,
|
||||
|
||||
}
|
||||
};
|
||||
const res = await this.doRequest({
|
||||
url: `product/sslcenter/?options=${encodeURIComponent(JSON.stringify(options))}`,
|
||||
method: "GET",
|
||||
@@ -95,12 +88,11 @@ export class RainyunAccess extends BaseAccess {
|
||||
total: res.TotalRecords,
|
||||
list: res.Records || [],
|
||||
pageNo: pageNo,
|
||||
pageSize: pageSize
|
||||
}
|
||||
pageSize: pageSize,
|
||||
};
|
||||
}
|
||||
|
||||
async doCertReplace(req:{certId:number,cert:CertInfo}){
|
||||
|
||||
async doCertReplace(req: { certId: number; cert: CertInfo }) {
|
||||
// /product/sslcenter/{id}
|
||||
return await this.doRequest({
|
||||
url: `product/sslcenter/${req.certId}`,
|
||||
@@ -108,29 +100,27 @@ export class RainyunAccess extends BaseAccess {
|
||||
data: {
|
||||
cert: req.cert.crt,
|
||||
key: req.cert.key,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
async getDomainId(domain:string){
|
||||
const res = await this.getDomainList({query: domain,limit:1});
|
||||
async getDomainId(domain: string) {
|
||||
const res = await this.getDomainList({ query: domain, limit: 1 });
|
||||
if (res.list.length === 0) {
|
||||
throw new Error(`域名${domain}不存在` );
|
||||
throw new Error(`域名${domain}不存在`);
|
||||
}
|
||||
return res.list[0].id;
|
||||
}
|
||||
|
||||
async doRequest(req:HttpRequestConfig){
|
||||
const res = await this.ctx.http.request({
|
||||
async doRequest(req: HttpRequestConfig) {
|
||||
const res = await this.ctx.http.request({
|
||||
url: req.url,
|
||||
baseURL:"https://api.v2.rainyun.com",
|
||||
method: req.method|| "POST",
|
||||
baseURL: "https://api.v2.rainyun.com",
|
||||
method: req.method || "POST",
|
||||
data: req.data,
|
||||
params: req.params,
|
||||
headers:{
|
||||
"X-Api-Key": this.apiKey
|
||||
params: req.params,
|
||||
headers: {
|
||||
"X-Api-Key": this.apiKey,
|
||||
},
|
||||
// httpProxy: this.httpProxy||undefined,
|
||||
});
|
||||
@@ -142,6 +132,4 @@ export class RainyunAccess extends BaseAccess {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
new RainyunAccess();
|
||||
|
||||
@@ -10,15 +10,11 @@ import { Pager, PageRes, PageSearch } from "@certd/pipeline";
|
||||
icon: "svg:icon-rainyun",
|
||||
})
|
||||
export class RainyunDnsProvider extends AbstractDnsProvider {
|
||||
|
||||
client: any;
|
||||
|
||||
async onInstance() {
|
||||
|
||||
}
|
||||
async onInstance() {}
|
||||
|
||||
async createRecord(options: CreateRecordOptions): Promise<any> {
|
||||
|
||||
const access: RainyunAccess = this.ctx.access as RainyunAccess;
|
||||
|
||||
const domainId = await access.getDomainId(options.domain);
|
||||
@@ -38,18 +34,16 @@ export class RainyunDnsProvider extends AbstractDnsProvider {
|
||||
level: 1,
|
||||
type: type,
|
||||
line: "DEFAULT",
|
||||
ttl: 60
|
||||
}
|
||||
ttl: 60,
|
||||
},
|
||||
});
|
||||
this.logger.info("添加域名解析成功:", JSON.stringify(options), ret);
|
||||
return {
|
||||
recordId: ret,
|
||||
domainId: domainId
|
||||
domainId: domainId,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
async removeRecord(options: RemoveRecordOptions<any>): Promise<any> {
|
||||
const { fullRecord, value } = options.recordReq;
|
||||
const access: RainyunAccess = this.ctx.access as RainyunAccess;
|
||||
@@ -69,14 +63,14 @@ export class RainyunDnsProvider extends AbstractDnsProvider {
|
||||
offset: pager.getOffset(),
|
||||
limit: pager.pageSize,
|
||||
query: req.searchKey,
|
||||
})
|
||||
});
|
||||
// this.logger.info("获取域名列表成功:", ret);
|
||||
const list = ret.list.map((item: any) => ({
|
||||
id: item.id,
|
||||
domain: item.domain,
|
||||
}));
|
||||
return {
|
||||
total:ret.total || list.length,
|
||||
total: ret.total || list.length,
|
||||
list,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from './plugin-refresh-cert.js'
|
||||
export * from "./plugin-refresh-cert.js";
|
||||
|
||||
+13
-14
@@ -15,9 +15,9 @@ import { RainyunAccess } from "../access.js";
|
||||
default: {
|
||||
//默认值配置照抄即可
|
||||
strategy: {
|
||||
runStrategy: RunStrategy.SkipWhenSucceed
|
||||
}
|
||||
}
|
||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||
},
|
||||
},
|
||||
})
|
||||
//类名规范,跟上面插件名称(name)一致
|
||||
export class RainyunRefreshCert extends AbstractTaskPlugin {
|
||||
@@ -27,8 +27,8 @@ export class RainyunRefreshCert extends AbstractTaskPlugin {
|
||||
helper: "请选择前置任务输出的域名证书",
|
||||
component: {
|
||||
name: "output-selector",
|
||||
from: [...CertApplyPluginNames]
|
||||
}
|
||||
from: [...CertApplyPluginNames],
|
||||
},
|
||||
// required: true, // 必填
|
||||
})
|
||||
cert!: CertInfo;
|
||||
@@ -41,9 +41,9 @@ export class RainyunRefreshCert extends AbstractTaskPlugin {
|
||||
title: "雨云授权",
|
||||
component: {
|
||||
name: "access-selector",
|
||||
type: "rainyun" //固定授权类型
|
||||
type: "rainyun", //固定授权类型
|
||||
},
|
||||
required: true //必填
|
||||
required: true, //必填
|
||||
})
|
||||
accessId!: string;
|
||||
//
|
||||
@@ -53,14 +53,13 @@ export class RainyunRefreshCert extends AbstractTaskPlugin {
|
||||
title: "证书Id",
|
||||
helper: "要更新的rainyun证书id",
|
||||
|
||||
action: RainyunRefreshCert.prototype.onGetCertList.name
|
||||
action: RainyunRefreshCert.prototype.onGetCertList.name,
|
||||
})
|
||||
)
|
||||
certList!: number[];
|
||||
|
||||
//插件实例化时执行的方法
|
||||
async onInstance() {
|
||||
}
|
||||
async onInstance() {}
|
||||
|
||||
//插件执行方法
|
||||
async execute(): Promise<void> {
|
||||
@@ -70,7 +69,7 @@ export class RainyunRefreshCert extends AbstractTaskPlugin {
|
||||
this.logger.info(`----------- 开始更新证书:${item}`);
|
||||
await access.doCertReplace({
|
||||
certId: item,
|
||||
cert: this.cert
|
||||
cert: this.cert,
|
||||
});
|
||||
this.logger.info(`----------- 更新证书${item}成功`);
|
||||
}
|
||||
@@ -85,7 +84,7 @@ export class RainyunRefreshCert extends AbstractTaskPlugin {
|
||||
const pageSize = req.pageSize ?? 100;
|
||||
const res = await access.getCertList({
|
||||
pageNo,
|
||||
pageSize
|
||||
pageSize,
|
||||
});
|
||||
const total = res.total;
|
||||
const list = res.list;
|
||||
@@ -97,14 +96,14 @@ export class RainyunRefreshCert extends AbstractTaskPlugin {
|
||||
return {
|
||||
label: `${item.Domain}<${item.ID}>`,
|
||||
value: item.ID,
|
||||
domain: item.Domain.split(",").map(item => item.trim())
|
||||
domain: item.Domain.split(",").map(item => item.trim()),
|
||||
};
|
||||
});
|
||||
return {
|
||||
list: this.ctx.utils.options.buildGroupOptions(options, this.certDomains),
|
||||
total: total,
|
||||
pageNo: pageNo,
|
||||
pageSize: pageSize
|
||||
pageSize: pageSize,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user