feat(xen-api): configurable transport
Related to zammad#14008 Possible value for the `transport` setting: `auto`, `json-rpc`, `xml-rpc`.
This commit is contained in:
@@ -13,7 +13,6 @@ import { Index } from 'xo-collection/index'
|
||||
import { cancelable, defer, fromCallback, ignoreErrors, pDelay, pRetry, pTimeout } from 'promise-toolbox'
|
||||
import { limitConcurrency } from 'limit-concurrency-decorator'
|
||||
|
||||
import autoTransport from './transports/auto'
|
||||
import debug from './_debug'
|
||||
import getTaskResult from './_getTaskResult'
|
||||
import isGetAllRecordsMethod from './_isGetAllRecordsMethod'
|
||||
@@ -22,6 +21,7 @@ import makeCallSetting from './_makeCallSetting'
|
||||
import parseUrl from './_parseUrl'
|
||||
import Ref from './_Ref'
|
||||
import replaceSensitiveValues from './_replaceSensitiveValues'
|
||||
import transports from './transports'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
@@ -90,6 +90,13 @@ export class Xapi extends EventEmitter {
|
||||
constructor(opts) {
|
||||
super()
|
||||
|
||||
const { transport = 'auto' } = opts
|
||||
const createTransport = transports[transport]
|
||||
if (createTransport === undefined) {
|
||||
throw new Error('invalid transport: ' + transport)
|
||||
}
|
||||
this._createTransport = createTransport
|
||||
|
||||
this._addSyncStackTrace =
|
||||
opts.syncStackTraces ?? process.env.NODE_ENV === 'development' ? addSyncStackTrace : identity
|
||||
this._callTimeout = makeCallSetting(opts.callTimeout, 60 * 60 * 1e3) // 1 hour but will be reduced in the future
|
||||
@@ -939,7 +946,7 @@ export class Xapi extends EventEmitter {
|
||||
|
||||
_setUrl(url) {
|
||||
this._humanId = `${this._auth.user ?? 'unknown'}@${url.hostname}`
|
||||
this._transport = autoTransport({
|
||||
this._transport = this._createTransport({
|
||||
secureOptions: {
|
||||
minVersion: 'TLSv1',
|
||||
rejectUnauthorized: !this._allowUnauthorized,
|
||||
|
||||
11
packages/xen-api/src/transports/index.js
Normal file
11
packages/xen-api/src/transports/index.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import auto from './auto.js'
|
||||
import jsonRpc from './json-rpc.js'
|
||||
import xmlRpc from './xml-rpc.js'
|
||||
|
||||
export default {
|
||||
__proto__: null,
|
||||
|
||||
auto,
|
||||
'json-rpc': jsonRpc,
|
||||
'xml-rpc': xmlRpc,
|
||||
}
|
||||
Reference in New Issue
Block a user