From 68a7dd80ec4baa29f3af2d1e670152666a4586b6 Mon Sep 17 00:00:00 2001 From: John Watson <42574977+johnwatson484@users.noreply.github.com> Date: Mon, 14 Nov 2022 19:09:19 +0000 Subject: [PATCH] Add client (#23) --- app/messaging/admin-client.js | 30 ++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 app/messaging/admin-client.js diff --git a/app/messaging/admin-client.js b/app/messaging/admin-client.js new file mode 100644 index 0000000..8202ea7 --- /dev/null +++ b/app/messaging/admin-client.js @@ -0,0 +1,30 @@ +const { ServiceBusAdministrationClient } = require('@azure/service-bus') +const { DefaultAzureCredential } = require('@azure/identity') + +class AdminClient { + constructor (config) { + this.connectionName = config.name || config.address + this.appInsights = config.appInsights + this.config = config + this.connect() + } + + connect () { + if (this.config.useCredentialChain) { + const credentials = this.getCredentials() + this.sbClient = new ServiceBusAdministrationClient(this.config.host, credentials) + } else { + this.sbClient = new ServiceBusAdministrationClient(`Endpoint=sb://${this.config.host}/;SharedAccessKeyName=${this.config.username};SharedAccessKey=${this.config.password}`) + } + } + + getCredentials () { + return new DefaultAzureCredential() + } + + async getClient () { + return this.sbClient + } +} + +module.exports = AdminClient diff --git a/package.json b/package.json index 331dbf4..be0b522 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ffc-messaging", - "version": "2.5.2", + "version": "2.6.0", "description": "Messaging npm module for FFC services", "main": "index.js", "repository": {