mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
feat: deployFlow
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user