mirror of https://github.com/certd/certd
refactor: fix
parent
b9d5d33aaa
commit
6eb9817296
|
@ -1,6 +1,6 @@
|
||||||
export class Registry {
|
export class Registry {
|
||||||
constructor () {
|
constructor () {
|
||||||
this.collection = {}
|
this.collection = new Map()
|
||||||
}
|
}
|
||||||
|
|
||||||
install (target) {
|
install (target) {
|
||||||
|
@ -8,7 +8,7 @@ export class Registry {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this.collection == null) {
|
if (this.collection == null) {
|
||||||
this.collection = {}
|
this.collection = new Map()
|
||||||
}
|
}
|
||||||
let defineName = target.define ? target.define().name : null
|
let defineName = target.define ? target.define().name : null
|
||||||
if (defineName == null) {
|
if (defineName == null) {
|
||||||
|
@ -22,14 +22,18 @@ export class Registry {
|
||||||
if (!key || value == null) {
|
if (!key || value == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.collection[key] = value
|
this.collection.set(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
get (name) {
|
get (name) {
|
||||||
if (name) {
|
if (name) {
|
||||||
return this.collection[name]
|
return this.collection.get(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(`${name} not found`)
|
throw new Error(`${name} not found`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCollection () {
|
||||||
|
return this.collection
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { CertStore } from './store/cert-store.js'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import forge from 'node-forge'
|
import forge from 'node-forge'
|
||||||
import DefaultDnsProviders from '@certd/dns-providers'
|
import DefaultDnsProviders from '@certd/dns-providers'
|
||||||
|
|
||||||
const logger = util.logger
|
const logger = util.logger
|
||||||
|
|
||||||
DefaultDnsProviders.install()
|
DefaultDnsProviders.install()
|
||||||
|
@ -125,11 +126,10 @@ export class Certd {
|
||||||
|
|
||||||
createProviderByType (props, accessProviders) {
|
createProviderByType (props, accessProviders) {
|
||||||
const { type } = props
|
const { type } = props
|
||||||
try {
|
|
||||||
const Provider = dnsProviderRegistry.get(type)
|
const Provider = dnsProviderRegistry.get(type)
|
||||||
return new Provider({ accessProviders, props })
|
if (Provider == null) {
|
||||||
} catch (e) {
|
throw new Error('暂不支持此dnsProvider,请先注册该provider:' + type)
|
||||||
throw new Error('暂不支持此dnsProvider,请先注册该provider:' + type, e)
|
|
||||||
}
|
}
|
||||||
|
return new Provider({ accessProviders, props })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -28,6 +28,7 @@ export class Executor {
|
||||||
async run (options) {
|
async run (options) {
|
||||||
logger.info('------------------- Cert-D ---------------------')
|
logger.info('------------------- Cert-D ---------------------')
|
||||||
try {
|
try {
|
||||||
|
this.transferToSafetyOptions(options)
|
||||||
options = _.merge(createDefaultOptions(), options)
|
options = _.merge(createDefaultOptions(), options)
|
||||||
return await this.doRun(options)
|
return await this.doRun(options)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -1,7 +1,22 @@
|
||||||
import { request } from './service'
|
import { request } from './service'
|
||||||
|
import _ from 'lodash-es'
|
||||||
|
function arrayToMap (arr) {
|
||||||
|
if (arr && arr instanceof Array) {
|
||||||
|
const map = {}
|
||||||
|
_.forEach(arr, item => {
|
||||||
|
map[item.key] = item
|
||||||
|
})
|
||||||
|
return map
|
||||||
|
}
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
|
||||||
|
function transfer (options) {
|
||||||
|
options.accessProviders = arrayToMap(options.accessProviders)
|
||||||
|
}
|
||||||
export default {
|
export default {
|
||||||
exportsToZip (options) {
|
exportsToZip (options) {
|
||||||
|
transfer(options)
|
||||||
return request({
|
return request({
|
||||||
url: '/exports/toZip',
|
url: '/exports/toZip',
|
||||||
data: { options },
|
data: { options },
|
||||||
|
|
Loading…
Reference in New Issue