Skip to content

Commit

Permalink
fix: Helper functions for Service Bus namespace ingredient (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinreillyhchb authored and whilke committed Jun 7, 2019
1 parent f954ebb commit fc68cf8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ingredient/ingredient-service-bus-namespace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"@types/node": "^10.12.18"
},
"dependencies": {
"@azbake/arm-helper": "^0.1.47"
"@azbake/arm-helper": "^0.1.47",
"@azure/arm-servicebus": "^3.2.0"
},
"publishConfig": {
"access": "public"
Expand Down
64 changes: 63 additions & 1 deletion ingredient/ingredient-service-bus-namespace/src/functions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,72 @@
import {BaseUtility, IngredientManager} from '@azbake/core'
import { ServiceBusManagementClient } from "@azure/arm-servicebus";

export class ServiceBusNamespaceUtils extends BaseUtility {

public create_resource_name(): string {
let util = IngredientManager.getIngredientFunction("coreutils", this.context)
let util = IngredientManager.getIngredientFunction("coreutils", this.context);
const name = util.create_resource_name("sbn", null, false);
return name;
}

public async get_endpoint(nsName: string, rg: string | null = null): Promise<string> {

let util = IngredientManager.getIngredientFunction("coreutils", this.context);
let resource_group = rg || await util.resource_group();

const client = new ServiceBusManagementClient(this.context.AuthToken, this.context.Environment.authentication.subscriptionId);

let response = await client.namespaces.get(resource_group, nsName);
// client.namespaces.listKeys(resource_group,)

return response.serviceBusEndpoint || "";
}

public async get_primary_key(nsName: string, authRuleName: string, rg: string | null = null) : Promise<string> {

let util = IngredientManager.getIngredientFunction("coreutils", this.context);
let resource_group = rg || await util.resource_group();

const client = new ServiceBusManagementClient(this.context.AuthToken, this.context.Environment.authentication.subscriptionId);

let response = await client.namespaces.listKeys(resource_group, nsName, authRuleName);

return response.primaryKey || "";
}

public async get_secondary_key(nsName: string, authRuleName: string, rg: string | null = null) : Promise<string> {

let util = IngredientManager.getIngredientFunction("coreutils", this.context);
let resource_group = rg || await util.resource_group();

const client = new ServiceBusManagementClient(this.context.AuthToken, this.context.Environment.authentication.subscriptionId);

let response = await client.namespaces.listKeys(resource_group, nsName, authRuleName);

return response.secondaryKey || "";
}

public async get_primary_connection_string(nsName: string, authRuleName: string, rg: string | null = null) : Promise<string> {

let util = IngredientManager.getIngredientFunction("coreutils", this.context);
let resource_group = rg || await util.resource_group();

const client = new ServiceBusManagementClient(this.context.AuthToken, this.context.Environment.authentication.subscriptionId);

let response = await client.namespaces.listKeys(resource_group, nsName, authRuleName);

return response.primaryConnectionString || "";
}

public async get_secondary_connection_string(nsName: string, authRuleName: string, rg: string | null = null) : Promise<string> {

let util = IngredientManager.getIngredientFunction("coreutils", this.context);
let resource_group = rg || await util.resource_group();

const client = new ServiceBusManagementClient(this.context.AuthToken, this.context.Environment.authentication.subscriptionId);

let response = await client.namespaces.listKeys(resource_group, nsName, authRuleName);

return response.secondaryConnectionString || "";
}
}
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fc68cf8

Please sign in to comment.