feat: deployFlow

This commit is contained in:
xiaojunnuo
2020-12-16 00:35:05 +08:00
parent a4bd29e6bf
commit 06603759fd
23 changed files with 6397 additions and 9 deletions
@@ -0,0 +1,17 @@
import fs from 'fs'
export class AbstractPlugin {
async executeFromContextFile (options = {}) {
const { contextPath } = options
const contextJson = fs.readFileSync(contextPath)
const context = JSON.parse(contextJson)
const newContext = await this.execute(options, context)
fs.writeFileSync(JSON.stringify(newContext || context))
}
async execute (options, context) {
console.log('请实现此方法,context:', context)
return context
}
}
+4
View File
@@ -0,0 +1,4 @@
import { UploadCertToAliyun } from './upload/upload-cert-to-aliyun/index.js'
export default {
UploadCertToAliyun
}
@@ -0,0 +1,33 @@
import { AbstractPlugin } from '../../abstract-plugin/index.js'
import Core from '@alicloud/pop-core'
import dayjs from 'dayjs'
export class UploadCertToAliyunPlugin extends AbstractPlugin {
getClient (aliyunProvider) {
this.client = new Core({
accessKeyId: aliyunProvider.accessKeyId,
accessKeySecret: aliyunProvider.accessKeySecret,
endpoint: 'https://alidns.aliyuncs.com',
apiVersion: '2015-01-09'
})
}
async execute ({ providers, cert, args, context }) {
const { name, provider } = args
const certName = name + '-' + dayjs().format('YYYYMMDDHHmmss')
const params = {
RegionId: 'cn-hangzhou',
Name: certName,
Cert: cert.crt.toString(),
Key: cert.key.toString()
}
const requestOption = {
method: 'POST'
}
const client = this.getClient(providers[provider])
const ret = await client.request('CreateUserCertificate', params, requestOption)
context.AliyunCertId = ret.CertId
}
}
+11
View File
@@ -0,0 +1,11 @@
import util from './util.js'
import log4js from 'log4js'
import path from 'path'
const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info'
const filename = path.join(util.getUserBasePath(), '/logs/certd.log')
log4js.configure({
appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename } },
categories: { default: { appenders: ['file', 'std'], level: level } }
})
const logger = log4js.getLogger('certd')
export default logger