mirror of https://github.com/certd/certd
				
				
				
			refactor: 重构
							parent
							
								
									82f86d9556
								
							
						
					
					
						commit
						cb8c8186f1
					
				| 
						 | 
				
			
			@ -7,7 +7,7 @@
 | 
			
		|||
  },
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "start": "lerna bootstrap --hoist",
 | 
			
		||||
    "i-all": "lerna exec npm install && lerna link "
 | 
			
		||||
    "i-all": "lerna link && lerna exec npm install  "
 | 
			
		||||
  },
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
export * from './dns-provider'
 | 
			
		||||
export * from './plugin'
 | 
			
		||||
export * from './access-provider'
 | 
			
		||||
export * from './dns-provider/index.js'
 | 
			
		||||
export * from './plugin/index.js'
 | 
			
		||||
export * from './access-provider/index.js'
 | 
			
		||||
export { Store } from './store/store.js'
 | 
			
		||||
export { util } from './utils'
 | 
			
		||||
export { util } from './utils/index.js'
 | 
			
		||||
// module.createRequireFromPath()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,7 +4,11 @@ import dayjs from 'dayjs'
 | 
			
		|||
import Sleep from '../utils/util.sleep.js'
 | 
			
		||||
 | 
			
		||||
export class AbstractPlugin {
 | 
			
