From d4cbc601da0d7014f64aded7123df12ce941e3db Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:15:07 -0600 Subject: [PATCH] fix: return gateway maddr in .info response --- src/kubo/daemon.ts | 9 ++++++++- src/kubo/index.ts | 1 + test/controller.spec.ts | 21 +++++++++++++++++++++ test/endpoint/routes.node.ts | 2 ++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/kubo/daemon.ts b/src/kubo/daemon.ts index 4239e23e..73fc2394 100644 --- a/src/kubo/daemon.ts +++ b/src/kubo/daemon.ts @@ -27,6 +27,7 @@ export default class KuboDaemon implements KuboNode { private readonly disposable: boolean private subprocess?: ResultPromise private _api?: KuboRPCClient + private _gateway?: string private readonly repo: string private readonly stdout: Logger private readonly stderr: Logger @@ -91,7 +92,8 @@ export default class KuboDaemon implements KuboNode { peerId: id?.id.toString(), multiaddrs: (id?.addresses ?? []).map(ma => ma.toString()), api: checkForRunningApi(this.repo), - repo: this.repo + repo: this.repo, + gateway: this._gateway ?? '' } } @@ -202,11 +204,16 @@ export default class KuboDaemon implements KuboNode { const readyHandler = (data: Buffer): void => { output += data.toString() const apiMatch = output.trim().match(/API .*listening on:? (.*)/) + const gwMatch = output.trim().match(/Gateway .*listening on:? (.*)/) if ((apiMatch != null) && apiMatch.length > 0) { this._api = this.options.rpc(apiMatch[1]) } + if ((gwMatch != null) && gwMatch.length > 0) { + this._gateway = gwMatch[1] + } + if (output.match(/(?:daemon is running|Daemon is ready)/) != null) { // we're good stdout.off('data', readyHandler) diff --git a/src/kubo/index.ts b/src/kubo/index.ts index fc9b8dfb..705acb4e 100644 --- a/src/kubo/index.ts +++ b/src/kubo/index.ts @@ -75,6 +75,7 @@ export interface KuboInfo { multiaddrs: string[] api?: string repo: string + gateway: string } export interface KuboNode extends Node { diff --git a/test/controller.spec.ts b/test/controller.spec.ts index 3df630f8..36fb58c2 100644 --- a/test/controller.spec.ts +++ b/test/controller.spec.ts @@ -208,4 +208,25 @@ describe('Node API', function () { } }) }) + + describe('info', () => { + describe('should return the node info', () => { + for (const opts of types) { + it(`type: ${opts.type} remote: ${Boolean(opts.remote)}`, async () => { + const node = await factory.spawn(opts) + const info = await node.info() + + expect(info).to.have.property('version').that.is.a('string') + expect(info).to.have.property('api').that.is.a('string') + expect(info).to.have.property('peerId').that.is.a('string') + expect(info).to.have.property('repo').that.is.a('string') + expect(info).to.have.property('pid').that.is.a('number') + expect(info).to.have.property('multiaddrs').that.is.an('array') + expect(info).to.have.property('gateway').that.is.a('string').that.matches(/\/ip4\/127\.0\.0\.1\/tcp\/\d+/) + + await node.stop() + }) + } + }) + }) }) diff --git a/test/endpoint/routes.node.ts b/test/endpoint/routes.node.ts index f73212be..281306e0 100644 --- a/test/endpoint/routes.node.ts +++ b/test/endpoint/routes.node.ts @@ -109,6 +109,8 @@ describe('routes', function () { expect(res.result).to.have.property('api').that.is.a('string') expect(res.result).to.have.property('repo').that.is.a('string') expect(res.result).to.have.property('multiaddrs').that.is.an('array') + expect(res.result).to.have.property('peerId').that.is.a('string') + expect(res.result).to.have.property('gateway').that.is.a('string') }) it('should return 400', async () => {