Attempt 2
This commit is contained in:
@@ -149,36 +149,6 @@ export function bareHolesailManagedNormalizeEntry(raw) {
|
||||
return { ok: true, entry }
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip Bare-managed fields (e.g. `enabled`) and pass only upstream holesail constructor options.
|
||||
* @param {Record<string, unknown>} entry normalized row from {@link bareHolesailManagedNormalizeEntry}
|
||||
* @returns {Record<string, unknown>}
|
||||
*/
|
||||
export function bareHolesailManagedEntryToOpts(entry) {
|
||||
const e = /** @type {Record<string, unknown>} */ (entry)
|
||||
/** @type {Record<string, unknown>} */
|
||||
const opts = {
|
||||
server: !!e.server,
|
||||
client: !!e.client
|
||||
}
|
||||
if (e.port != null && e.port !== '') opts.port = e.port
|
||||
const host = String(e.host ?? '').trim()
|
||||
if (host) opts.host = host
|
||||
const key = String(e.key ?? '').trim()
|
||||
if (key) opts.key = key
|
||||
if (e.secure !== undefined && e.secure !== null && String(e.secure) !== '')
|
||||
opts.secure = bareHolesailEnvTruthy(e.secure)
|
||||
if (e.udp !== undefined && e.udp !== null && String(e.udp) !== '')
|
||||
opts.udp = bareHolesailEnvTruthy(e.udp)
|
||||
if (e.log !== undefined && e.log !== null && e.log !== '') {
|
||||
if (typeof e.log === 'number') opts.log = e.log
|
||||
else if (/^\d+$/.test(String(e.log)))
|
||||
opts.log = Number.parseInt(String(e.log), 10)
|
||||
else opts.log = bareHolesailEnvTruthy(e.log)
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare persisted shareable URL / key string to live `hs.info.url` (case-insensitive trim).
|
||||
* @param {string} persisted
|
||||
@@ -391,7 +361,30 @@ async function startManagedInstance(ctx, env, id, entry) {
|
||||
}
|
||||
|
||||
const Holesail = await loadHolesailConstructor(ctx)
|
||||
const hs = new Holesail(bareHolesailManagedEntryToOpts(norm.entry))
|
||||
const conn = norm.entry
|
||||
/** @type {number | boolean} */
|
||||
let logLevel = 1
|
||||
if (conn.log !== undefined && conn.log !== null && conn.log !== '') {
|
||||
if (typeof conn.log === 'number') logLevel = conn.log
|
||||
else if (/^\d+$/.test(String(conn.log)))
|
||||
logLevel = Number.parseInt(String(conn.log), 10)
|
||||
else logLevel = bareHolesailEnvTruthy(conn.log)
|
||||
}
|
||||
/** Fields mirror `state.json` connection rows; `enabled` stays on the row only (not passed to holesail). */
|
||||
/** @type {Record<string, unknown>} */
|
||||
const cfg = {
|
||||
server: conn.server,
|
||||
client: conn.client,
|
||||
port: conn.port,
|
||||
host: conn.host,
|
||||
key: conn.key,
|
||||
log: logLevel
|
||||
}
|
||||
if (conn.secure !== undefined && conn.secure !== null && String(conn.secure) !== '')
|
||||
cfg.secure = bareHolesailEnvTruthy(conn.secure)
|
||||
if (conn.udp !== undefined && conn.udp !== null && String(conn.udp) !== '')
|
||||
cfg.udp = bareHolesailEnvTruthy(conn.udp)
|
||||
const hs = new Holesail(cfg)
|
||||
await hs.ready()
|
||||
managedInstances.set(id, { hs, entry: norm.entry })
|
||||
if (norm.entry.server) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import test from 'brittle'
|
||||
import {
|
||||
BARE_HOLESAIL_STATE_USER,
|
||||
bareHolesailManagedEntryToOpts,
|
||||
bareHolesailManagedEnvForConnectionId,
|
||||
bareHolesailManagedNormalizeEntry,
|
||||
bareHolesailManagedPersistedUrlMatchesLive,
|
||||
@@ -64,30 +63,6 @@ test('bareHolesailManagedNormalizeEntry client needs key', (t) => {
|
||||
t.absent(r.ok)
|
||||
})
|
||||
|
||||
test('bareHolesailManagedEntryToOpts strips enabled and passes holesail fields', (t) => {
|
||||
const r = bareHolesailManagedNormalizeEntry({
|
||||
server: true,
|
||||
port: 8088,
|
||||
host: '127.0.0.1',
|
||||
key: 'hs://0000abc',
|
||||
secure: true,
|
||||
udp: true,
|
||||
log: 0,
|
||||
enabled: false
|
||||
})
|
||||
t.ok(r.ok)
|
||||
const o = bareHolesailManagedEntryToOpts(r.entry)
|
||||
t.is(o.server, true)
|
||||
t.is(o.client, false)
|
||||
t.is(o.port, 8088)
|
||||
t.is(o.host, '127.0.0.1')
|
||||
t.is(o.key, 'hs://0000abc')
|
||||
t.is(o.secure, true)
|
||||
t.is(o.udp, true)
|
||||
t.is(o.log, 0)
|
||||
t.absent(Object.prototype.hasOwnProperty.call(o, 'enabled'))
|
||||
})
|
||||
|
||||
test('bareHolesailManagedPersistedUrlMatchesLive', (t) => {
|
||||
const u = 'hs://0000aaaabbbbccccddddeeeeffffgggg'
|
||||
t.ok(bareHolesailManagedPersistedUrlMatchesLive(u, u))
|
||||
|
||||
Reference in New Issue
Block a user