		||||
  constructor ({ accessProviders }) {
 | 
			
		||||
  constructor (options) {
 | 
			
		||||
    if (options == null) {
 | 
			
		||||
      throw new Error('插件安装失败:参数不允许为空')
 | 
			
		||||
    }
 | 
			
		||||
    const { accessProviders } = options
 | 
			
		||||
    this.logger = logger
 | 
			
		||||
    this.accessProviders = accessProviders
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,11 +26,18 @@ export class Registry {
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  get (name) {
 | 
			
		||||
    if (name) {
 | 
			
		||||
      return this.collection[name]
 | 
			
		||||
    if (!name) {
 | 
			
		||||
      throw new Error('插件名称不能为空')
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    throw new Error(`${name} cant blank`)
 | 
			
		||||
    if (!this.collection) {
 | 
			
		||||
      this.collection = {}
 | 
			
		||||
    }
 | 
			
		||||
    const plugin = this.collection[name]
 | 
			
		||||
    if (!plugin) {
 | 
			
		||||
      throw new Error(`插件${name}还未注册`)
 | 
			
		||||
    }
 | 
			
		||||
    return plugin
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getCollection () {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -43,6 +43,18 @@
 | 
			
		|||
        "node-forge": "^0.10.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "@certd/api": {
 | 
			
		||||
      "version": "0.1.13",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@certd/api/-/api-0.1.13.tgz",
 | 
			
		||||
      "integrity": "sha512-klb4B5D+lu1SAtopCyU4sfe12Q9U4k5x+GTaSLLk1Dr3cX0Mpq7/fySQIW5yPH2ZJGQQAbKm/vciBnUGYWFy/A==",
 | 
			
		||||
      "requires": {
 | 
			
		||||
        "axios": "^0.21.1",
 | 
			
		||||
        "dayjs": "^1.9.7",
 | 
			
		||||
        "lodash-es": "^4.17.20",
 | 
			
		||||
        "log4js": "^6.3.0",
 | 
			
		||||
        "qs": "^6.9.4"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "@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",
 | 
			
		||||
| 
						 | 
				
			
			@ -1790,6 +1802,11 @@
 | 
			
		|||
      "integrity": "sha1-tYsBCsQMIsVldhbI0sLALHv0eew=",
 | 
			
		||||
      "dev": true
 | 
			
		||||
    },
 | 
			
		||||
    "qs": {
 | 
			
		||||
      "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",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/randombytes/download/randombytes-2.1.0.tgz",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
{
 | 
			
		||||
  "name": "@certd/certd",
 | 
			
		||||
  "version": "0.1.13",
 | 
			
		||||
  "description": "",
 | 
			
		||||
  "description": "a ssl cert keeper",
 | 
			
		||||
  "main": "src/index.js",
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "test": "echo \\\"Error: no test specified\\\" && exit 1"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,12 +4,8 @@ import { FileStore } from './store/file-store.js'
 | 
			
		|||
import { CertStore } from './store/cert-store.js'
 | 
			
		||||
import dayjs from 'dayjs'
 | 
			
		||||
import forge from 'node-forge'
 | 
			
		||||
import DefaultDnsProviders from '@certd/dns-providers'
 | 
			
		||||
 | 
			
		||||
const logger = util.logger
 | 
			
		||||
 | 
			
		||||
DefaultDnsProviders.install()
 | 
			
		||||
 | 
			
		||||
export class Certd {
 | 
			
		||||
  constructor (options) {
 | 
			
		||||
    this.options = options
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
import chai from 'chai'
 | 
			
		||||
import { Certd } from '../src'
 | 
			
		||||
import { Certd } from '../src/index.js'
 | 
			
		||||
import { createOptions } from '../../../../test/options.js'
 | 
			
		||||
const { expect } = chai
 | 
			
		||||
const fakeCrt = `-----BEGIN CERTIFICATE-----
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,8 +12,6 @@
 | 
			
		|||
  "dependencies": {
 | 
			
		||||
    "@certd/api": "^0.1.13",
 | 
			
		||||
    "@certd/certd": "^0.1.13",
 | 
			
		||||
    "@certd/dns-providers": "^0.1.13",
 | 
			
		||||
    "@certd/plugins": "^0.1.13",
 | 
			
		||||
    "dayjs": "^1.9.7",
 | 
			
		||||
    "lodash-es": "^4.17.20"
 | 
			
		||||
  },
 | 
			
		||||
| 
						 | 
				
			
			@ -29,7 +27,10 @@
 | 
			
		|||
    "eslint-plugin-promise": "^4.2.1",
 | 
			
		||||
    "mocha": "^8.2.1",
 | 
			
		||||
    "rollup": "^2.35.1",
 | 
			
		||||
    "rollup-plugin-terser": "^7.0.2"
 | 
			
		||||
    "rollup-plugin-terser": "^7.0.2",
 | 
			
		||||
    "@certd/plugin-aliyun": "^0.1.13",
 | 
			
		||||
    "@certd/plugin-tencent": "^0.1.13",
 | 
			
		||||
    "@certd/plugin-host": "^0.1.13"
 | 
			
		||||
  },
 | 
			
		||||
  "author": "Greper",
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,15 +3,6 @@ import { pluginRegistry, util } from '@certd/api'
 | 
			
		|||
import _ from 'lodash-es'
 | 
			
		||||
import dayjs from 'dayjs'
 | 
			
		||||
import { Trace } from './trace.js'
 | 
			
		||||
import PluginAliyun from '@certd/plugin-aliyun'
 | 
			
		||||
import PluginTencent from '@certd/plugin-tencent'
 | 
			
		||||
import PluginHost from '@certd/plugin-host'
 | 
			
		||||
 | 
			
		||||
// 安装默认插件和授权提供者
 | 
			
		||||
PluginAliyun.install()
 | 
			
		||||
PluginTencent.install()
 | 
			
		||||
PluginHost.install()
 | 
			
		||||
 | 
			
		||||
const logger = util.logger
 | 
			
		||||
 | 
			
		||||
function createDefaultOptions () {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| 
						 | 
				
			
			@ -17,7 +17,8 @@
 | 
			
		|||
		"eslint-plugin-import": "^2.22.1",
 | 
			
		||||
		"eslint-plugin-node": "^11.1.0",
 | 
			
		||||
		"eslint-plugin-promise": "^4.2.1",
 | 
			
		||||
		"mocha": "^8.2.1"
 | 
			
		||||
		"mocha": "^8.2.1",
 | 
			
		||||
		"@certd/certd": "^0.1.13"
 | 
			
		||||
	},
 | 
			
		||||
	"author": "Greper",
 | 
			
		||||
	"license": "MIT",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,33 +1,16 @@
 | 
			
		|||
 | 
			
		||||
import _ from 'lodash-es'
 | 
			
		||||
 | 
			
		||||
import { AliyunDnsProvider, AliyunAccessProvider } from './access-providers/aliyun'
 | 
			
		||||
import { AliyunDnsProvider } from './dns-providers/aliyun.js'
 | 
			
		||||
import { AliyunAccessProvider } from './access-providers/aliyun.js'
 | 
			
		||||
import { UploadCertToAliyun } from './plugins/upload-to-aliyun/index.js'
 | 
			
		||||
import { DeployCertToAliyunCDN } from './plugins/deploy-to-cdn/index.js'
 | 
			
		||||
 | 
			
		||||
import { UploadCertToAliyun } from './plugins/upload-to-aliyun'
 | 
			
		||||
import { DeployCertToAliyunCDN } from './plugins/deploy-to-cdn'
 | 
			
		||||
 | 
			
		||||
import { UploadCertToTencent } from './tencent/upload-to-tencent/index.js'
 | 
			
		||||
 | 
			
		||||
import { DeployCertToTencentCDN } from './tencent/deploy-to-cdn/index.js'
 | 
			
		||||
 | 
			
		||||
import { DeployCertToTencentCLB } from './tencent/deploy-to-clb/index.js'
 | 
			
		||||
 | 
			
		||||
import { DeployCertToTencentTKEIngress } from './tencent/deploy-to-tke-ingress/index.js'
 | 
			
		||||
 | 
			
		||||
import { UploadCertToHost } from './host/upload-to-host/index.js'
 | 
			
		||||
import { HostShellExecute } from './host/host-shell-execute/index.js'
 | 
			
		||||
 | 
			
		||||
import { pluginRegistry, accessProviderRegister, dnsProviderRegistry } from '@certd/api'
 | 
			
		||||
import { pluginRegistry, accessProviderRegistry, dnsProviderRegistry } from '@certd/api'
 | 
			
		||||
 | 
			
		||||
export const Plugins = {
 | 
			
		||||
  UploadCertToAliyun,
 | 
			
		||||
  DeployCertToAliyunCDN,
 | 
			
		||||
  UploadCertToTencent,
 | 
			
		||||
  DeployCertToTencentTKEIngress,
 | 
			
		||||
  DeployCertToTencentCDN,
 | 
			
		||||
  DeployCertToTencentCLB,
 | 
			
		||||
  UploadCertToHost,
 | 
			
		||||
  HostShellExecute
 | 
			
		||||
  DeployCertToAliyunCDN
 | 
			
		||||
}
 | 
			
		||||
export default {
 | 
			
		||||
  install () {
 | 
			
		||||
| 
						 | 
				
			
			@ -35,8 +18,7 @@ export default {
 | 
			
		|||
      pluginRegistry.install(item)
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    accessProviderRegister.install(AliyunAccessProvider)
 | 
			
		||||
 | 
			
		||||
    accessProviderRegistry.install(AliyunAccessProvider)
 | 
			
		||||
    dnsProviderRegistry.install(AliyunDnsProvider)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,10 @@
 | 
			
		|||
import pkg from 'chai'
 | 
			
		||||
import { createOptions } from '../../../../../test/options.js'
 | 
			
		||||
import { Certd } from '../../src'
 | 
			
		||||
import { Certd } from '@certd/certd'
 | 
			
		||||
import PluginAliyun from '../../src/index.js'
 | 
			
		||||
 | 
			
		||||
// 安装默认插件和授权提供者
 | 
			
		||||
PluginAliyun.install()
 | 
			
		||||
const { expect } = pkg
 | 
			
		||||
describe('AliyunDnsProvider', function () {
 | 
			
		||||
  it('#申请证书-aliyun', async function () {
 | 
			
		||||
| 
						 | 
				
			
			@ -1,27 +1,33 @@
 | 
			
		|||
import pkg from 'chai'
 | 
			
		||||
import AliyunDnsProvider from '../../src/dns-providers/aliyun.js'
 | 
			
		||||
import { AliyunDnsProvider } from '../../src/dns-providers/aliyun.js'
 | 
			
		||||
import { createOptions } from '../../../../../test/options.js'
 | 
			
		||||
const { expect } = pkg
 | 
			
		||||
 | 
			
		||||
export function getPluginOptions () {
 | 
			
		||||
  const options = createOptions()
 | 
			
		||||
  return { accessProviders: options.accessProviders, props: options.cert.dnsProvider }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
describe('AliyunDnsProvider', function () {
 | 
			
		||||
  it('#getDomainList', async function () {
 | 
			
		||||
    const options = createOptions()
 | 
			
		||||
    const aliyunDnsProvider = new AliyunDnsProvider(options.accessProviders.aliyun)
 | 
			
		||||
    const options = getPluginOptions()
 | 
			
		||||
    const aliyunDnsProvider = new AliyunDnsProvider(options)
 | 
			
		||||
    const domainList = await aliyunDnsProvider.getDomainList()
 | 
			
		||||
    console.log('domainList', domainList)
 | 
			
		||||
    expect(domainList.length).gt(0)
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  it('#getRecords', async function () {
 | 
			
		||||
    const options = createOptions()
 | 
			
		||||
    const aliyunDnsProvider = new AliyunDnsProvider(options.accessProviders.aliyun)
 | 
			
		||||
    const options = getPluginOptions()
 | 
			
		||||
    const aliyunDnsProvider = new AliyunDnsProvider(options)
 | 
			
		||||
    const recordList = await aliyunDnsProvider.getRecords('docmirror.cn', '*')
 | 
			
		||||
    console.log('recordList', recordList)
 | 
			
		||||
    expect(recordList.length).gt(0)
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  it('#createAndRemoveRecord', async function () {
 | 
			
		||||
    const options = createOptions()
 | 
			
		||||
    const aliyunDnsProvider = new AliyunDnsProvider(options.accessProviders.aliyun)
 | 
			
		||||
    const options = getPluginOptions()
 | 
			
		||||
    const aliyunDnsProvider = new AliyunDnsProvider(options)
 | 
			
		||||
    const record = await aliyunDnsProvider.createRecord({ fullRecord: '___certd___.__test__.docmirror.cn', type: 'TXT', value: 'aaaa' })
 | 
			
		||||
    console.log('recordId', record)
 | 
			
		||||
    expect(record != null).ok
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,7 +24,7 @@ const defaultOptions = {
 | 
			
		|||
  cert: {
 | 
			
		||||
    domains: ['*.docmirror.club', 'docmirror.club'],
 | 
			
		||||
    email: 'xiaojunnuo@qq.com',
 | 
			
		||||
    dnsProvider: 'aliyun',
 | 
			
		||||
    dnsProvider: { type: 'aliyun', accessProvider: 'aliyun' },
 | 
			
		||||
    certProvider: 'letsencrypt',
 | 
			
		||||
    csrInfo: {
 | 
			
		||||
      country: 'CN',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,21 +1,20 @@
 | 
			
		|||
import pkg from 'chai'
 | 
			
		||||
import { DeployCertToAliyunCDN } from '../../src/plugins/deploy-to-cdn/index.js'
 | 
			
		||||
import { Certd } from '@certd/certd'
 | 
			
		||||
import createOptions from '../../../../../test/options.js'
 | 
			
		||||
import { createOptions } from '../../../../../test/options.js'
 | 
			
		||||
const { expect } = pkg
 | 
			
		||||
 | 
			
		||||
describe('DeployToAliyunCDN', function () {
 | 
			
		||||
  it('#execute', async function () {
 | 
			
		||||
    this.timeout(5000)
 | 
			
		||||
    const options = createOptions()
 | 
			
		||||
    const plugin = new DeployCertToAliyunCDN()
 | 
			
		||||
    const plugin = new DeployCertToAliyunCDN(options)
 | 
			
		||||
    options.cert.domains = ['*.docmirror.cn', 'docmirror.cn']
 | 
			
		||||
    const certd = new Certd(options)
 | 
			
		||||
    const cert = await certd.readCurrentCert()
 | 
			
		||||
    const ret = await plugin.doExecute({
 | 
			
		||||
      accessProviders: options.accessProviders,
 | 
			
		||||
      cert,
 | 
			
		||||
      props: { domainName: 'certd-cdn-upload.docmirror.cn', certName: 'certd部署测试', certType: 'cas', accessProvider: 'aliyun' }
 | 
			
		||||
      props: { domainName: 'certd-cdn-upload.docmirror.cn', certName: 'certd部署测试', from: 'cas', accessProvider: 'aliyun' }
 | 
			
		||||
    })
 | 
			
		||||
    console.log('context:', context, ret)
 | 
			
		||||
  })
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,12 +9,11 @@ describe('PluginUploadToAliyun', function () {
 | 
			
		|||
    const options = createOptions()
 | 
			
		||||
    options.cert.email = 'xiaojunnuo@qq.com'
 | 
			
		||||
    options.cert.domains = ['_.docmirror.cn']
 | 
			
		||||
    const plugin = new UploadCertToAliyun()
 | 
			
		||||
    const plugin = new UploadCertToAliyun(options)
 | 
			
		||||
    const certd = new Certd(options)
 | 
			
		||||
    const cert = await certd.readCurrentCert()
 | 
			
		||||
    const context = {}
 | 
			
		||||
    const deployOpts = {
 | 
			
		||||
      accessProviders: options.accessProviders,
 | 
			
		||||
      cert,
 | 
			
		||||
      props: { accessProvider: 'aliyun' },
 | 
			
		||||
      context
 | 
			
		||||
| 
						 | 
				
			
			@ -22,7 +21,7 @@ describe('PluginUploadToAliyun', function () {
 | 
			
		|||
    await plugin.doExecute(deployOpts)
 | 
			
		||||
    console.log('context:', context)
 | 
			
		||||
 | 
			
		||||
    //  await plugin.sleep(1000)
 | 
			
		||||
    // await plugin.sleep(1000)
 | 
			
		||||
    // await plugin.rollback(deployOpts)
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
{
 | 
			
		||||
	"name": "@certd/plugins",
 | 
			
		||||
	"name": "@certd/plugin-host",
 | 
			
		||||
	"version": "0.1.13",
 | 
			
		||||
	"description": "",
 | 
			
		||||
	"main": "src/index.js",
 | 
			
		||||
| 
						 | 
				
			
			@ -17,7 +17,8 @@
 | 
			
		|||
		"eslint-plugin-import": "^2.22.1",
 | 
			
		||||
		"eslint-plugin-node": "^11.1.0",
 | 
			
		||||
		"eslint-plugin-promise": "^4.2.1",
 | 
			
		||||
		"mocha": "^8.2.1"
 | 
			
		||||
		"mocha": "^8.2.1",
 | 
			
		||||
		"@certd/certd": "^0.1.13"
 | 
			
		||||
	},
 | 
			
		||||
	"author": "Greper",
 | 
			
		||||
	"license": "MIT",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,12 +12,6 @@ export class HostShellExecute extends AbstractHostPlugin {
 | 
			
		|||
      name: 'hostShellExecute',
 | 
			
		||||
      label: '执行远程主机脚本命令',
 | 
			
		||||
      input: {
 | 
			
		||||
        script: {
 | 
			
		||||
          label: 'shell脚本命令',
 | 
			
		||||
          component: {
 | 
			
		||||
            name: 'a-textarea'
 | 
			
		||||
          }
 | 
			
		||||
        },
 | 
			
		||||
        accessProvider: {
 | 
			
		||||
          label: '主机登录配置',
 | 
			
		||||
          type: [String, Object],
 | 
			
		||||
| 
						 | 
				
			
			@ -27,6 +21,12 @@ export class HostShellExecute extends AbstractHostPlugin {
 | 
			
		|||
            filter: 'ssh'
 | 
			
		||||
          },
 | 
			
		||||
          required: true
 | 
			
		||||
        },
 | 
			
		||||
        script: {
 | 
			
		||||
          label: 'shell脚本命令',
 | 
			
		||||
          component: {
 | 
			
		||||
            name: 'a-textarea'
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      },
 | 
			
		||||
      output: {
 | 
			
		||||
| 
						 | 
				
			
			@ -39,7 +39,7 @@ export class HostShellExecute extends AbstractHostPlugin {
 | 
			
		|||
    const { script, accessProvider } = props
 | 
			
		||||
    const connectConf = this.getAccessProvider(accessProvider)
 | 
			
		||||
    const sshClient = new SshClient()
 | 
			
		||||
    const ret = await sshClient.shell({
 | 
			
		||||
    const ret = await sshClient.exec({
 | 
			
		||||
      connectConf,
 | 
			
		||||
      script
 | 
			
		||||
    })
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
import ssh2 from 'ssh2'
 | 
			
		||||
import path from 'path'
 | 
			
		||||
import { util } from '@certd/api'
 | 
			
		||||
import _ from 'lodash-es'
 | 
			
		||||
const logger = util.logger
 | 
			
		||||
export class SshClient {
 | 
			
		||||
  /**
 | 
			
		||||
| 
						 | 
				
			
			@ -42,6 +43,42 @@ export class SshClient {
 | 
			
		|||
    })
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  exec ({ connectConf, script }) {
 | 
			
		||||
    if (_.isArray(script)) {
 | 
			
		||||
      script = script.join('\n')
 | 
			
		||||
    }
 | 
			
		||||
    return new Promise((resolve, reject) => {
 | 
			
		||||
      this.connect({
 | 
			
		||||
        connectConf,
 | 
			
		||||
        onReady: (conn) => {
 | 
			
		||||
          conn.exec(script, (err, stream) => {
 | 
			
		||||
            if (err) {
 | 
			
		||||
              reject(err)
 | 
			
		||||
              return
 | 
			
		||||
            }
 | 
			
		||||
            let data = null
 | 
			
		||||
            stream.on('close', (code, signal) => {
 | 
			
		||||
              console.log(`[${connectConf.host}][close]:code:${code}, signal:${signal} `)
 | 
			
		||||
              if (code === 0) {
 | 
			
		||||
                resolve(data.toString())
 | 
			
		||||
              } else {
 | 
			
		||||
                reject(data.toString())
 | 
			
		||||
              }
 | 
			
		||||
              conn.end()
 | 
			
		||||
            }).on('data', (ret) => {
 | 
			
		||||
              console.log(`[${connectConf.host}][info]: ` + ret)
 | 
			
		||||
              data = ret
 | 
			
		||||
            }).stderr.on('data', (err) => {
 | 
			
		||||
              console.log(`[${connectConf.host}][error]: ` + err)
 | 
			
		||||
              data = err
 | 
			
		||||
              stream.close()
 | 
			
		||||
            })
 | 
			
		||||
          })
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  shell ({ connectConf, script }) {
 | 
			
		||||
    return new Promise((resolve, reject) => {
 | 
			
		||||
      this.connect({
 | 
			
		||||
| 
						 | 
				
			
			@ -88,24 +125,4 @@ export class SshClient {
 | 
			
		|||
      })
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  exec ({ conn, cmd }) {
 | 
			
		||||
    return new Promise((resolve, reject) => {
 | 
			
		||||
      conn.exec(cmd, (err, stream) => {
 | 
			
		||||
        if (err) {
 | 
			
		||||
          logger.error('执行命令出错', err)
 | 
			
		||||
          reject(err)
 | 
			
		||||
          // return conn.end()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        stream.on('close', (code, signal) => {
 | 
			
		||||
          // logger.info('Stream :: close :: code: ' + code + ', signal: ' + signal)
 | 
			
		||||
          // conn.end()
 | 
			
		||||
          resolve()
 | 
			
		||||
        }).on('data', (data) => {
 | 
			
		||||
          logger.info('data', data.toString())
 | 
			
		||||
        })
 | 
			
		||||
      })
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,13 +16,12 @@ describe('HostShellExecute', function () {
 | 
			
		|||
    const context = {}
 | 
			
		||||
    const uploadOpts = {
 | 
			
		||||
      cert,
 | 
			
		||||
      props: { script: 'ls ', accessProvider: 'aliyun-ssh' },
 | 
			
		||||
      props: { script: ['ls ', 'ls '], accessProvider: 'aliyun-ssh' },
 | 
			
		||||
      context
 | 
			
		||||
    }
 | 
			
		||||
    const ret = await plugin.doExecute(uploadOpts)
 | 
			
		||||
    for (const retElement of ret) {
 | 
			
		||||
      console.log('-----' + retElement)
 | 
			
		||||
    }
 | 
			
		||||
    expect(ret).ok
 | 
			
		||||
    console.log('-----' + JSON.stringify(ret))
 | 
			
		||||
 | 
			
		||||
    await plugin.doRollback(uploadOpts)
 | 
			
		||||
  })
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
{
 | 
			
		||||
  "name": "@certd/plugins",
 | 
			
		||||
  "name": "@certd/plugin-tencent",
 | 
			
		||||
  "version": "0.1.13",
 | 
			
		||||
  "lockfileVersion": 1,
 | 
			
		||||
  "requires": true,
 | 
			
		||||
| 
						 | 
				
			
			@ -8,6 +8,7 @@
 | 
			
		|||
      "version": "1.7.10",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/@alicloud/pop-core/download/@alicloud/pop-core-1.7.10.tgz",
 | 
			
		||||
      "integrity": "sha1-0OIhA227DM3kU90Jsc+r2DQbemk=",
 | 
			
		||||
      "dev": true,
 | 
			
		||||
      "requires": {
 | 
			
		||||
        "debug": "^3.1.0",
 | 
			
		||||
        "httpx": "^2.1.2",
 | 
			
		||||
| 
						 | 
				
			
			@ -131,6 +132,37 @@
 | 
			
		|||
        "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==",
 | 
			
		||||
      "dev": true,
 | 
			
		||||
      "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==",
 | 
			
		||||
          "dev": true,
 | 
			
		||||
          "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==",
 | 
			
		||||
          "dev": true
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "@certd/api": {
 | 
			
		||||
      "version": "0.1.13",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/@certd/api/download/@certd/api-0.1.13.tgz",
 | 
			
		||||
| 
						 | 
				
			
			@ -143,6 +175,32 @@
 | 
			
		|||
        "qs": "^6.9.4"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "@certd/certd": {
 | 
			
		||||
      "version": "0.1.13",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@certd/certd/-/certd-0.1.13.tgz",
 | 
			
		||||
      "integrity": "sha512-ng4iFJY23AhTM2VY/tX/3ywoIF96pUF6VP6iXRlhdap8o4xOEywfjeHefFMxdi85Aw3sklBm4U38QZjqA++tnA==",
 | 
			
		||||
      "dev": true,
 | 
			
		||||
      "requires": {
 | 
			
		||||
        "@certd/acme-client": "^0.1.6",
 | 
			
		||||
        "@certd/api": "^0.1.13",
 | 
			
		||||
        "@certd/dns-providers": "^0.1.13",
 | 
			
		||||
        "dayjs": "^1.9.7",
 | 
			
		||||
        "lodash-es": "^4.17.20",
 | 
			
		||||
        "node-forge": "^0.10.0"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "@certd/dns-providers": {
 | 
			
		||||
      "version": "0.1.13",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/@certd/dns-providers/-/dns-providers-0.1.13.tgz",
 | 
			
		||||
      "integrity": "sha512-a9eD61t6dnacTLJqEUWijhVf1OUmZmPyrm8asTxMAPt7zw60xNxFSJFGHGJYM0bMGPsqUP4WBsSZ5JU4SHy5bg==",
 | 
			
		||||
      "dev": true,
 | 
			
		||||
      "requires": {
 | 
			
		||||
        "@alicloud/pop-core": "^1.7.10",
 | 
			
		||||
        "@certd/api": "^0.1.13",
 | 
			
		||||
        "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",
 | 
			
		||||
| 
						 | 
				
			
			@ -509,6 +567,12 @@
 | 
			
		|||
        "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=",
 | 
			
		||||
      "dev": true
 | 
			
		||||
    },
 | 
			
		||||
    "balanced-match": {
 | 
			
		||||
      "version": "1.0.0",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/balanced-match/download/balanced-match-1.0.0.tgz",
 | 
			
		||||
| 
						 | 
				
			
			@ -530,7 +594,8 @@
 | 
			
		|||
    "bignumber.js": {
 | 
			
		||||
      "version": "9.0.1",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/bignumber.js/download/bignumber.js-9.0.1.tgz",
 | 
			
		||||
      "integrity": "sha1-jXuhJMiCv9jkMmDGdHVRjQaJ5OU="
 | 
			
		||||
      "integrity": "sha1-jXuhJMiCv9jkMmDGdHVRjQaJ5OU=",
 | 
			
		||||
      "dev": true
 | 
			
		||||
    },
 | 
			
		||||
    "binary-extensions": {
 | 
			
		||||
      "version": "2.1.0",
 | 
			
		||||
| 
						 | 
				
			
			@ -538,6 +603,12 @@
 | 
			
		|||
      "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==",
 | 
			
		||||
      "dev": true
 | 
			
		||||
    },
 | 
			
		||||
    "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",
 | 
			
		||||
| 
						 | 
				
			
			@ -1662,6 +1733,7 @@
 | 
			
		|||
      "version": "2.2.7",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/httpx/download/httpx-2.2.7.tgz?cache=0&sync_timestamp=1604908999113&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fhttpx%2Fdownload%2Fhttpx-2.2.7.tgz",
 | 
			
		||||
      "integrity": "sha1-HjQZgUbjLKMwWmbBEglVnhy+ugk=",
 | 
			
		||||
      "dev": true,
 | 
			
		||||
      "requires": {
 | 
			
		||||
        "@types/node": "^14",
 | 
			
		||||
        "debug": "^4.1.1"
 | 
			
		||||
| 
						 | 
				
			
			@ -1671,6 +1743,7 @@
 | 
			
		|||
          "version": "4.3.1",
 | 
			
		||||
          "resolved": "https://registry.npm.taobao.org/debug/download/debug-4.3.1.tgz?cache=0&sync_timestamp=1607566533140&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fdebug%2Fdownload%2Fdebug-4.3.1.tgz",
 | 
			
		||||
          "integrity": "sha1-8NIpxQXgxtjEmsVT0bE9wYP2su4=",
 | 
			
		||||
          "dev": true,
 | 
			
		||||
          "requires": {
 | 
			
		||||
            "ms": "2.1.2"
 | 
			
		||||
          }
 | 
			
		||||
| 
						 | 
				
			
			@ -1678,7 +1751,8 @@
 | 
			
		|||
        "ms": {
 | 
			
		||||
          "version": "2.1.2",
 | 
			
		||||
          "resolved": "https://registry.npm.taobao.org/ms/download/ms-2.1.2.tgz?cache=0&sync_timestamp=1607433842694&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fms%2Fdownload%2Fms-2.1.2.tgz",
 | 
			
		||||
          "integrity": "sha1-0J0fNXtEP0kzgqjrPM0YOHKuYAk="
 | 
			
		||||
          "integrity": "sha1-0J0fNXtEP0kzgqjrPM0YOHKuYAk=",
 | 
			
		||||
          "dev": true
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
| 
						 | 
				
			
			@ -1923,6 +1997,7 @@
 | 
			
		|||
      "version": "1.0.0",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/json-bigint/download/json-bigint-1.0.0.tgz",
 | 
			
		||||
      "integrity": "sha1-rlR4I6wMrYOYZn+M2e9HMPWwH/E=",
 | 
			
		||||
      "dev": true,
 | 
			
		||||
      "requires": {
 | 
			
		||||
        "bignumber.js": "^9.0.0"
 | 
			
		||||
      }
 | 
			
		||||
| 
						 | 
				
			
			@ -2011,7 +2086,8 @@
 | 
			
		|||
    "kitx": {
 | 
			
		||||
      "version": "1.3.0",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/kitx/download/kitx-1.3.0.tgz",
 | 
			
		||||
      "integrity": "sha1-qz7nxZjSsdYp/VVWj4aMREDCAOo="
 | 
			
		||||
      "integrity": "sha1-qz7nxZjSsdYp/VVWj4aMREDCAOo=",
 | 
			
		||||
      "dev": true
 | 
			
		||||
    },
 | 
			
		||||
    "kubernetes-client": {
 | 
			
		||||
      "version": "9.0.0",
 | 
			
		||||
| 
						 | 
				
			
			@ -2366,6 +2442,12 @@
 | 
			
		|||
      "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==",
 | 
			
		||||
      "dev": true
 | 
			
		||||
    },
 | 
			
		||||
    "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",
 | 
			
		||||
| 
						 | 
				
			
			@ -2901,7 +2983,8 @@
 | 
			
		|||
    "sax": {
 | 
			
		||||
      "version": "1.2.4",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/sax/download/sax-1.2.4.tgz",
 | 
			
		||||
      "integrity": "sha1-KBYjTiN4vdxOU1T6tcqold9xANk="
 | 
			
		||||
      "integrity": "sha1-KBYjTiN4vdxOU1T6tcqold9xANk=",
 | 
			
		||||
      "dev": true
 | 
			
		||||
    },
 | 
			
		||||
    "semver": {
 | 
			
		||||
      "version": "7.3.4",
 | 
			
		||||
| 
						 | 
				
			
			@ -3041,24 +3124,6 @@
 | 
			
		|||
      "resolved": "https://registry.npm.taobao.org/sprintf-js/download/sprintf-js-1.0.3.tgz",
 | 
			
		||||
      "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
 | 
			
		||||
    },
 | 
			
		||||
    "ssh2": {
 | 
			
		||||
      "version": "0.8.9",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/ssh2/download/ssh2-0.8.9.tgz",
 | 
			
		||||
      "integrity": "sha1-VNo6bEuj2vDYR3pTikgTJgkYFfM=",
 | 
			
		||||
      "requires": {
 | 
			
		||||
        "ssh2-streams": "~0.4.10"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "ssh2-streams": {
 | 
			
		||||
      "version": "0.4.10",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/ssh2-streams/download/ssh2-streams-0.4.10.tgz",
 | 
			
		||||
      "integrity": "sha1-SO9+ig452PKSHDBSHVbayzHSOjQ=",
 | 
			
		||||
      "requires": {
 | 
			
		||||
        "asn1": "~0.2.0",
 | 
			
		||||
        "bcrypt-pbkdf": "^1.0.2",
 | 
			
		||||
        "streamsearch": "~0.1.2"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "sshpk": {
 | 
			
		||||
      "version": "1.16.1",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/sshpk/download/sshpk-1.16.1.tgz",
 | 
			
		||||
| 
						 | 
				
			
			@ -3105,11 +3170,6 @@
 | 
			
		|||
        }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "streamsearch": {
 | 
			
		||||
      "version": "0.1.2",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/streamsearch/download/streamsearch-0.1.2.tgz",
 | 
			
		||||
      "integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
 | 
			
		||||
    },
 | 
			
		||||
    "string-width": {
 | 
			
		||||
      "version": "4.2.0",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/string-width/download/string-width-4.2.0.tgz",
 | 
			
		||||
| 
						 | 
				
			
			@ -3520,6 +3580,7 @@
 | 
			
		|||
      "version": "0.4.23",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/xml2js/download/xml2js-0.4.23.tgz?cache=0&sync_timestamp=1599054229598&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fxml2js%2Fdownload%2Fxml2js-0.4.23.tgz",
 | 
			
		||||
      "integrity": "sha1-oMaVFnUkIesqx1juTUzPWIQ+rGY=",
 | 
			
		||||
      "dev": true,
 | 
			
		||||
      "requires": {
 | 
			
		||||
        "sax": ">=0.6.0",
 | 
			
		||||
        "xmlbuilder": "~11.0.0"
 | 
			
		||||
| 
						 | 
				
			
			@ -3528,7 +3589,8 @@
 | 
			
		|||
    "xmlbuilder": {
 | 
			
		||||
      "version": "11.0.1",
 | 
			
		||||
      "resolved": "https://registry.npm.taobao.org/xmlbuilder/download/xmlbuilder-11.0.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fxmlbuilder%2Fdownload%2Fxmlbuilder-11.0.1.tgz",
 | 
			
		||||
      "integrity": "sha1-vpuuHIoEbnazESdyY0fQrXACvrM="
 | 
			
		||||
      "integrity": "sha1-vpuuHIoEbnazESdyY0fQrXACvrM=",
 | 
			
		||||
      "dev": true
 | 
			
		||||
    },
 | 
			
		||||
    "y18n": {
 | 
			
		||||
      "version": "4.0.1",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
{
 | 
			
		||||
	"name": "@certd/plugins",
 | 
			
		||||
	"name": "@certd/plugin-tencent",
 | 
			
		||||
	"version": "0.1.13",
 | 
			
		||||
	"description": "",
 | 
			
		||||
	"main": "src/index.js",
 | 
			
		||||
| 
						 | 
				
			
			@ -18,7 +18,8 @@
 | 
			
		|||
		"eslint-plugin-import": "^2.22.1",
 | 
			
		||||
		"eslint-plugin-node": "^11.1.0",
 | 
			
		||||
		"eslint-plugin-promise": "^4.2.1",
 | 
			
		||||
		"mocha": "^8.2.1"
 | 
			
		||||
		"mocha": "^8.2.1",
 | 
			
		||||
		"@certd/certd": "^0.1.13"
 | 
			
		||||
	},
 | 
			
		||||
	"author": "Greper",
 | 
			
		||||
	"license": "MIT",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,16 +1,16 @@
 | 
			
		|||
import _ from 'lodash-es'
 | 
			
		||||
 | 
			
		||||
import { TencentAccessProvider } from './access-providers/tencent'
 | 
			
		||||
import { DnspodAccessProvider } from './access-providers/dnspod'
 | 
			
		||||
import { TencentAccessProvider } from './access-providers/tencent.js'
 | 
			
		||||
import { DnspodAccessProvider } from './access-providers/dnspod.js'
 | 
			
		||||
import { DnspodDnsProvider } from './dns-providers/dnspod.js'
 | 
			
		||||
 | 
			
		||||
import { UploadCertToTencent } from './plugins/upload-to-tencent'
 | 
			
		||||
import { UploadCertToTencent } from './plugins/upload-to-tencent/index.js'
 | 
			
		||||
 | 
			
		||||
import { DeployCertToTencentCDN } from './plugins/deploy-to-cdn'
 | 
			
		||||
import { DeployCertToTencentCDN } from './plugins/deploy-to-cdn/index.js'
 | 
			
		||||
 | 
			
		||||
import { DeployCertToTencentCLB } from './plugins/deploy-to-clb'
 | 
			
		||||
import { DeployCertToTencentCLB } from './plugins/deploy-to-clb/index.js'
 | 
			
		||||
 | 
			
		||||
import { DeployCertToTencentTKEIngress } from './plugins/deploy-to-tke-ingress'
 | 
			
		||||
import { DeployCertToTencentTKEIngress } from './plugins/deploy-to-tke-ingress/index.js'
 | 
			
		||||
 | 
			
		||||
import { pluginRegistry, accessProviderRegistry, dnsProviderRegistry } from '@certd/api'
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -27,7 +27,7 @@ export default {
 | 
			
		|||
    })
 | 
			
		||||
 | 
			
		||||
    accessProviderRegistry.install(TencentAccessProvider)
 | 
			
		||||
    accessProviderRegistry.install(DnspodDnsProvider)
 | 
			
		||||
    accessProviderRegistry.install(DnspodAccessProvider)
 | 
			
		||||
 | 
			
		||||
    dnsProviderRegistry.install(DnspodDnsProvider)
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,7 +44,10 @@ export class DeployCertToTencentCDN extends AbstractTencentPlugin {
 | 
			
		|||
        }
 | 
			
		||||
      },
 | 
			
		||||
      output: {
 | 
			
		||||
 | 
			
		||||
        tencentCertId: {
 | 
			
		||||
          type: String,
 | 
			
		||||
          desc: '证书来源选择上传时,将返回此id'
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,7 +45,7 @@ export class K8sClient {
 | 
			
		|||
   * @param opts = {namespace:default}
 | 
			
		||||
   * @returns secretsList
 | 
			
		||||
   */
 | 
			
		||||
  async getSecret (opts) {
 | 
			
		||||
  async getSecret (opts = {}) {
 | 
			
		||||
    const namespace = opts.namespace || 'default'
 | 
			
		||||
    const secrets = await this.client.api.v1.namespaces(namespace).secrets.get()
 | 
			
		||||
    return secrets
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,13 +1,20 @@
 | 
			
		|||
import pkg from 'chai'
 | 
			
		||||
import { Certd } from '../../src'
 | 
			
		||||
import PluginTencent from '../../src/index.js'
 | 
			
		||||
import { createOptions } from '../../../../../test/options.js'
 | 
			
		||||
import { Certd } from '@certd/certd'
 | 
			
		||||
const { expect } = pkg
 | 
			
		||||
 | 
			
		||||
// 安装默认插件和授权提供者
 | 
			
		||||
PluginTencent.install()
 | 
			
		||||
describe('DnspodDnsProvider', function () {
 | 
			
		||||
  it('#申请证书', async function () {
 | 
			
		||||
    this.timeout(300000)
 | 
			
		||||
    const options = createOptions()
 | 
			
		||||
    options.cert.domains = ['*.certd.xyz', '*.test.certd.xyz', '*.base.certd.xyz', 'certd.xyz']
 | 
			
		||||
    options.cert.dnsProvider = 'dnspod'
 | 
			
		||||
    options.cert.dnsProvider = {
 | 
			
		||||
      type: 'dnspod',
 | 
			
		||||
      accessProvider: 'dnspod'
 | 
			
		||||
    }
 | 
			
		||||
    options.args = { forceCert: true }
 | 
			
		||||
    const certd = new Certd(options)
 | 
			
		||||
    const cert = await certd.certApply()
 | 
			
		||||
| 
						 | 
				
			
			@ -1,19 +1,31 @@
 | 
			
		|||
import pkg from 'chai'
 | 
			
		||||
import DnspodDnsProvider from '../../src/dns-providers/dnspod.js'
 | 
			
		||||
import { createOptions } from '../../../../../test/options.js'
 | 
			
		||||
import { DnspodDnsProvider } from '../../src/dns-providers/dnspod.js'
 | 
			
		||||
import { createOptions, getDnsProviderOptions } from '../../../../../test/options.js'
 | 
			
		||||
const { expect } = pkg
 | 
			
		||||
describe('DnspodDnsProvider', function () {
 | 
			
		||||
  it('#getDomainList', async function () {
 | 
			
		||||
    const options = createOptions()
 | 
			
		||||
    const dnsProvider = new DnspodDnsProvider(options.accessProviders.dnspod)
 | 
			
		||||
    let options = createOptions()
 | 
			
		||||
    options.cert.dnsProvider = {
 | 
			
		||||
      type: 'dnspod',
 | 
			
		||||
      accessProvider: 'dnspod'
 | 
			
		||||
    }
 | 
			
		||||
    options = getDnsProviderOptions(options)
 | 
			
		||||
 | 
			
		||||
    const dnsProvider = new DnspodDnsProvider(options)
 | 
			
		||||
    const domainList = await dnsProvider.getDomainList()
 | 
			
		||||
    console.log('domainList', domainList)
 | 
			
		||||
    expect(domainList.length).gt(0)
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  it('#createRecord&removeRecord', async function () {
 | 
			
		||||
    const options = createOptions()
 | 
			
		||||
    const dnsProvider = new DnspodDnsProvider(options.accessProviders.dnspod)
 | 
			
		||||
    let options = createOptions()
 | 
			
		||||
    options.cert.dnsProvider = {
 | 
			
		||||
      type: 'dnspod',
 | 
			
		||||
      accessProvider: 'dnspod'
 | 
			
		||||
    }
 | 
			
		||||
    options = getDnsProviderOptions(options)
 | 
			
		||||
 | 
			
		||||
    const dnsProvider = new DnspodDnsProvider(options)
 | 
			
		||||
    const record = await dnsProvider.createRecord({ fullRecord: '___certd___.__test__.certd.xyz', type: 'TXT', value: 'aaaa' })
 | 
			
		||||
    console.log('recordId', record.id)
 | 
			
		||||
    expect(record.id != null).ok
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,42 +0,0 @@
 | 
			
		|||
import _ from 'lodash-es'
 | 
			
		||||
import optionsPrivate from '../../../../test/options.private.js'
 | 
			
		||||
const defaultOptions = {
 | 
			
		||||
  version: '1.0.0',
 | 
			
		||||
  args: {
 | 
			
		||||
    directory: 'test',
 | 
			
		||||
    dry: false
 | 
			
		||||
  },
 | 
			
		||||
  accessProviders: {
 | 
			
		||||
    aliyun: {
 | 
			
		||||
      providerType: 'aliyun',
 | 
			
		||||
      accessKeyId: '',
 | 
			
		||||
      accessKeySecret: ''
 | 
			
		||||
    },
 | 
			
		||||
    myLinux: {
 | 
			
		||||
      providerType: 'SSH',
 | 
			
		||||
      username: 'xxx',
 | 
			
		||||
      password: 'xxx',
 | 
			
		||||
      host: '1111.com',
 | 
			
		||||
      port: 22,
 | 
			
		||||
      publicKey: ''
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  cert: {
 | 
			
		||||
    domains: ['*.docmirror.club', 'docmirror.club'],
 | 
			
		||||
    email: 'xiaojunnuo@qq.com',
 | 
			
		||||
    dnsProvider: 'aliyun',
 | 
			
		||||
    certProvider: 'letsencrypt',
 | 
			
		||||
    csrInfo: {
 | 
			
		||||
      country: 'CN',
 | 
			
		||||
      state: 'GuangDong',
 | 
			
		||||
      locality: 'ShengZhen',
 | 
			
		||||
      organization: 'CertD Org.',
 | 
			
		||||
      organizationUnit: 'IT Department',
 | 
			
		||||
      emailAddress: 'xiaojunnuo@qq.com'
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
_.merge(defaultOptions, optionsPrivate)
 | 
			
		||||
 | 
			
		||||
export default defaultOptions
 | 
			
		||||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
import pkg from 'chai'
 | 
			
		||||
import { DeployCertToTencentCDN } from '../../src/plugins/deploy-to-cdn'
 | 
			
		||||
import { DeployCertToTencentCDN } from '../../src/plugins/deploy-to-cdn/index.js'
 | 
			
		||||
import { Certd } from '@certd/certd'
 | 
			
		||||
import { UploadCertToTencent } from '../../src/plugins/upload-to-tencent'
 | 
			
		||||
import { UploadCertToTencent } from '../../src/plugins/upload-to-tencent/index.js'
 | 
			
		||||
import { createOptions } from '../../../../../test/options.js'
 | 
			
		||||
const { expect } = pkg
 | 
			
		||||
describe('DeployToTencentCDN', function () {
 | 
			
		||||
| 
						 | 
				
			
			@ -9,27 +9,25 @@ describe('DeployToTencentCDN', function () {
 | 
			
		|||
    const options = createOptions()
 | 
			
		||||
    options.args.test = false
 | 
			
		||||
    const certd = new Certd(options)
 | 
			
		||||
    const cert = certd.readCurrentCert('xiaojunnuo@qq.com', ['*.docmirror.cn'])
 | 
			
		||||
    const cert = await certd.readCurrentCert('xiaojunnuo@qq.com', ['*.docmirror.cn'])
 | 
			
		||||
    const context = {}
 | 
			
		||||
    const uploadPlugin = new UploadCertToTencent()
 | 
			
		||||
    const uploadPlugin = new UploadCertToTencent(options)
 | 
			
		||||
    const uploadOptions = {
 | 
			
		||||
      accessProviders: options.accessProviders,
 | 
			
		||||
      cert,
 | 
			
		||||
      props: { name: 'certd部署测试', accessProvider: 'tencent' },
 | 
			
		||||
      context
 | 
			
		||||
    }
 | 
			
		||||
    await uploadPlugin.doExecute(uploadOptions)
 | 
			
		||||
 | 
			
		||||
    const deployPlugin = new DeployCertToTencentCDN()
 | 
			
		||||
    const deployPlugin = new DeployCertToTencentCDN(options)
 | 
			
		||||
    const deployOpts = {
 | 
			
		||||
      accessProviders: options.accessProviders,
 | 
			
		||||
      cert,
 | 
			
		||||
      props: { domainName: 'tentcent-certd.docmirror.cn', certName: 'certd部署测试', accessProvider: 'tencent' },
 | 
			
		||||
      context
 | 
			
		||||
    }
 | 
			
		||||
    const ret = await deployPlugin.doExecute(deployOpts)
 | 
			
		||||
    expect(ret).ok
 | 
			
		||||
    await deployPlugin.doExecute(deployOpts)
 | 
			
		||||
    console.log('context:', context)
 | 
			
		||||
    expect(context.tencentCertId).ok
 | 
			
		||||
 | 
			
		||||
    await uploadPlugin.doRollback(uploadOptions)
 | 
			
		||||
  })
 | 
			
		||||
| 
						 | 
				
			
			@ -38,17 +36,17 @@ describe('DeployToTencentCDN', function () {
 | 
			
		|||
    options.args.test = false
 | 
			
		||||
    options.cert.email = 'xiaojunnuo@qq.com'
 | 
			
		||||
    options.cert.domains = ['*.docmirror.cn']
 | 
			
		||||
    const plugin = new DeployCertToTencentCDN()
 | 
			
		||||
    const plugin = new DeployCertToTencentCDN(options)
 | 
			
		||||
    const certd = new Certd(options)
 | 
			
		||||
    const cert = await certd.readCurrentCert()
 | 
			
		||||
    const context = {}
 | 
			
		||||
    const deployOpts = {
 | 
			
		||||
      accessProviders: options.accessProviders,
 | 
			
		||||
      cert,
 | 
			
		||||
      props: { domainName: 'tentcent-certd.docmirror.cn', accessProvider: 'tencent' },
 | 
			
		||||
      context
 | 
			
		||||
    }
 | 
			
		||||
    const ret = await plugin.doExecute(deployOpts)
 | 
			
		||||
    console.log('context:', context, ret)
 | 
			
		||||
    expect(context).be.empty
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,21 +3,20 @@ import { DeployCertToTencentCLB } from '../../src/plugins/deploy-to-clb/index.js
 | 
			
		|||
import { Certd } from '@certd/certd'
 | 
			
		||||
// eslint-disable-next-line no-unused-vars
 | 
			
		||||
import { createOptions } from '../../../../../test/options.js'
 | 
			
		||||
import { UploadCertToTencent } from '../../src/plugins/upload-to-tencent'
 | 
			
		||||
import { UploadCertToTencent } from '../../src/plugins/upload-to-tencent/index.js'
 | 
			
		||||
const { expect } = pkg
 | 
			
		||||
describe('DeployToTencentCLB', function () {
 | 
			
		||||
  it('#execute-getClbList', async function () {
 | 
			
		||||
    const options = createOptions()
 | 
			
		||||
    options.args.test = false
 | 
			
		||||
    options.cert.dnsProvider = 'tencent-yonsz'
 | 
			
		||||
    const deployPlugin = new DeployCertToTencentCLB()
 | 
			
		||||
    const deployPlugin = new DeployCertToTencentCLB(options)
 | 
			
		||||
    const props = {
 | 
			
		||||
      region: 'ap-guangzhou',
 | 
			
		||||
      domain: 'certd-test-no-sni.base.yonsz.net',
 | 
			
		||||
      accessProvider: 'tencent-yonsz'
 | 
			
		||||
    }
 | 
			
		||||
    const accessProviders = options.accessProviders
 | 
			
		||||
    const accessProvider = deployPlugin.getAccessProvider(props.accessProvider, accessProviders)
 | 
			
		||||
    const accessProvider = deployPlugin.getAccessProvider(props.accessProvider)
 | 
			
		||||
    const { region } = props
 | 
			
		||||
    const client = deployPlugin.getClient(accessProvider, region)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -34,13 +33,14 @@ describe('DeployToTencentCLB', function () {
 | 
			
		|||
      region: 'ap-guangzhou',
 | 
			
		||||
      domain: 'certd-test-no-sni.base.yonsz.net',
 | 
			
		||||
      accessProvider: 'tencent-yonsz',
 | 
			
		||||
      loadBalancerId: 'lb-59yhe5xo'
 | 
			
		||||
      loadBalancerId: 'lb-59yhe5xo',
 | 
			
		||||
      listenerId: 'lbl-1vfwx8dq'
 | 
			
		||||
    }
 | 
			
		||||
    const accessProvider = deployPlugin.getAccessProvider(props.accessProvider)
 | 
			
		||||
    const { region } = props
 | 
			
		||||
    const client = deployPlugin.getClient(accessProvider, region)
 | 
			
		||||
 | 
			
		||||
    const ret = await deployPlugin.getListenerList(client, props.loadBalancerId, props)
 | 
			
		||||
    const ret = await deployPlugin.getListenerList(client, props.loadBalancerId, [props.listenerId])
 | 
			
		||||
    expect(ret.length > 0).ok
 | 
			
		||||
    console.log('clb count:', ret.length, ret)
 | 
			
		||||
  })
 | 
			
		||||
| 
						 | 
				
			
			@ -54,10 +54,9 @@ describe('DeployToTencentCLB', function () {
 | 
			
		|||
    options.cert.domains = ['*.docmirror.cn']
 | 
			
		||||
    const certd = new Certd(options)
 | 
			
		||||
    const cert = await certd.readCurrentCert()
 | 
			
		||||
    const deployPlugin = new DeployCertToTencentCLB()
 | 
			
		||||
    const deployPlugin = new DeployCertToTencentCLB(options)
 | 
			
		||||
    const context = {}
 | 
			
		||||
    const deployOpts = {
 | 
			
		||||
      accessProviders: options.accessProviders,
 | 
			
		||||
      cert,
 | 
			
		||||
      props: {
 | 
			
		||||
        region: 'ap-guangzhou',
 | 
			
		||||
| 
						 | 
				
			
			@ -72,7 +71,7 @@ describe('DeployToTencentCLB', function () {
 | 
			
		|||
    console.log('ret:', ret)
 | 
			
		||||
 | 
			
		||||
    // 删除测试证书
 | 
			
		||||
    const uploadPlugin = new UploadCertToTencent()
 | 
			
		||||
    const uploadPlugin = new UploadCertToTencent(options)
 | 
			
		||||
    await uploadPlugin.doRollback(deployOpts)
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -83,10 +82,9 @@ describe('DeployToTencentCLB', function () {
 | 
			
		|||
    options.cert.dnsProvider = 'tencent-yonsz'
 | 
			
		||||
    const certd = new Certd(options)
 | 
			
		||||
    const cert = certd.readCurrentCert('xiaojunnuo@qq.com', ['*.docmirror.cn'])
 | 
			
		||||
    const deployPlugin = new DeployCertToTencentCLB()
 | 
			
		||||
    const deployPlugin = new DeployCertToTencentCLB(options)
 | 
			
		||||
    const context = {}
 | 
			
		||||
    const deployOpts = {
 | 
			
		||||
      accessProviders: options.accessProviders,
 | 
			
		||||
      cert,
 | 
			
		||||
      props: {
 | 
			
		||||
        region: 'ap-guangzhou',
 | 
			
		||||
| 
						 | 
				
			
			@ -98,10 +96,10 @@ describe('DeployToTencentCLB', function () {
 | 
			
		|||
      context
 | 
			
		||||
    }
 | 
			
		||||
    const ret = await deployPlugin.doExecute(deployOpts)
 | 
			
		||||
    expect(ret).ok
 | 
			
		||||
    console.log('ret:', ret)
 | 
			
		||||
    expect(ret).ok
 | 
			
		||||
    // 删除测试证书
 | 
			
		||||
    const uploadPlugin = new UploadCertToTencent()
 | 
			
		||||
    const uploadPlugin = new UploadCertToTencent(options)
 | 
			
		||||
    await uploadPlugin.doRollback(deployOpts)
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,14 +28,6 @@ async function getOptions () {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
describe('DeployCertToTencentTKEIngress', function () {
 | 
			
		||||
  // it('#getTkeKubeConfig', async function () {
 | 
			
		||||
  //   const { options, deployOpts } = await getOptions()
 | 
			
		||||
  //   const plugin = new DeployCertToTencentTKEIngress()
 | 
			
		||||
  //   const tkeClient = plugin.getTkeClient(options.accessProviders[deployOpts.props.accessProvider], deployOpts.props.region)
 | 
			
		||||
  //   const kubeConfig = await plugin.getTkeKubeConfig(tkeClient, deployOpts.props)
 | 
			
		||||
  //   console.log('kubeConfig:', kubeConfig)
 | 
			
		||||
  // })
 | 
			
		||||
  //
 | 
			
		||||
  it('#getTKESecrets', async function () {
 | 
			
		||||
    this.timeout(50000)
 | 
			
		||||
    const { options, deployOpts } = await getOptions()
 | 
			
		||||
| 
						 | 
				
			
			@ -47,66 +39,17 @@ describe('DeployCertToTencentTKEIngress', function () {
 | 
			
		|||
    k8sClient.setLookup({
 | 
			
		||||
      'cls-6lbj1vee.ccs.tencent-cloud.com': { ip: '13.123.123.123' }
 | 
			
		||||
    })
 | 
			
		||||
    const secrets = await k8sClient.getSecret()
 | 
			
		||||
    const secrets = await k8sClient.getSecret({ namespace: 'default' })
 | 
			
		||||
 | 
			
		||||
    console.log('secrets:', secrets)
 | 
			
		||||
  })
 | 
			
		||||
  //
 | 
			
		||||
  // it('#patchTKECertSecrets', async function () {
 | 
			
		||||
  //   this.timeout(5000)
 | 
			
		||||
  //
 | 
			
		||||
  //   const { options, deployOpts } = await getOptions()
 | 
			
		||||
  //   const plugin = new DeployCertToTencentTKEIngress()
 | 
			
		||||
  //   const tkeClient = plugin.getTkeClient(options.accessProviders[deployOpts.props.accessProvider], deployOpts.props.region)
 | 
			
		||||
  //   const kubeConfig = await plugin.getTkeKubeConfig(tkeClient, deployOpts.props)
 | 
			
		||||
  //   const k8sClient = new K8sClient(kubeConfig)
 | 
			
		||||
  //
 | 
			
		||||
  //   deployOpts.k8sClient = k8sClient
 | 
			
		||||
  //   deployOpts.context.tencentCertId = 'hNVD3Z45'
 | 
			
		||||
  //   const newCecret = await plugin.patchCertSecret(deployOpts)
 | 
			
		||||
  //   console.log('newCecret', newCecret)
 | 
			
		||||
  // })
 | 
			
		||||
  // it('#GetTkeIngress', async function () {
 | 
			
		||||
  //   this.timeout(5000)
 | 
			
		||||
  //
 | 
			
		||||
  //   const { options, deployOpts } = await getOptions()
 | 
			
		||||
  //   deployOpts.props.ingressName = 'ingress-base'
 | 
			
		||||
  //   deployOpts.props.secretName = 'cert---docmirror-cn'
 | 
			
		||||
  //   const plugin = new DeployCertToTencentTKEIngress()
 | 
			
		||||
  //   const tkeClient = plugin.getTkeClient(options.accessProviders[deployOpts.props.accessProvider], deployOpts.props.region)
 | 
			
		||||
  //   const kubeConfig = await plugin.getTkeKubeConfig(tkeClient, deployOpts.props)
 | 
			
		||||
  //
 | 
			
		||||
  //   const k8sClient = new K8sClient(kubeConfig)
 | 
			
		||||
  //   const ingress = await k8sClient.getIngress({
 | 
			
		||||
  //     ingressName: 'ingress-base'
 | 
			
		||||
  //   })
 | 
			
		||||
  //   console.log('ingress:', ingress)
 | 
			
		||||
  // })
 | 
			
		||||
  // it('#RestartTKEIngress', async function () {
 | 
			
		||||
  //   this.timeout(5000)
 | 
			
		||||
  //
 | 
			
		||||
  //   const { options, deployOpts } = await getOptions()
 | 
			
		||||
  //   deployOpts.props.ingressName = 'ingress-base'
 | 
			
		||||
  //   deployOpts.props.secretName = 'cert---docmirror-cn'
 | 
			
		||||
  //   const plugin = new DeployCertToTencentTKEIngress()
 | 
			
		||||
  //   const tkeClient = plugin.getTkeClient(options.accessProviders[deployOpts.props.accessProvider], deployOpts.props.region)
 | 
			
		||||
  //   const kubeConfig = await plugin.getTkeKubeConfig(tkeClient, deployOpts.props)
 | 
			
		||||
  //
 | 
			
		||||
  //   const k8sClient = new K8sClient(kubeConfig)
 | 
			
		||||
  //
 | 
			
		||||
  //   deployOpts.k8sClient = k8sClient
 | 
			
		||||
  //   deployOpts.context.tencentCertId = 'hNVD3Z45'
 | 
			
		||||
  //   const newCecret = await plugin.restartIngress(deployOpts)
 | 
			
		||||
  //   console.log('newCecret', newCecret)
 | 
			
		||||
  // })
 | 
			
		||||
 | 
			
		||||
  it('#execute', async function () {
 | 
			
		||||
    this.timeout(5000)
 | 
			
		||||
    const { deployOpts } = await getOptions()
 | 
			
		||||
    const { options, deployOpts } = await getOptions()
 | 
			
		||||
    deployOpts.props.ingressName = 'ingress-base'
 | 
			
		||||
    deployOpts.props.secretName = 'cert---docmirror-cn'
 | 
			
		||||
    deployOpts.context.tencentCertId = 'hNUZJrZf'
 | 
			
		||||
    const plugin = new DeployCertToTencentTKEIngress()
 | 
			
		||||
    const plugin = new DeployCertToTencentTKEIngress(options)
 | 
			
		||||
 | 
			
		||||
    const ret = await plugin.doExecute(deployOpts)
 | 
			
		||||
    console.log('sucess', ret)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,7 @@ const { expect } = pkg
 | 
			
		|||
describe('PluginUploadToTencent', function () {
 | 
			
		||||
  it('#execute', async function () {
 | 
			
		||||
    const options = createOptions()
 | 
			
		||||
    const plugin = new UploadCertToTencent()
 | 
			
		||||
    const plugin = new UploadCertToTencent(options)
 | 
			
		||||
    options.args = { test: false }
 | 
			
		||||
    options.cert.email = 'xiaojunnuo@qq.com'
 | 
			
		||||
    options.cert.domains = ['*.docmirror.cn']
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,12 @@
 | 
			
		|||
import { Executor } from '@certd/executor'
 | 
			
		||||
import PluginAliyun from '@certd/plugin-aliyun'
 | 
			
		||||
import PluginTencent from '@certd/plugin-tencent'
 | 
			
		||||
import PluginHost from '@certd/plugin-host'
 | 
			
		||||
import options from './options.json'
 | 
			
		||||
 | 
			
		||||
// 安装默认插件和授权提供者
 | 
			
		||||
PluginAliyun.install()
 | 
			
		||||
PluginTencent.install()
 | 
			
		||||
PluginHost.install()
 | 
			
		||||
const executor = new Executor()
 | 
			
		||||
executor.run(options)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3115,27 +3115,6 @@
 | 
			
		|||
            "webpack-sources": "^1.4.3"
 | 
			
		||||
          }
 | 
			
		||||
        },
 | 
			
		||||
        "vue-loader-v15": {
 | 
			
		||||
          "version": "npm:vue-loader@15.9.6",
 | 
			
		||||
          "resolved": "https://registry.npm.taobao.org/vue-loader/download/vue-loader-15.9.6.tgz?cache=0&sync_timestamp=1608188009078&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvue-loader%2Fdownload%2Fvue-loader-15.9.6.tgz",
 | 
			
		||||
          "integrity": "sha1-9Lua4gw6g3CvPs8JuBJtOP/ba4s=",
 | 
			
		||||
          "dev": true,
 | 
			
		||||
          "requires": {
 | 
			
		||||
            "@vue/component-compiler-utils": "^3.1.0",
 | 
			
		||||
            "hash-sum": "^1.0.2",
 | 
			
		||||
            "loader-utils": "^1.1.0",
 | 
			
		||||
            "vue-hot-reload-api": "^2.3.0",
 | 
			
		||||
            "vue-style-loader": "^4.1.0"
 | 
			
		||||
          },
 | 
			
		||||
          "dependencies": {
 | 
			
		||||
            "hash-sum": {
 | 
			
		||||
              "version": "1.0.2",
 | 
			
		||||
              "resolved": "https://registry.npm.taobao.org/hash-sum/download/hash-sum-1.0.2.tgz",
 | 
			
		||||
              "integrity": "sha1-M7QHd3VMZDJXPBIMw4CLvRDUfwQ=",
 | 
			
		||||
              "dev": true
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        },
 | 
			
		||||
        "webpack": {
 | 
			
		||||
          "version": "5.19.0",
 | 
			
		||||
          "resolved": "https://registry.npm.taobao.org/webpack/download/webpack-5.19.0.tgz",
 | 
			
		||||
| 
						 | 
				
			
			@ -17332,6 +17311,27 @@
 | 
			
		|||
        }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "vue-loader-v15": {
 | 
			
		||||
      "version": "npm:vue-loader@15.9.6",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-15.9.6.tgz",
 | 
			
		||||
      "integrity": "sha512-j0cqiLzwbeImIC6nVIby2o/ABAWhlppyL/m5oJ67R5MloP0hj/DtFgb0Zmq3J9CG7AJ+AXIvHVnJAPBvrLyuDg==",
 | 
			
		||||
      "dev": true,
 | 
			
		||||
      "requires": {
 | 
			
		||||
        "@vue/component-compiler-utils": "^3.1.0",
 | 
			
		||||
        "hash-sum": "^1.0.2",
 | 
			
		||||
        "loader-utils": "^1.1.0",
 | 
			
		||||
        "vue-hot-reload-api": "^2.3.0",
 | 
			
		||||
        "vue-style-loader": "^4.1.0"
 | 
			
		||||
      },
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "hash-sum": {
 | 
			
		||||
          "version": "1.0.2",
 | 
			
		||||
          "resolved": "https://registry.npmjs.org/hash-sum/-/hash-sum-1.0.2.tgz",
 | 
			
		||||
          "integrity": "sha1-M7QHd3VMZDJXPBIMw4CLvRDUfwQ=",
 | 
			
		||||
          "dev": true
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "vue-router": {
 | 
			
		||||
      "version": "4.0.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-4.0.3.tgz",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -138,5 +138,12 @@ const defaultOptions = {
 | 
			
		|||
_.merge(defaultOptions, optionsPrivate)
 | 
			
		||||
 | 
			
		||||
export function createOptions(){
 | 
			
		||||
  return _.cloneDeep(defaultOptions)
 | 
			
		||||
  return  _.cloneDeep(defaultOptions)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function getDnsProviderOptions (options) {
 | 
			
		||||
  if(!options){
 | 
			
		||||
    options = createOptions()
 | 
			
		||||
  }
 | 
			
		||||
  return { accessProviders: options.accessProviders, props: options.cert.dnsProvider }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue