mirror of
https://github.com/certd/certd.git
synced 2025-11-25 09:10:11 +08:00
perf: 抽取api
This commit is contained in:
@@ -11,10 +11,8 @@
|
||||
"@alicloud/pop-core": "^1.7.10",
|
||||
"@certd/certd": "^0.1.1",
|
||||
"@types/node": "^14.14.13",
|
||||
"dayjs": "^1.9.7",
|
||||
"kubernetes-client": "^9.0.0",
|
||||
"lodash": "^4.17.20",
|
||||
"log4js": "^6.3.0",
|
||||
"lodash-es": "^4.17.20",
|
||||
"ssh2": "^0.8.9",
|
||||
"tencentcloud-sdk-nodejs": "^4.0.44"
|
||||
},
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
import fs from 'fs'
|
||||
import logger from '../utils/util.log.js'
|
||||
import dayjs from 'dayjs'
|
||||
import Sleep from '../utils/util.sleep.js'
|
||||
export class AbstractPlugin {
|
||||
constructor ({ accessProviders }) {
|
||||
this.logger = logger
|
||||
this.accessProviders = accessProviders
|
||||
}
|
||||
|
||||
appendTimeSuffix (name) {
|
||||
if (name == null) {
|
||||
name = 'certd'
|
||||
}
|
||||
return name + '-' + dayjs().format('YYYYMMDD-HHmmss')
|
||||
}
|
||||
|
||||
async executeFromContextFile (options = {}) {
|
||||
const { contextPath } = options
|
||||
const contextJson = fs.readFileSync(contextPath)
|
||||
const context = JSON.parse(contextJson)
|
||||
options.context = context
|
||||
await this.doExecute(options)
|
||||
fs.writeFileSync(JSON.stringify(context))
|
||||
}
|
||||
|
||||
async doExecute (options) {
|
||||
try {
|
||||
return await this.execute(options)
|
||||
} catch (e) {
|
||||
logger.error('插件执行出错:', e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行
|
||||
* @param options
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async execute (options) {
|
||||
console.error('请实现此方法,context:', options.context)
|
||||
}
|
||||
|
||||
async doRollback (options) {
|
||||
try {
|
||||
return await this.rollback(options)
|
||||
} catch (e) {
|
||||
logger.error('插件rollback出错:', e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 回退,如有必要
|
||||
* @param options
|
||||
*/
|
||||
async rollback (options) {
|
||||
console.error('请实现此方法,rollback:', options.context)
|
||||
}
|
||||
|
||||
getAccessProvider (accessProvider, accessProviders = this.accessProviders) {
|
||||
if (typeof accessProvider === 'string' && accessProviders) {
|
||||
accessProvider = accessProviders[accessProvider]
|
||||
}
|
||||
return accessProvider
|
||||
}
|
||||
|
||||
async sleep (time) {
|
||||
await Sleep(time)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AbstractPlugin } from '../abstract-plugin/index.js'
|
||||
import { AbstractPlugin } from '@certd/api'
|
||||
|
||||
export class AbstractAliyunPlugin extends AbstractPlugin {
|
||||
checkRet (ret) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AbstractPlugin } from '../abstract-plugin/index.js'
|
||||
import { AbstractPlugin } from '@certd/api'
|
||||
|
||||
export class AbstractHostPlugin extends AbstractPlugin {
|
||||
checkRet (ret) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AbstractPlugin } from '../abstract-plugin/index.js'
|
||||
import { AbstractPlugin } from '@certd/api'
|
||||
|
||||
export class AbstractTencentPlugin extends AbstractPlugin {
|
||||
checkRet (ret) {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import kubernetesClient from 'kubernetes-client'
|
||||
import logger from './util.log.js'
|
||||
import { util } from '@certd/api0'
|
||||
import Request from 'kubernetes-client/backends/request/index.js'
|
||||
const { KubeConfig, Client } = kubernetesClient
|
||||
const logger = util.logger
|
||||
export class K8sClient {
|
||||
constructor (kubeConfigStr) {
|
||||
const kubeconfig = new KubeConfig()
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import log4js from 'log4js'
|
||||
log4js.configure({
|
||||
appenders: { std: { type: 'stdout' } },
|
||||
categories: { default: { appenders: ['std'], level: 'info' } }
|
||||
})
|
||||
const logger = log4js.getLogger('certd')
|
||||
export default logger
|
||||
@@ -1,7 +0,0 @@
|
||||
export default function (timeout) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve()
|
||||
}, timeout)
|
||||
})
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import _ from 'lodash'
|
||||
import _ from 'lodash-es'
|
||||
import optionsPrivate from '../../../test/options.private.mjs'
|
||||
const defaultOptions = {
|
||||
version: '1.0.0',
|
||||
|
||||
Reference in New Issue
Block a user