-
Notifications
You must be signed in to change notification settings - Fork 14
/
functions.ts
66 lines (45 loc) · 2.3 KB
/
functions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import {BaseUtility, IngredientManager} from '@azbake/core'
import { StorageManagementClient } from '@azure/arm-storage'
export class StorageUtils extends BaseUtility {
public create_resource_name(): string {
let util = IngredientManager.getIngredientFunction("coreutils", this.context)
const st_profile = util.create_resource_name("st", null, false);
return st_profile;
}
public async get_primary_key(name: 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 StorageManagementClient(this.context.AuthToken, this.context.Environment.authentication.subscriptionId);
let response = await client.storageAccounts.listKeys(resource_group, name)
let key: string = ""
if (response.keys)
{
key = response.keys[0].value || ""
}
return key
}
public async get_secondary_key(name: 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 StorageManagementClient(this.context.AuthToken, this.context.Environment.authentication.subscriptionId);
let response = await client.storageAccounts.listKeys(resource_group, name)
let key: string = ""
if (response.keys)
{
key = response.keys[1].value || ""
}
return key
}
public async get_primary_connectionstring(name: string, rg: string | null = null) : Promise<string> {
let key: string = ""
key = await this.get_primary_key(name, rg);
let connectionString = `DefaultEndpointsProtocol=https;AccountName=${name};AccountKey=${key};`
return connectionString;
}
public async get_secondary_connectionstring(name: string, rg: string | null = null) : Promise<string> {
let key: string = ""
key = await this.get_secondary_key(name, rg);
let connectionString = `DefaultEndpointsProtocol=https;AccountName=${name};AccountKey=${key};`
return connectionString;
}
}