perf: 小优化

master
xiaojunnuo 2021-01-14 23:04:47 +08:00
parent 466f2b1a02
commit 8b0ca1da2e
18 changed files with 640 additions and 222 deletions

View File

@ -6,10 +6,9 @@
"lerna": "^3.18.4"
},
"scripts": {
"submodule": "git submodule update --init --recursive"
},
"license": "MIT",
"dependencies": {
"lodash": "^4.17.20"
"lodash-es": "^4.17.20"
}
}

View File

@ -1,28 +1,25 @@
{
"name": "@certd/api",
"version": "0.1.7",
"description": "",
"main": "./src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"type": "module",
"author": "Greper",
"license": "MIT",
"dependencies": {
"axios": "^0.21.1",
"dayjs": "^1.9.7",
"lodash-es": "^4.17.20",
"log4js": "^6.3.0",
"qs": "^6.9.4"
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^7.15.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"mocha": "^8.2.1"
}
"name": "@certd/api",
"version": "0.1.7",
"description": "",
"main": "./src/index.js",
"type": "module",
"author": "Greper",
"license": "MIT",
"dependencies": {
"axios": "^0.21.1",
"dayjs": "^1.9.7",
"lodash-es": "^4.17.20",
"log4js": "^6.3.0",
"qs": "^6.9.4"
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^7.15.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"mocha": "^8.2.1"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -2,11 +2,26 @@ import { util, Store } from '@certd/api'
import { AcmeService } from './acme.js'
import { FileStore } from './store/file-store.js'
import { CertStore } from './store/cert-store.js'
import { DnsProviderFactory } from '@certd/providers'
import dayjs from 'dayjs'
import forge from 'node-forge'
import DefaultProviders from '@certd/providers'
import _ from 'lodash-es'
const logger = util.logger
const AccessProviderClasses = {}
function install (providerClass) {
AccessProviderClasses[providerClass.name()] = providerClass
}
logger.info('use')
_.forEach(DefaultProviders, item => {
logger.info('use:', item.name())
install(item)
})
export class Certd {
static use (providerClass) {
install(providerClass)
}
constructor (options) {
this.options = options
this.email = options.cert.email
@ -74,7 +89,7 @@ export class Certd {
createDnsProvider (options) {
const accessProviders = options.accessProviders
const providerOptions = accessProviders[options.cert.dnsProvider]
return DnsProviderFactory.createByType(providerOptions.providerType, providerOptions)
return this.createProviderByType(providerOptions.providerType, providerOptions)
}
async writeCert (cert) {
@ -121,4 +136,13 @@ export class Certd {
leftDays
}
}
createProviderByType (type, options) {
try {
const Provider = AccessProviderClasses[type]
return new Provider(options)
} catch (e) {
throw new Error('暂不支持此dnsProvider,请先use该provider' + type, e)
}
}
}

View File

@ -2873,9 +2873,9 @@
"integrity": "sha1-tYsBCsQMIsVldhbI0sLALHv0eew="
},
"qs": {
"version": "6.9.4",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.9.4.tgz",
"integrity": "sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ=="
"version": "6.9.6",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.9.6.tgz",
"integrity": "sha512-TIRk4aqYLNoJUbd+g2lEdz5kLWIuTMRagAXxl78Q0RiVjAOugHmeKNGdd3cwo/ktpf9aL9epCfFqWDEKysUlLQ=="
},
"randombytes": {
"version": "2.1.0",
@ -3444,9 +3444,9 @@
}
},
"tencentcloud-sdk-nodejs": {
"version": "4.0.46",
"resolved": "https://registry.npmjs.org/tencentcloud-sdk-nodejs/-/tencentcloud-sdk-nodejs-4.0.46.tgz",
"integrity": "sha512-EP6K2da9yJsKWQcaMJ2dV2WyuwassBckUeLflGQZITKBz3kF92TkNdE1A1JzO74MAdzA2PhIuvaDXxxYAAaThA==",
"version": "4.0.49",
"resolved": "https://registry.npmjs.org/tencentcloud-sdk-nodejs/-/tencentcloud-sdk-nodejs-4.0.49.tgz",
"integrity": "sha512-4mZIwIup5oTtmlXtyyqGIUdpurLFdU25ZLcgjElcKOep8HYnMKVXNCvV57WXEMJx+UBc+wYg21OBQd6neUSkxg==",
"requires": {
"babel-eslint": "^10.0.2",
"eslint-plugin-react": "^7.17.0",

View File

@ -22,7 +22,19 @@ export class Executor {
this.trace = new Trace()
}
use (plugin) {
useProviders (providers) {
if (providers) {
_.forEach(item => {
Certd.use(item)
})
}
}
useProvider (provider) {
Certd.use(provider)
}
usePlugin (plugin) {
if (plugin == null) {
return
}
@ -38,9 +50,9 @@ export class Executor {
usePlugins (plugins) {
if (plugins) {
for (const plugin of plugins) {
this.use(plugin)
}
_.forEach(plugins, item => {
this.usePlugin(item)
})
}
}
@ -58,7 +70,7 @@ export class Executor {
async doRun (options) {
// 申请证书
logger.info('任务开始')
const certd = new Certd(options)
const certd = new Certd(options, this.providers)
const cert = await this.runCertd(certd)
if (cert == null) {
throw new Error('申请证书失败')

View File

@ -16,7 +16,10 @@ describe('AutoDeploy', function () {
this.timeout(120000)
const executor = new Executor()
const options = createOptions()
const ret = await executor.run(options, { forceCert: true, forceDeploy: false })
options.args.forceCert = true
options.args.forceDeploy = true
const ret = await executor.run(options)
expect(ret).ok
expect(ret.cert).ok
})

View File

@ -131,34 +131,6 @@
"to-fast-properties": "^2.0.0"
}
},
"@certd/acme-client": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/@certd/acme-client/-/acme-client-0.1.6.tgz",
"integrity": "sha512-XffzB/QHRj61gUHXor1B8R2TVt7HnklJpjAbwQi8vHjBGloU8I3occJxIunoh1AShhc4wsxnc+h/D5yRIUp17A==",
"requires": {
"axios": "0.21.1",
"backo2": "^1.0.0",
"bluebird": "^3.5.0",
"debug": "^4.1.1",
"log4js": "^6.3.0",
"node-forge": "^0.10.0"
},
"dependencies": {
"debug": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
"integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
"requires": {
"ms": "2.1.2"
}
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
}
}
},
"@certd/api": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/@certd/api/-/api-0.1.7.tgz",
@ -171,30 +143,6 @@
"qs": "^6.9.4"
}
},
"@certd/certd": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/@certd/certd/-/certd-0.1.7.tgz",
"integrity": "sha512-h+YWlcXzdQk3dbhK7u0guwyzotKRtsIA9zTaHdViWlMDlT9/oO9QflFoo8x8wA1Xx/Vd90APT6EEBnizgOXxsQ==",
"requires": {
"@certd/acme-client": "^0.1.6",
"@certd/api": "^0.1.7",
"@certd/providers": "^0.1.7",
"dayjs": "^1.9.7",
"lodash-es": "^4.17.20",
"node-forge": "^0.10.0"
}
},
"@certd/providers": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/@certd/providers/-/providers-0.1.7.tgz",
"integrity": "sha512-ACiFNhRBVWB5Nyui3RTuAX0oTVkuWi0zopO1qMzbA/2iOrtFAoNs3I5DSLpZxS3d1erKcOq+Lx7Rm0rZxiL6wg==",
"requires": {
"@alicloud/pop-core": "^1.7.10",
"@certd/api": "^0.1.7",
"lodash-es": "^4.17.20",
"tencentcloud-sdk-nodejs": "^4.0.44"
}
},
"@eslint/eslintrc": {
"version": "0.2.2",
"resolved": "https://registry.npm.taobao.org/@eslint/eslintrc/download/@eslint/eslintrc-0.2.2.tgz?cache=0&sync_timestamp=1607145629875&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40eslint%2Feslintrc%2Fdownload%2F%40eslint%2Feslintrc-0.2.2.tgz",
@ -561,11 +509,6 @@
"resolve": "^1.12.0"
}
},
"backo2": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz",
"integrity": "sha1-MasayLEpNjRj41s+u2n038+6eUc="
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npm.taobao.org/balanced-match/download/balanced-match-1.0.0.tgz",
@ -595,11 +538,6 @@
"integrity": "sha1-MPpAyef+B9vIlWeM0ocCTeokHdk=",
"dev": true
},
"bluebird": {
"version": "3.7.2",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz",
"integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg=="
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npm.taobao.org/brace-expansion/download/brace-expansion-1.1.11.tgz?cache=0&sync_timestamp=1601898189928&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbrace-expansion%2Fdownload%2Fbrace-expansion-1.1.11.tgz",
@ -2428,11 +2366,6 @@
"resolved": "https://registry.npm.taobao.org/node-fetch/download/node-fetch-2.6.1.tgz?cache=0&sync_timestamp=1599309179354&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fnode-fetch%2Fdownload%2Fnode-fetch-2.6.1.tgz",
"integrity": "sha1-BFvTI2Mfdu0uK1VXM5RBa2OaAFI="
},
"node-forge": {
"version": "0.10.0",
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.10.0.tgz",
"integrity": "sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA=="
},
"normalize-package-data": {
"version": "2.5.0",
"resolved": "https://registry.npm.taobao.org/normalize-package-data/download/normalize-package-data-2.5.0.tgz?cache=0&sync_timestamp=1602547447569&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fnormalize-package-data%2Fdownload%2Fnormalize-package-data-2.5.0.tgz",

View File

@ -1,31 +1,27 @@
{
"name": "@certd/plugins",
"version": "0.1.9",
"description": "",
"main": "./src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"type": "module",
"dependencies": {
"@alicloud/pop-core": "^1.7.10",
"@certd/api": "^0.1.7",
"@certd/certd": "^0.1.7",
"dayjs": "^1.9.7",
"kubernetes-client": "^9.0.0",
"lodash-es": "^4.17.20",
"ssh2": "^0.8.9",
"tencentcloud-sdk-nodejs": "^4.0.44"
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^7.15.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"mocha": "^8.2.1"
},
"author": "Greper",
"license": "MIT"
"name": "@certd/plugins",
"version": "0.1.9",
"description": "",
"main": "./src/index.js",
"type": "module",
"dependencies": {
"@alicloud/pop-core": "^1.7.10",
"dayjs": "^1.9.7",
"kubernetes-client": "^9.0.0",
"lodash-es": "^4.17.20",
"ssh2": "^0.8.9",
"tencentcloud-sdk-nodejs": "^4.0.44",
"@certd/api": "^0.1.7"
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^7.15.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"mocha": "^8.2.1"
},
"author": "Greper",
"license": "MIT"
}

View File

@ -9,11 +9,11 @@ import { DeployCertToTencentCLB } from './tencent/deploy-to-clb/index.js'
import { DeployCertToTencentTKEIngress } from './tencent/deploy-to-tke-ingress/index.js'
export default [
export default {
UploadCertToAliyun,
DeployCertToAliyunCDN,
UploadCertToTencent,
DeployCertToTencentTKEIngress,
DeployCertToTencentCDN,
DeployCertToTencentCLB
]
}

View File

@ -85,7 +85,9 @@ export class AliyunDnsProvider extends AbstractDnsProvider {
this.logger.info('添加域名解析成功:', value, value, ret.RecordId)
return ret.RecordId
} catch (e) {
// e.code === 'DomainRecordDuplicate'
if (e.code === 'DomainRecordDuplicate') {
return
}
this.logger.info('添加域名解析出错', e)
throw e
}

View File

@ -1,12 +0,0 @@
import dnsProviders from './index.js'
export class DnsProviderFactory {
static createByType (type, options) {
try {
const Provider = dnsProviders[type]
return new Provider(options)
} catch (e) {
throw new Error('暂不支持此dnsProvider' + type, e)
}
}
}

View File

@ -1,6 +0,0 @@
import { AliyunDnsProvider } from './impl/aliyun.js'
import { DnspodDnsProvider } from './impl/dnspod.js'
export default {
[AliyunDnsProvider.name()]: AliyunDnsProvider,
[DnspodDnsProvider.name()]: DnspodDnsProvider
}

View File

@ -1,4 +1,7 @@
import dnsProviders from './dns-provider/index.js'
export { DnsProviderFactory } from './dns-provider/dns-provider-factory.js'
import { AliyunDnsProvider } from './dns-provider/aliyun.js'
import { DnspodDnsProvider } from './dns-provider/dnspod.js'
export default dnsProviders
export default {
AliyunDnsProvider,
DnspodDnsProvider
}

View File

@ -1,7 +1,6 @@
import pkg from 'chai'
import AliyunDnsProvider from '../../src/dns-provider/impl/aliyun.js'
import AliyunDnsProvider from '../../src/dns-provider/aliyun.js'
import { createOptions } from '../../../../test/options.js'
import { Certd } from '../../src/index.js'
const { expect } = pkg
describe('AliyunDnsProvider', function () {
it('#getDomainList', async function () {

View File

@ -1,5 +1,5 @@
import pkg from 'chai'
import DnspodDnsProvider from '../../src/dns-provider/impl/dnspod.js'
import DnspodDnsProvider from '../../src/dns-provider/dnspod.js'
import { Certd } from '../../src/index.js'
import { createOptions } from '../../../../test/options.js'
const { expect } = pkg

View File

@ -1,11 +1,11 @@
import _ from 'lodash'
import _ from 'lodash-es'
import optionsPrivate from './options.private.js'
const defaultOptions = {
args: {
forceCert: false, // 强制更新证书
skipCert: false, // 是否跳过证书申请环节
forceDeploy: true,
test: true
test: false
},
accessProviders: {
aliyun: {