Compare commits

..

5 Commits

Author SHA1 Message Date
xiaojunnuo
d1a74713ef v0.1.9 2021-01-08 15:49:48 +08:00
xiaojunnuo
813e9e71d7 refactor: 1 2021-01-08 15:49:16 +08:00
xiaojunnuo
3d08dce26e refactor: 1 2021-01-08 15:46:37 +08:00
xiaojunnuo
4739d75f4a refactor: 1 2021-01-08 15:45:31 +08:00
xiaojunnuo
30cd62664b refactor: 1 2021-01-08 15:39:23 +08:00
11 changed files with 46 additions and 27 deletions

View File

@@ -2,5 +2,5 @@
"packages": [
"packages/*"
],
"version": "0.1.8"
"version": "0.1.9"
}

View File

@@ -1,6 +1,6 @@
{
"name": "@certd/executor",
"version": "0.1.8",
"version": "0.1.9",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "@certd/executor",
"version": "0.1.8",
"version": "0.1.9",
"description": "",
"main": "src/index.js",
"scripts": {
@@ -12,7 +12,7 @@
"dependencies": {
"@certd/api": "^0.1.7",
"@certd/certd": "^0.1.7",
"@certd/plugins": "^0.1.8",
"@certd/plugins": "^0.1.9",
"dayjs": "^1.9.7",
"lodash-es": "^4.17.20"
},

View File

@@ -5,12 +5,19 @@ import _ from 'lodash-es'
import dayjs from 'dayjs'
import { Trace } from './trace.js'
const logger = util.logger
function createDefaultOptions () {
return {
args: {
forceCert: false,
forceDeploy: true,
forceRedeploy: false
}
}
}
export class Executor {
constructor (args = {}) {
const { plugins } = args
this.plugins = {}
constructor () {
this.usePlugins(DefaultPlugins)
this.usePlugins(plugins)
this.trace = new Trace()
}
@@ -33,12 +40,10 @@ export class Executor {
}
}
async run (options, args) {
async run (options) {
logger.info('------------------- Cert-D ---------------------')
try {
if (args != null) {
_.merge(options.args, args)
}
options = _.merge(createDefaultOptions(), options)
return await this.doRun(options)
} catch (e) {
logger.error('任务执行出错:', e)
@@ -67,14 +72,14 @@ export class Executor {
}
}
// 读取上次执行进度
let context = {
certIsNew: !!cert.isNew
}
let context = {}
const contextJson = await certd.certStore.getCurrentFile('context.json')
if (contextJson) {
context = JSON.parse(contextJson)
}
context.certIsNew = !!cert.isNew
const trace = new Trace(context)
// 运行部署任务
try {
@@ -85,10 +90,17 @@ export class Executor {
logger.info('任务完成')
trace.print()
return {
const result = trace.get({ })
const returnData = {
cert,
context
context,
result
}
if (result.status === 'error') {
const err = new Error(result.remark)
err.data = returnData
}
return returnData
}
async runCertd (certd) {
@@ -125,6 +137,7 @@ export class Executor {
trace.set({ deployName, value: { status: 'success', remark: '执行成功' } })
} catch (e) {
trace.set({ deployName, value: { status: 'error', remark: '执行失败:' + e.message } })
trace.set({ value: { status: 'error', remark: deployName + '执行失败:' + e.message } })
logger.error('流程执行失败', e)
}

View File

@@ -41,10 +41,10 @@ export class Trace {
print () {
const context = this.context
logger.info('---------------------------任务结果总览--------------------------')
if (!context.certIsNew) {
this.printTraceLine({ current: 'skip', remark: '还未到过期时间,跳过' }, '更新证书')
} else {
if (context.certIsNew) {
this.printTraceLine({ current: 'success', remark: '证书更新成功' }, '更新证书')
} else {
this.printTraceLine({ current: 'skip', remark: '还未到过期时间,跳过' }, '更新证书')
}
const trace = this.get({ })
// logger.info('trace', trace)
@@ -64,6 +64,11 @@ export class Trace {
}
}
}
const mainContext = {}
_.merge(mainContext, context)
delete mainContext.__trace__
logger.info('context:', JSON.stringify(mainContext))
}
printTraceLine (traceStatus, name, prefix = '') {

View File

@@ -1,6 +1,6 @@
{
"name": "@certd/plugins",
"version": "0.1.8",
"version": "0.1.9",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "@certd/plugins",
"version": "0.1.8",
"version": "0.1.9",
"description": "",
"main": "./src/index.js",
"scripts": {

View File

@@ -52,14 +52,14 @@ export class DeployCertToTencentCDN extends AbstractTencentPlugin {
}
}
async execute ({ cert, props, context }) {
async execute ({ cert, props, context }) {
const accessProvider = this.getAccessProvider(props.accessProvider)
const client = this.getClient(accessProvider)
const params = this.buildParams(props, context, cert)
await this.doRequest(client, params)
}
async rollback ({ cert, props, context }) {
async rollback ({ cert, props, context }) {
}
@@ -85,7 +85,7 @@ export class DeployCertToTencentCDN extends AbstractTencentPlugin {
buildParams (props, context, cert) {
const { domainName, from } = props
const { tencentCertId } = context
this.logger.info('部署腾讯云证书ID:', tencentCertId)
const params = {
Https: {
Switch: 'on',

View File

@@ -128,7 +128,7 @@ export class DeployCertToTencentCLB extends AbstractTencentPlugin {
buildProps (props, context, cert) {
const { certName } = props
const { tencentCertId } = context
this.logger.info('部署腾讯云证书ID:', tencentCertId)
const params = {
Certificate: {
SSLMode: 'UNIDIRECTIONAL', // 单向认证

View File

@@ -123,6 +123,7 @@ export class DeployCertToTencentTKEIngress extends AbstractTencentPlugin {
if (tencentCertId == null) {
throw new Error('请先将【上传证书到腾讯云】作为前置任务')
}
this.logger.info('腾讯云证书ID:', tencentCertId)
const certIdBase64 = Buffer.from(tencentCertId).toString('base64')
const { namespace, secretName } = props

View File

@@ -54,7 +54,7 @@ export class UploadCertToTencent extends AbstractTencentPlugin {
async execute ({ cert, props, context, logger }) {
const { name, accessProvider } = props
const certName = this.appendTimeSuffix(name)
const certName = this.appendTimeSuffix(name || cert.domain)
const provider = this.getAccessProvider(accessProvider)
const client = this.getClient(provider)