Skip to content

Commit a752f8a

Browse files
authored
Merge pull request #75 from bioinformatics-ua/imp/service-hostname_6
Extend API with service hostname support (v6.x)
2 parents 01ce3df + cb84e6a commit a752f8a

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

src/service.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export interface ServiceConfiguration {
2929
autostart?: boolean,
3030
/** the TCP port that the service should listen to */
3131
port?: number,
32+
/** the hostname that the service should bind to
33+
*
34+
* _Note:_ Available since Dicoogle 3.5.0
35+
*/
36+
hostname?: string,
3237
}
3338

3439
/** Full status of the DICOM service. */
@@ -39,6 +44,11 @@ export interface ServiceStatus {
3944
autostart: boolean,
4045
/** the TCP port that the service listens to */
4146
port: number,
47+
/** the hostname that the service is bound to
48+
*
49+
* _Note:_ Available since Dicoogle 3.5.0
50+
*/
51+
hostname?: string,
4252
}
4353

4454
/** A DICOM service change outcome object,
@@ -52,15 +62,15 @@ export interface ServiceChangeOutcome extends ServiceConfiguration {
5262
}
5363

5464
export interface RemoteStorage {
55-
/// {string} aetitle
65+
/** called AE title of the remote DICOM node */
5666
aetitle: string,
57-
/// {string} ip
67+
/** IP address or hostname of the remote DICOM node */
5868
ip: string,
59-
/// {number} port
69+
/** TCP port to the remote DICOM node */
6070
port: number,
61-
/// {?string} description
71+
/** Free text description of the DICOM node */
6272
description?: string,
63-
/// {?boolean} public
73+
/** Whether the DICOM node is public */
6474
public?: boolean,
6575
}
6676

@@ -95,9 +105,9 @@ class BaseService {
95105
* @param callback the callback function
96106
*/
97107
configure(config: ServiceConfiguration, callback?: (error: Error | null, outcome: ServiceChangeOutcome | undefined) => void): Promise<ServiceChangeOutcome> {
98-
const {running, autostart, port} = config;
108+
const {running, autostart, port, hostname} = config;
99109
return andCall(this._socket.post(this._endpoint)
100-
.query({running, autostart, port})
110+
.query({running, autostart, hostname, port})
101111
.then((resp) => resp.body), callback);
102112
}
103113

test/base-promise.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,15 @@ describe('Dicoogle Client, Promise API (under Node.js)', function() {
392392
it("should give no error", async function() {
393393
await dicoogle.queryRetrieve.configure({
394394
autostart: true,
395+
hostname: '127.1',
395396
port: 7777
396397
});
397398
});
398399
it("and {autostart, port} changes", async function() {
399400
const data = await dicoogle.queryRetrieve.getStatus();
400401
assert.strictEqual(data.autostart, true);
401402
assert.strictEqual(data.port, 7777);
403+
assert.strictEqual(data.hostname, '127.1');
402404
});
403405
});
404406

test/mock/service-mock.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ export default function createDicoogleMock(port = 8080): ReturnType<typeof dicoo
185185
const QR = {
186186
isRunning: true,
187187
autostart: false,
188-
port: 1045
188+
port: 1045,
189+
hostname: undefined
189190
};
190191
let TaskClosed = false;
191192
let TaskStopped = false;
@@ -505,18 +506,27 @@ export default function createDicoogleMock(port = 8080): ReturnType<typeof dicoo
505506
error: "Incomplete configurations"
506507
})
507508
.post('/management/dicom/query')
508-
.query({
509-
autostart: true,
510-
port: 7777
511-
})
509+
.query((query) => !!(query.autostart || query.port || query.hostname))
512510
.reply(200, function() {
513-
QR.autostart = true;
514-
QR.port = 7777;
515-
return {
511+
// pass whatever is in the query parameters
512+
const {query} = URL.parse(this.req.path, true);
513+
const out: {[key: string]: string | boolean | number} = {
516514
success: true,
517-
autostart: true,
518-
port: 7777
519515
};
516+
517+
if (query.autostart) {
518+
QR.autostart = query.autostart == 'true';
519+
out.autostart = QR.autostart;
520+
}
521+
if (query.port) {
522+
QR.port = +query.port;
523+
out.port = QR.port;
524+
}
525+
if (query.hostname) {
526+
QR.hostname = query.hostname ? query.hostname : undefined;
527+
out.hostname = QR.hostname;
528+
}
529+
return out;
520530
})
521531

522532

0 commit comments

Comments
 (0)