mirror of https://github.com/certd/certd
refactor: 1
parent
ae6b0fb111
commit
30cd62664b
|
@ -5,12 +5,19 @@ import _ from 'lodash-es'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { Trace } from './trace.js'
|
import { Trace } from './trace.js'
|
||||||
const logger = util.logger
|
const logger = util.logger
|
||||||
|
|
||||||
|
function createDefaultOptions () {
|
||||||
|
return {
|
||||||
|
args: {
|
||||||
|
forceCert: false,
|
||||||
|
forceDeploy: true,
|
||||||
|
forceRedeploy: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
export class Executor {
|
export class Executor {
|
||||||
constructor (args = {}) {
|
constructor () {
|
||||||
const { plugins } = args
|
|
||||||
this.plugins = {}
|
|
||||||
this.usePlugins(DefaultPlugins)
|
this.usePlugins(DefaultPlugins)
|
||||||
this.usePlugins(plugins)
|
|
||||||
this.trace = new Trace()
|
this.trace = new Trace()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,12 +40,10 @@ export class Executor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async run (options, args) {
|
async run (options) {
|
||||||
logger.info('------------------- Cert-D ---------------------')
|
logger.info('------------------- Cert-D ---------------------')
|
||||||
try {
|
try {
|
||||||
if (args != null) {
|
options = _.merge(createDefaultOptions(), options)
|
||||||
_.merge(options.args, args)
|
|
||||||
}
|
|
||||||
return await this.doRun(options)
|
return await this.doRun(options)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error('任务执行出错:', e)
|
logger.error('任务执行出错:', e)
|
||||||
|
@ -67,14 +72,14 @@ export class Executor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 读取上次执行进度
|
// 读取上次执行进度
|
||||||
let context = {
|
let context = {}
|
||||||
certIsNew: !!cert.isNew
|
|
||||||
}
|
|
||||||
const contextJson = await certd.certStore.getCurrentFile('context.json')
|
const contextJson = await certd.certStore.getCurrentFile('context.json')
|
||||||
if (contextJson) {
|
if (contextJson) {
|
||||||
context = JSON.parse(contextJson)
|
context = JSON.parse(contextJson)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.certIsNew = !!cert.isNew
|
||||||
|
|
||||||
const trace = new Trace(context)
|
const trace = new Trace(context)
|
||||||
// 运行部署任务
|
// 运行部署任务
|
||||||
try {
|
try {
|
||||||
|
@ -85,10 +90,17 @@ export class Executor {
|
||||||
|
|
||||||
logger.info('任务完成')
|
logger.info('任务完成')
|
||||||
trace.print()
|
trace.print()
|
||||||
return {
|
const result = trace.get({ })
|
||||||
|
const returnData = {
|
||||||
cert,
|
cert,
|
||||||
context
|
context,
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
if (result.status === 'error') {
|
||||||
|
const err = new Error(result.remark)
|
||||||
|
err.data = returnData
|
||||||
|
}
|
||||||
|
return returnData
|
||||||
}
|
}
|
||||||
|
|
||||||
async runCertd (certd) {
|
async runCertd (certd) {
|
||||||
|
@ -125,6 +137,7 @@ export class Executor {
|
||||||
trace.set({ deployName, value: { status: 'success', remark: '执行成功' } })
|
trace.set({ deployName, value: { status: 'success', remark: '执行成功' } })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
trace.set({ deployName, value: { status: 'error', remark: '执行失败:' + e.message } })
|
trace.set({ deployName, value: { status: 'error', remark: '执行失败:' + e.message } })
|
||||||
|
trace.set({ value: { status: 'error', remark: deployName + '执行失败:' + e.message } })
|
||||||
logger.error('流程执行失败', e)
|
logger.error('流程执行失败', e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,10 +41,10 @@ export class Trace {
|
||||||
print () {
|
print () {
|
||||||
const context = this.context
|
const context = this.context
|
||||||
logger.info('---------------------------任务结果总览--------------------------')
|
logger.info('---------------------------任务结果总览--------------------------')
|
||||||
if (!context.certIsNew) {
|
if (context.certIsNew) {
|
||||||
this.printTraceLine({ current: 'skip', remark: '还未到过期时间,跳过' }, '更新证书')
|
|
||||||
} else {
|
|
||||||
this.printTraceLine({ current: 'success', remark: '证书更新成功' }, '更新证书')
|
this.printTraceLine({ current: 'success', remark: '证书更新成功' }, '更新证书')
|
||||||
|
} else {
|
||||||
|
this.printTraceLine({ current: 'skip', remark: '还未到过期时间,跳过' }, '更新证书')
|
||||||
}
|
}
|
||||||
const trace = this.get({ })
|
const trace = this.get({ })
|
||||||
// logger.info('trace', trace)
|
// logger.info('trace', trace)
|
||||||
|
|
|
@ -54,7 +54,7 @@ export class UploadCertToTencent extends AbstractTencentPlugin {
|
||||||
|
|
||||||
async execute ({ cert, props, context, logger }) {
|
async execute ({ cert, props, context, logger }) {
|
||||||
const { name, accessProvider } = props
|
const { name, accessProvider } = props
|
||||||
const certName = this.appendTimeSuffix(name)
|
const certName = this.appendTimeSuffix(name || cert.domain)
|
||||||
|
|
||||||
const provider = this.getAccessProvider(accessProvider)
|
const provider = this.getAccessProvider(accessProvider)
|
||||||
const client = this.getClient(provider)
|
const client = this.getClient(provider)
|
||||||
|
|
Loading…
Reference in New Issue