mirror of https://github.com/certd/certd
chore:
parent
f876ac99b0
commit
b421798a1b
|
@ -1,6 +1,10 @@
|
||||||
<template>
|
<template>
|
||||||
<a-select mode="tags" readonly :value="modelValue" />
|
<div class="cert-domains-getter">
|
||||||
<div>{{ errorRef }}</div>
|
<div>
|
||||||
|
<a-tag v-for="item of modelValue" :key="item" type="success" class="m-3">{{ item }}</a-tag>
|
||||||
|
</div>
|
||||||
|
<div class="helper">{{ errorRef }}</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
@ -40,11 +44,19 @@ function getDomainFromPipeline(inputKey: string) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const targetStepId = inputKey.split(".")[1];
|
const targetStepId = inputKey.split(".")[1];
|
||||||
const certStep = findStepFromPipeline(targetStepId);
|
let certStep = findStepFromPipeline(targetStepId);
|
||||||
if (!certStep) {
|
if (!certStep) {
|
||||||
errorRef.value = "找不到目标步骤,请先选择域名证书";
|
errorRef.value = "找不到目标步骤,请先选择域名证书";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (certStep.type !== "CertApply" || certStep.type !== "CertApplyLego") {
|
||||||
|
certStep = findStepFromPipeline(certStep.input?.cert);
|
||||||
|
if (!certStep) {
|
||||||
|
errorRef.value = "找不到目标步骤,请先选择域名证书";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const domain = certStep.input["domains"];
|
const domain = certStep.input["domains"];
|
||||||
emit("update:modelValue", domain);
|
emit("update:modelValue", domain);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,8 @@
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
|
import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
|
||||||
import { ref, useAttrs, watch } from "vue";
|
import { inject, ref, useAttrs, watch } from "vue";
|
||||||
|
import { PluginDefine } from "@certd/pipeline";
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: "RemoteSelect"
|
name: "RemoteSelect"
|
||||||
|
@ -40,14 +41,40 @@ const emit = defineEmits<{
|
||||||
|
|
||||||
const attrs = useAttrs();
|
const attrs = useAttrs();
|
||||||
|
|
||||||
|
const getCurrentPluginDefine: any = inject("getCurrentPluginDefine");
|
||||||
const optionsRef = ref([]);
|
const optionsRef = ref([]);
|
||||||
const message = ref("");
|
const message = ref("");
|
||||||
const hasError = ref(false);
|
const hasError = ref(false);
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const getOptions = async () => {
|
const getOptions = async () => {
|
||||||
|
if (loading.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!getCurrentPluginDefine) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const define: PluginDefine = getCurrentPluginDefine()?.value;
|
||||||
|
if (!define) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (let key in define.input) {
|
||||||
|
const inWatches = props.watches.includes(key);
|
||||||
|
const inputDefine = define.input[key];
|
||||||
|
if (inWatches && inputDefine.required) {
|
||||||
|
const value = props.form[key];
|
||||||
|
if (value == null || value === "") {
|
||||||
|
console.log("remote-select required", key);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
message.value = "";
|
message.value = "";
|
||||||
hasError.value = false;
|
hasError.value = false;
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
optionsRef.value = [];
|
||||||
try {
|
try {
|
||||||
const res = await doRequest(
|
const res = await doRequest(
|
||||||
{
|
{
|
||||||
|
@ -67,6 +94,7 @@ const getOptions = async () => {
|
||||||
if (res && res.length > 0) {
|
if (res && res.length > 0) {
|
||||||
message.value = "获取数据成功,请从下拉框中选择";
|
message.value = "获取数据成功,请从下拉框中选择";
|
||||||
}
|
}
|
||||||
|
optionsRef.value = res;
|
||||||
return res;
|
return res;
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
@ -77,17 +105,14 @@ const filterOption = (input: string, option: any) => {
|
||||||
return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0 || String(option.value).toLowerCase().indexOf(input.toLowerCase());
|
return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0 || String(option.value).toLowerCase().indexOf(input.toLowerCase());
|
||||||
};
|
};
|
||||||
|
|
||||||
let isFirst = true;
|
|
||||||
async function onClick() {
|
async function onClick() {
|
||||||
if (!isFirst) {
|
if (optionsRef.value?.length === 0) {
|
||||||
return;
|
await refreshOptions();
|
||||||
}
|
}
|
||||||
isFirst = false;
|
|
||||||
await refreshOptions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refreshOptions() {
|
async function refreshOptions() {
|
||||||
optionsRef.value = await getOptions();
|
await getOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
@ -102,7 +127,10 @@ watch(
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
async () => {
|
async () => {
|
||||||
optionsRef.value = await getOptions();
|
await getOptions();
|
||||||
|
},
|
||||||
|
{
|
||||||
|
immediate: true
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -78,12 +78,20 @@ h1, h2, h3, h4, h5, h6 {
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
.m-2{
|
||||||
|
margin:2px
|
||||||
|
}
|
||||||
|
.m-3{
|
||||||
|
margin:3px
|
||||||
|
}
|
||||||
|
|
||||||
.mb-2 {
|
.mb-2 {
|
||||||
margin-bottom: 2px;
|
margin-bottom: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mb-5 {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
.ml-5 {
|
.ml-5 {
|
||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@
|
||||||
|
|
||||||
<script lang="tsx">
|
<script lang="tsx">
|
||||||
import { message, Modal } from "ant-design-vue";
|
import { message, Modal } from "ant-design-vue";
|
||||||
import { computed, inject, Ref, ref, watch } from "vue";
|
import { computed, inject, Ref, ref, watch, provide } from "vue";
|
||||||
import _ from "lodash-es";
|
import _ from "lodash-es";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { CopyOutlined } from "@ant-design/icons-vue";
|
import { CopyOutlined } from "@ant-design/icons-vue";
|
||||||
|
@ -219,6 +219,9 @@ export default {
|
||||||
};
|
};
|
||||||
|
|
||||||
const currentPluginDefine = ref();
|
const currentPluginDefine = ref();
|
||||||
|
provide("getCurrentPluginDefine", () => {
|
||||||
|
return currentPluginDefine;
|
||||||
|
});
|
||||||
|
|
||||||
function getContext() {
|
function getContext() {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
|
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { AliyunAccess, AliyunClient } from '@certd/plugin-plus';
|
import { AliyunAccess, AliyunClient, createCertDomainGetterInputDefine } from '@certd/plugin-plus';
|
||||||
|
import { CertInfo } from '@certd/plugin-cert';
|
||||||
|
|
||||||
@IsTaskPlugin({
|
@IsTaskPlugin({
|
||||||
name: 'DeployCertToAliyunDCDN',
|
name: 'DeployCertToAliyunDCDN',
|
||||||
title: '部署证书至阿里云DCDN',
|
title: '部署证书至阿里云DCDN',
|
||||||
|
@ -14,29 +16,19 @@ import { AliyunAccess, AliyunClient } from '@certd/plugin-plus';
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
export class DeployCertToAliyunDCDN extends AbstractTaskPlugin {
|
export class DeployCertToAliyunDCDN extends AbstractTaskPlugin {
|
||||||
@TaskInput({
|
|
||||||
title: 'DCDN加速域名',
|
|
||||||
helper: '你在阿里云上配置的CDN加速域名,比如:certd.docmirror.cn',
|
|
||||||
required: true,
|
|
||||||
})
|
|
||||||
domainName!: string;
|
|
||||||
|
|
||||||
@TaskInput({
|
|
||||||
title: '证书名称',
|
|
||||||
helper: '上传后将以此名称作为前缀备注',
|
|
||||||
})
|
|
||||||
certName!: string;
|
|
||||||
|
|
||||||
@TaskInput({
|
@TaskInput({
|
||||||
title: '域名证书',
|
title: '域名证书',
|
||||||
helper: '请选择前置任务输出的域名证书',
|
helper: '请选择前置任务输出的域名证书',
|
||||||
component: {
|
component: {
|
||||||
name: 'output-selector',
|
name: 'output-selector',
|
||||||
from: ['CertApply', 'CertApplyLego'],
|
from: ['CertApply', 'CertApplyLego', 'uploadCertToAliyun'],
|
||||||
},
|
},
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
cert!: string;
|
cert!: CertInfo | number;
|
||||||
|
|
||||||
|
@TaskInput(createCertDomainGetterInputDefine({ props: { required: false } }))
|
||||||
|
certDomains!: string[];
|
||||||
|
|
||||||
@TaskInput({
|
@TaskInput({
|
||||||
title: 'Access授权',
|
title: 'Access授权',
|
||||||
|
@ -49,6 +41,19 @@ export class DeployCertToAliyunDCDN extends AbstractTaskPlugin {
|
||||||
})
|
})
|
||||||
accessId!: string;
|
accessId!: string;
|
||||||
|
|
||||||
|
@TaskInput({
|
||||||
|
title: 'DCDN加速域名',
|
||||||
|
helper: '你在阿里云上配置的CDN加速域名,比如:certd.docmirror.cn',
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
domainName!: string;
|
||||||
|
|
||||||
|
@TaskInput({
|
||||||
|
title: '证书名称',
|
||||||
|
helper: '上传后将以此名称作为前缀备注',
|
||||||
|
})
|
||||||
|
certName!: string;
|
||||||
|
|
||||||
async onInstance() {}
|
async onInstance() {}
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
this.logger.info('开始部署证书到阿里云DCDN');
|
this.logger.info('开始部署证书到阿里云DCDN');
|
||||||
|
@ -72,6 +77,20 @@ export class DeployCertToAliyunDCDN extends AbstractTaskPlugin {
|
||||||
|
|
||||||
async buildParams() {
|
async buildParams() {
|
||||||
const CertName = (this.certName ?? 'certd') + '-' + dayjs().format('YYYYMMDDHHmmss');
|
const CertName = (this.certName ?? 'certd') + '-' + dayjs().format('YYYYMMDDHHmmss');
|
||||||
|
|
||||||
|
if (typeof this.cert !== 'object') {
|
||||||
|
const certId = this.cert;
|
||||||
|
this.logger.info('使用已上传的证书:', certId);
|
||||||
|
return {
|
||||||
|
DomainName: this.domainName,
|
||||||
|
SSLProtocol: 'on',
|
||||||
|
CertType: 'cas',
|
||||||
|
CertName: CertName,
|
||||||
|
CertId: certId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.info('上传证书:', CertName);
|
||||||
const cert: any = this.cert;
|
const cert: any = this.cert;
|
||||||
return {
|
return {
|
||||||
DomainName: this.domainName,
|
DomainName: this.domainName,
|
||||||
|
|
|
@ -1,13 +1,32 @@
|
||||||
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskOutput } from '@certd/pipeline';
|
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskOutput } from '@certd/pipeline';
|
||||||
import { appendTimeSuffix, checkRet } from '../../utils/index.js';
|
import { AliyunAccess } from '@certd/plugin-plus';
|
||||||
import { AliyunAccess, AliyunClient } from '@certd/plugin-plus';
|
import { AliyunSslClient } from '@certd/plugin-plus';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 华东1(杭州) cn-hangzhou cas.aliyuncs.com cas-vpc.cn-hangzhou.aliyuncs.com
|
||||||
|
* 马来西亚(吉隆坡) ap-southeast-3 cas.ap-southeast-3.aliyuncs.com cas-vpc.ap-southeast-3.aliyuncs.com
|
||||||
|
* 新加坡 ap-southeast-1 cas.ap-southeast-1.aliyuncs.com cas-vpc.ap-southeast-1.aliyuncs.com
|
||||||
|
* 印度尼西亚(雅加达) ap-southeast-5 cas.ap-southeast-5.aliyuncs.com cas-vpc.ap-southeast-5.aliyuncs.com
|
||||||
|
* 中国香港 cn-hongkong cas.cn-hongkong.aliyuncs.com cas-vpc.cn-hongkong.aliyuncs.com
|
||||||
|
* 欧洲与美洲
|
||||||
|
* 名称 区域 ID 服务地址 VPC 地址
|
||||||
|
* 德国(法兰克福) eu-central-1 cas.eu-central-1.aliyuncs.com
|
||||||
|
*/
|
||||||
|
const regionDict = [
|
||||||
|
{ value: 'cn-hangzhou', endpoint: 'cas.aliyuncs.com', label: 'cn-hangzhou-中国大陆' },
|
||||||
|
{ value: 'eu-central-1', endpoint: 'cas.eu-central-1.aliyuncs.com', label: 'eu-central-1-德国(法兰克福)' },
|
||||||
|
{ value: 'ap-southeast-1', endpoint: 'cas.ap-southeast-1.aliyuncs.com', label: 'ap-southeast-1-新加坡' },
|
||||||
|
{ value: 'ap-southeast-3', endpoint: 'cas.ap-southeast-3.aliyuncs.com', label: 'ap-southeast-3-马来西亚(吉隆坡)' },
|
||||||
|
{ value: 'ap-southeast-5', endpoint: 'cas.ap-southeast-5.aliyuncs.com', label: 'ap-southeast-5-印度尼西亚(雅加达)' },
|
||||||
|
{ value: 'cn-hongkong', endpoint: 'cas.cn-hongkong.aliyuncs.com', label: 'cn-hongkong-中国香港' },
|
||||||
|
];
|
||||||
|
|
||||||
@IsTaskPlugin({
|
@IsTaskPlugin({
|
||||||
name: 'uploadCertToAliyun',
|
name: 'uploadCertToAliyun',
|
||||||
title: '上传证书到阿里云',
|
title: '上传证书到阿里云',
|
||||||
icon: 'ant-design:aliyun-outlined',
|
icon: 'ant-design:aliyun-outlined',
|
||||||
group: pluginGroups.aliyun.key,
|
group: pluginGroups.aliyun.key,
|
||||||
desc: '',
|
desc: '如果不想在阿里云上同一份证书上传多次,可以把此任务作为前置任务,其他阿里云任务证书那一项选择此任务的输出',
|
||||||
default: {
|
default: {
|
||||||
strategy: {
|
strategy: {
|
||||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||||
|
@ -27,7 +46,7 @@ export class UploadCertToAliyun extends AbstractTaskPlugin {
|
||||||
component: {
|
component: {
|
||||||
name: 'a-auto-complete',
|
name: 'a-auto-complete',
|
||||||
vModel: 'value',
|
vModel: 'value',
|
||||||
options: [{ value: 'cn-hangzhou' }, { value: 'eu-central-1' }, { value: 'ap-southeast-1' }],
|
options: regionDict,
|
||||||
},
|
},
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
|
@ -65,36 +84,23 @@ export class UploadCertToAliyun extends AbstractTaskPlugin {
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
this.logger.info('开始部署证书到阿里云cdn');
|
this.logger.info('开始部署证书到阿里云cdn');
|
||||||
const access: AliyunAccess = await this.accessService.getById(this.accessId);
|
const access: AliyunAccess = await this.accessService.getById(this.accessId);
|
||||||
const client = await this.getClient(access);
|
|
||||||
const certName = appendTimeSuffix(this.name);
|
|
||||||
const params = {
|
|
||||||
RegionId: this.regionId || 'cn-hangzhou',
|
|
||||||
Name: certName,
|
|
||||||
Cert: this.cert.crt,
|
|
||||||
Key: this.cert.key,
|
|
||||||
};
|
|
||||||
|
|
||||||
const requestOption = {
|
let endpoint = '';
|
||||||
method: 'POST',
|
for (const region of regionDict) {
|
||||||
};
|
if (region.value === this.regionId) {
|
||||||
|
endpoint = region.endpoint;
|
||||||
const ret: any = await client.request('CreateUserCertificate', params, requestOption);
|
break;
|
||||||
checkRet(ret);
|
}
|
||||||
this.logger.info('证书上传成功:aliyunCertId=', ret.CertId);
|
}
|
||||||
|
const client = new AliyunSslClient({
|
||||||
//output
|
access,
|
||||||
this.aliyunCertId = ret.CertId;
|
logger: this.logger,
|
||||||
}
|
endpoint,
|
||||||
|
});
|
||||||
async getClient(aliyunProvider: AliyunAccess) {
|
this.aliyunCertId = await client.uploadCert({
|
||||||
const client = new AliyunClient({ logger: this.logger });
|
name: this.appendTimeSuffix('certd'),
|
||||||
await client.init({
|
cert: this.cert,
|
||||||
accessKeyId: aliyunProvider.accessKeyId,
|
|
||||||
accessKeySecret: aliyunProvider.accessKeySecret,
|
|
||||||
endpoint: 'https://cas.aliyuncs.com',
|
|
||||||
apiVersion: '2020-04-07',
|
|
||||||
});
|
});
|
||||||
return client;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//注册插件
|
//注册插件
|
||||||
|
|
Loading…
Reference in New Issue