-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazureManagement.js
48 lines (38 loc) · 1.4 KB
/
azureManagement.js
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
import { SubscriptionClient } from '@azure/arm-resources-subscriptions';
import { BlobServiceClient } from '@azure/storage-blob';
import { storageInformation } from './authConfig';
/**
* Returns a subscription client object with the provided token acquisition options
*/
export const getSubscriptionClient = async (accessToken) => {
const credential = new StaticTokenCredential({
token: accessToken,
expiresOnTimestamp: accessToken.exp
});
const client = new SubscriptionClient(credential);
return client;
};
/**
* Returns a blob service client object with the provided token acquisition options
*/
export const getBlobServiceClient = async (accessToken) => {
const credential = new StaticTokenCredential({
token: accessToken,
expiresOnTimestamp: accessToken.exp,
});
const client = new BlobServiceClient(`https://${storageInformation.accountName}.blob.core.windows.net`, credential);
return client;
};
/**
* StaticTokenCredential implements the TokenCredential abstraction.
* It takes a pre-fetched access token in its constructor as an AccessTokhttps://docs.microsoft.com/javascript/api/@azure/core-auth/accesstoken)
* and returns that from its implementation of `getToken()`.
*/
class StaticTokenCredential {
constructor(accessToken) {
this.accessToken = accessToken;
}
async getToken() {
return this.accessToken;
}
}