@microsoft/vscode-azext-azureauth 2.3.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,297 +1,297 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
- * Licensed under the MIT License. See License.txt in the project root for license information.
5
- *--------------------------------------------------------------------------------------------*/
6
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
- return new (P || (P = Promise))(function (resolve, reject) {
9
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
- step((generator = generator.apply(thisArg, _arguments || [])).next());
13
- });
14
- };
15
- var __asyncValues = (this && this.__asyncValues) || function (o) {
16
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
17
- var m = o[Symbol.asyncIterator], i;
18
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
19
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
20
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.VSCodeAzureSubscriptionProvider = void 0;
24
- const vscode = require("vscode");
25
- const NotSignedInError_1 = require("./NotSignedInError");
26
- const getSessionFromVSCode_1 = require("./getSessionFromVSCode");
27
- const configuredAzureEnv_1 = require("./utils/configuredAzureEnv");
28
- const EventDebounce = 5 * 1000; // 5 seconds
29
- /**
30
- * A class for obtaining Azure subscription information using VSCode's built-in authentication
31
- * provider.
32
- */
33
- class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
34
- constructor() {
35
- const disposable = vscode.authentication.onDidChangeSessions((e) => __awaiter(this, void 0, void 0, function* () {
36
- // Ignore any sign in that isn't for the configured auth provider
37
- if (e.provider.id !== (0, configuredAzureEnv_1.getConfiguredAuthProviderId)()) {
38
- return;
39
- }
40
- if (yield this.isSignedIn()) {
41
- if (!this.suppressSignInEvents && Date.now() > this.lastSignInEventFired + EventDebounce) {
42
- this.lastSignInEventFired = Date.now();
43
- this.onDidSignInEmitter.fire();
44
- }
45
- }
46
- else if (Date.now() > this.lastSignOutEventFired + EventDebounce) {
47
- this.lastSignOutEventFired = Date.now();
48
- this.onDidSignOutEmitter.fire();
49
- }
50
- }));
51
- super(() => {
52
- this.onDidSignInEmitter.dispose();
53
- this.onDidSignOutEmitter.dispose();
54
- disposable.dispose();
55
- });
56
- this.onDidSignInEmitter = new vscode.EventEmitter();
57
- this.lastSignInEventFired = 0;
58
- this.suppressSignInEvents = false;
59
- this.onDidSignOutEmitter = new vscode.EventEmitter();
60
- this.lastSignOutEventFired = 0;
61
- /**
62
- * An event that is fired when the user signs in. Debounced to fire at most once every 5 seconds.
63
- */
64
- this.onDidSignIn = this.onDidSignInEmitter.event;
65
- /**
66
- * An event that is fired when the user signs out. Debounced to fire at most once every 5 seconds.
67
- */
68
- this.onDidSignOut = this.onDidSignOutEmitter.event;
69
- }
70
- /**
71
- * Gets a list of tenants available to the user.
72
- * Use {@link isSignedIn} to check if the user is signed in to a particular tenant.
73
- *
74
- * @returns A list of tenants.
75
- */
76
- getTenants() {
77
- var _a, e_1, _b, _c;
78
- return __awaiter(this, void 0, void 0, function* () {
79
- const { client } = yield this.getSubscriptionClient();
80
- const results = [];
81
- try {
82
- for (var _d = true, _e = __asyncValues(client.tenants.list()), _f; _f = yield _e.next(), _a = _f.done, !_a;) {
83
- _c = _f.value;
84
- _d = false;
85
- try {
86
- const tenant = _c;
87
- results.push(tenant);
88
- }
89
- finally {
90
- _d = true;
91
- }
92
- }
93
- }
94
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
95
- finally {
96
- try {
97
- if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
98
- }
99
- finally { if (e_1) throw e_1.error; }
100
- }
101
- return results;
102
- });
103
- }
104
- /**
105
- * Gets a list of Azure subscriptions available to the user.
106
- *
107
- * @param filter - Whether to filter the list returned, according to the list returned
108
- * by `getTenantFilters()` and `getSubscriptionFilters()`. Optional, default true.
109
- *
110
- * @returns A list of Azure subscriptions.
111
- *
112
- * @throws A {@link NotSignedInError} If the user is not signed in to Azure.
113
- * Use {@link isSignedIn} and/or {@link signIn} before this method to ensure
114
- * the user is signed in.
115
- */
116
- getSubscriptions(filter = true) {
117
- return __awaiter(this, void 0, void 0, function* () {
118
- const tenantIds = yield this.getTenantFilters();
119
- const shouldFilterTenants = filter && !!tenantIds.length; // If the list is empty it is treated as "no filter"
120
- const results = [];
121
- try {
122
- this.suppressSignInEvents = true;
123
- // Get the list of tenants
124
- for (const tenant of yield this.getTenants()) {
125
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
126
- const tenantId = tenant.tenantId;
127
- // If filtering is enabled, and the current tenant is not in that list, then skip it
128
- if (shouldFilterTenants && !tenantIds.includes(tenantId)) {
129
- continue;
130
- }
131
- // If the user is not signed in to this tenant, then skip it
132
- if (!(yield this.isSignedIn(tenantId))) {
133
- continue;
134
- }
135
- // For each tenant, get the list of subscriptions
136
- results.push(...yield this.getSubscriptionsForTenant(tenantId));
137
- }
138
- }
139
- finally {
140
- this.suppressSignInEvents = false;
141
- }
142
- const sortSubscriptions = (subscriptions) => subscriptions.sort((a, b) => a.name.localeCompare(b.name));
143
- const subscriptionIds = yield this.getSubscriptionFilters();
144
- if (filter && !!subscriptionIds.length) { // If the list is empty it is treated as "no filter"
145
- return sortSubscriptions(results.filter(sub => subscriptionIds.includes(sub.subscriptionId)));
146
- }
147
- return sortSubscriptions(results);
148
- });
149
- }
150
- /**
151
- * Checks to see if a user is signed in.
152
- *
153
- * @param tenantId (Optional) Provide to check if a user is signed in to a specific tenant.
154
- *
155
- * @returns True if the user is signed in, false otherwise.
156
- */
157
- isSignedIn(tenantId) {
158
- return __awaiter(this, void 0, void 0, function* () {
159
- const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)([], tenantId, { createIfNone: false, silent: true });
160
- return !!session;
161
- });
162
- }
163
- /**
164
- * Asks the user to sign in or pick an account to use.
165
- *
166
- * @param tenantId (Optional) Provide to sign in to a specific tenant.
167
- *
168
- * @returns True if the user is signed in, false otherwise.
169
- */
170
- signIn(tenantId) {
171
- return __awaiter(this, void 0, void 0, function* () {
172
- const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)([], tenantId, { createIfNone: true, clearSessionPreference: true });
173
- return !!session;
174
- });
175
- }
176
- /**
177
- * Signs the user out
178
- *
179
- * @deprecated Not currently supported by VS Code auth providers
180
- */
181
- signOut() {
182
- throw new Error(vscode.l10n.t('Signing out programmatically is not supported. You must sign out by selecting the account in the Accounts menu and choosing Sign Out.'));
183
- }
184
- /**
185
- * Gets the tenant filters that are configured in `azureResourceGroups.selectedSubscriptions`. To
186
- * override the settings with a custom filter, implement a child class with `getSubscriptionFilters()`
187
- * and/or `getTenantFilters()` overridden.
188
- *
189
- * If no values are returned by `getTenantFilters()`, then all tenants will be scanned for subscriptions.
190
- *
191
- * @returns A list of tenant IDs that are configured in `azureResourceGroups.selectedSubscriptions`.
192
- */
193
- getTenantFilters() {
194
- return __awaiter(this, void 0, void 0, function* () {
195
- const config = vscode.workspace.getConfiguration('azureResourceGroups');
196
- const fullSubscriptionIds = config.get('selectedSubscriptions', []);
197
- return fullSubscriptionIds.map(id => id.split('/')[0]);
198
- });
199
- }
200
- /**
201
- * Gets the subscription filters that are configured in `azureResourceGroups.selectedSubscriptions`. To
202
- * override the settings with a custom filter, implement a child class with `getSubscriptionFilters()`
203
- * and/or `getTenantFilters()` overridden.
204
- *
205
- * If no values are returned by `getSubscriptionFilters()`, then all subscriptions will be returned.
206
- *
207
- * @returns A list of subscription IDs that are configured in `azureResourceGroups.selectedSubscriptions`.
208
- */
209
- getSubscriptionFilters() {
210
- return __awaiter(this, void 0, void 0, function* () {
211
- const config = vscode.workspace.getConfiguration('azureResourceGroups');
212
- const fullSubscriptionIds = config.get('selectedSubscriptions', []);
213
- return fullSubscriptionIds.map(id => id.split('/')[1]);
214
- });
215
- }
216
- /**
217
- * Gets the subscriptions for a given tenant.
218
- *
219
- * @param tenantId The tenant ID to get subscriptions for.
220
- *
221
- * @returns The list of subscriptions for the tenant.
222
- */
223
- getSubscriptionsForTenant(tenantId) {
224
- var _a, e_2, _b, _c;
225
- return __awaiter(this, void 0, void 0, function* () {
226
- const { client, credential, authentication } = yield this.getSubscriptionClient(tenantId);
227
- const environment = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
228
- const subscriptions = [];
229
- try {
230
- for (var _d = true, _e = __asyncValues(client.subscriptions.list()), _f; _f = yield _e.next(), _a = _f.done, !_a;) {
231
- _c = _f.value;
232
- _d = false;
233
- try {
234
- const subscription = _c;
235
- subscriptions.push({
236
- authentication: authentication,
237
- environment: environment,
238
- credential: credential,
239
- isCustomCloud: environment.isCustomCloud,
240
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
241
- name: subscription.displayName,
242
- subscriptionId: subscription.subscriptionId,
243
- /* eslint-enable @typescript-eslint/no-non-null-assertion */
244
- tenantId: tenantId,
245
- });
246
- }
247
- finally {
248
- _d = true;
249
- }
250
- }
251
- }
252
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
253
- finally {
254
- try {
255
- if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
256
- }
257
- finally { if (e_2) throw e_2.error; }
258
- }
259
- return subscriptions;
260
- });
261
- }
262
- /**
263
- * Gets a fully-configured subscription client for a given tenant ID
264
- *
265
- * @param tenantId (Optional) The tenant ID to get a client for
266
- *
267
- * @returns A client, the credential used by the client, and the authentication function
268
- */
269
- getSubscriptionClient(tenantId, scopes) {
270
- return __awaiter(this, void 0, void 0, function* () {
271
- const armSubs = yield Promise.resolve().then(() => require('@azure/arm-resources-subscriptions'));
272
- const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true });
273
- if (!session) {
274
- throw new NotSignedInError_1.NotSignedInError();
275
- }
276
- const credential = {
277
- getToken: () => __awaiter(this, void 0, void 0, function* () {
278
- return {
279
- token: session.accessToken,
280
- expiresOnTimestamp: 0
281
- };
282
- })
283
- };
284
- const configuredAzureEnv = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
285
- const endpoint = configuredAzureEnv.resourceManagerEndpointUrl;
286
- return {
287
- client: new armSubs.SubscriptionClient(credential, { endpoint }),
288
- credential: credential,
289
- authentication: {
290
- getSession: () => session
291
- }
292
- };
293
- });
294
- }
295
- }
296
- exports.VSCodeAzureSubscriptionProvider = VSCodeAzureSubscriptionProvider;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License. See License.txt in the project root for license information.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
16
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
17
+ var m = o[Symbol.asyncIterator], i;
18
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
19
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
20
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.VSCodeAzureSubscriptionProvider = void 0;
24
+ const vscode = require("vscode");
25
+ const NotSignedInError_1 = require("./NotSignedInError");
26
+ const getSessionFromVSCode_1 = require("./getSessionFromVSCode");
27
+ const configuredAzureEnv_1 = require("./utils/configuredAzureEnv");
28
+ const EventDebounce = 5 * 1000; // 5 seconds
29
+ /**
30
+ * A class for obtaining Azure subscription information using VSCode's built-in authentication
31
+ * provider.
32
+ */
33
+ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
34
+ constructor() {
35
+ const disposable = vscode.authentication.onDidChangeSessions((e) => __awaiter(this, void 0, void 0, function* () {
36
+ // Ignore any sign in that isn't for the configured auth provider
37
+ if (e.provider.id !== (0, configuredAzureEnv_1.getConfiguredAuthProviderId)()) {
38
+ return;
39
+ }
40
+ if (yield this.isSignedIn()) {
41
+ if (!this.suppressSignInEvents && Date.now() > this.lastSignInEventFired + EventDebounce) {
42
+ this.lastSignInEventFired = Date.now();
43
+ this.onDidSignInEmitter.fire();
44
+ }
45
+ }
46
+ else if (Date.now() > this.lastSignOutEventFired + EventDebounce) {
47
+ this.lastSignOutEventFired = Date.now();
48
+ this.onDidSignOutEmitter.fire();
49
+ }
50
+ }));
51
+ super(() => {
52
+ this.onDidSignInEmitter.dispose();
53
+ this.onDidSignOutEmitter.dispose();
54
+ disposable.dispose();
55
+ });
56
+ this.onDidSignInEmitter = new vscode.EventEmitter();
57
+ this.lastSignInEventFired = 0;
58
+ this.suppressSignInEvents = false;
59
+ this.onDidSignOutEmitter = new vscode.EventEmitter();
60
+ this.lastSignOutEventFired = 0;
61
+ /**
62
+ * An event that is fired when the user signs in. Debounced to fire at most once every 5 seconds.
63
+ */
64
+ this.onDidSignIn = this.onDidSignInEmitter.event;
65
+ /**
66
+ * An event that is fired when the user signs out. Debounced to fire at most once every 5 seconds.
67
+ */
68
+ this.onDidSignOut = this.onDidSignOutEmitter.event;
69
+ }
70
+ /**
71
+ * Gets a list of tenants available to the user.
72
+ * Use {@link isSignedIn} to check if the user is signed in to a particular tenant.
73
+ *
74
+ * @returns A list of tenants.
75
+ */
76
+ getTenants() {
77
+ var _a, e_1, _b, _c;
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const { client } = yield this.getSubscriptionClient();
80
+ const results = [];
81
+ try {
82
+ for (var _d = true, _e = __asyncValues(client.tenants.list()), _f; _f = yield _e.next(), _a = _f.done, !_a;) {
83
+ _c = _f.value;
84
+ _d = false;
85
+ try {
86
+ const tenant = _c;
87
+ results.push(tenant);
88
+ }
89
+ finally {
90
+ _d = true;
91
+ }
92
+ }
93
+ }
94
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
95
+ finally {
96
+ try {
97
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
98
+ }
99
+ finally { if (e_1) throw e_1.error; }
100
+ }
101
+ return results;
102
+ });
103
+ }
104
+ /**
105
+ * Gets a list of Azure subscriptions available to the user.
106
+ *
107
+ * @param filter - Whether to filter the list returned, according to the list returned
108
+ * by `getTenantFilters()` and `getSubscriptionFilters()`. Optional, default true.
109
+ *
110
+ * @returns A list of Azure subscriptions.
111
+ *
112
+ * @throws A {@link NotSignedInError} If the user is not signed in to Azure.
113
+ * Use {@link isSignedIn} and/or {@link signIn} before this method to ensure
114
+ * the user is signed in.
115
+ */
116
+ getSubscriptions(filter = true) {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ const tenantIds = yield this.getTenantFilters();
119
+ const shouldFilterTenants = filter && !!tenantIds.length; // If the list is empty it is treated as "no filter"
120
+ const results = [];
121
+ try {
122
+ this.suppressSignInEvents = true;
123
+ // Get the list of tenants
124
+ for (const tenant of yield this.getTenants()) {
125
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
126
+ const tenantId = tenant.tenantId;
127
+ // If filtering is enabled, and the current tenant is not in that list, then skip it
128
+ if (shouldFilterTenants && !tenantIds.includes(tenantId)) {
129
+ continue;
130
+ }
131
+ // If the user is not signed in to this tenant, then skip it
132
+ if (!(yield this.isSignedIn(tenantId))) {
133
+ continue;
134
+ }
135
+ // For each tenant, get the list of subscriptions
136
+ results.push(...yield this.getSubscriptionsForTenant(tenantId));
137
+ }
138
+ }
139
+ finally {
140
+ this.suppressSignInEvents = false;
141
+ }
142
+ const sortSubscriptions = (subscriptions) => subscriptions.sort((a, b) => a.name.localeCompare(b.name));
143
+ const subscriptionIds = yield this.getSubscriptionFilters();
144
+ if (filter && !!subscriptionIds.length) { // If the list is empty it is treated as "no filter"
145
+ return sortSubscriptions(results.filter(sub => subscriptionIds.includes(sub.subscriptionId)));
146
+ }
147
+ return sortSubscriptions(results);
148
+ });
149
+ }
150
+ /**
151
+ * Checks to see if a user is signed in.
152
+ *
153
+ * @param tenantId (Optional) Provide to check if a user is signed in to a specific tenant.
154
+ *
155
+ * @returns True if the user is signed in, false otherwise.
156
+ */
157
+ isSignedIn(tenantId) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)([], tenantId, { createIfNone: false, silent: true });
160
+ return !!session;
161
+ });
162
+ }
163
+ /**
164
+ * Asks the user to sign in or pick an account to use.
165
+ *
166
+ * @param tenantId (Optional) Provide to sign in to a specific tenant.
167
+ *
168
+ * @returns True if the user is signed in, false otherwise.
169
+ */
170
+ signIn(tenantId) {
171
+ return __awaiter(this, void 0, void 0, function* () {
172
+ const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)([], tenantId, { createIfNone: true, clearSessionPreference: true });
173
+ return !!session;
174
+ });
175
+ }
176
+ /**
177
+ * Signs the user out
178
+ *
179
+ * @deprecated Not currently supported by VS Code auth providers
180
+ */
181
+ signOut() {
182
+ throw new Error(vscode.l10n.t('Signing out programmatically is not supported. You must sign out by selecting the account in the Accounts menu and choosing Sign Out.'));
183
+ }
184
+ /**
185
+ * Gets the tenant filters that are configured in `azureResourceGroups.selectedSubscriptions`. To
186
+ * override the settings with a custom filter, implement a child class with `getSubscriptionFilters()`
187
+ * and/or `getTenantFilters()` overridden.
188
+ *
189
+ * If no values are returned by `getTenantFilters()`, then all tenants will be scanned for subscriptions.
190
+ *
191
+ * @returns A list of tenant IDs that are configured in `azureResourceGroups.selectedSubscriptions`.
192
+ */
193
+ getTenantFilters() {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ const config = vscode.workspace.getConfiguration('azureResourceGroups');
196
+ const fullSubscriptionIds = config.get('selectedSubscriptions', []);
197
+ return fullSubscriptionIds.map(id => id.split('/')[0]);
198
+ });
199
+ }
200
+ /**
201
+ * Gets the subscription filters that are configured in `azureResourceGroups.selectedSubscriptions`. To
202
+ * override the settings with a custom filter, implement a child class with `getSubscriptionFilters()`
203
+ * and/or `getTenantFilters()` overridden.
204
+ *
205
+ * If no values are returned by `getSubscriptionFilters()`, then all subscriptions will be returned.
206
+ *
207
+ * @returns A list of subscription IDs that are configured in `azureResourceGroups.selectedSubscriptions`.
208
+ */
209
+ getSubscriptionFilters() {
210
+ return __awaiter(this, void 0, void 0, function* () {
211
+ const config = vscode.workspace.getConfiguration('azureResourceGroups');
212
+ const fullSubscriptionIds = config.get('selectedSubscriptions', []);
213
+ return fullSubscriptionIds.map(id => id.split('/')[1]);
214
+ });
215
+ }
216
+ /**
217
+ * Gets the subscriptions for a given tenant.
218
+ *
219
+ * @param tenantId The tenant ID to get subscriptions for.
220
+ *
221
+ * @returns The list of subscriptions for the tenant.
222
+ */
223
+ getSubscriptionsForTenant(tenantId) {
224
+ var _a, e_2, _b, _c;
225
+ return __awaiter(this, void 0, void 0, function* () {
226
+ const { client, credential, authentication } = yield this.getSubscriptionClient(tenantId);
227
+ const environment = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
228
+ const subscriptions = [];
229
+ try {
230
+ for (var _d = true, _e = __asyncValues(client.subscriptions.list()), _f; _f = yield _e.next(), _a = _f.done, !_a;) {
231
+ _c = _f.value;
232
+ _d = false;
233
+ try {
234
+ const subscription = _c;
235
+ subscriptions.push({
236
+ authentication: authentication,
237
+ environment: environment,
238
+ credential: credential,
239
+ isCustomCloud: environment.isCustomCloud,
240
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
241
+ name: subscription.displayName,
242
+ subscriptionId: subscription.subscriptionId,
243
+ /* eslint-enable @typescript-eslint/no-non-null-assertion */
244
+ tenantId: tenantId,
245
+ });
246
+ }
247
+ finally {
248
+ _d = true;
249
+ }
250
+ }
251
+ }
252
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
253
+ finally {
254
+ try {
255
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
256
+ }
257
+ finally { if (e_2) throw e_2.error; }
258
+ }
259
+ return subscriptions;
260
+ });
261
+ }
262
+ /**
263
+ * Gets a fully-configured subscription client for a given tenant ID
264
+ *
265
+ * @param tenantId (Optional) The tenant ID to get a client for
266
+ *
267
+ * @returns A client, the credential used by the client, and the authentication function
268
+ */
269
+ getSubscriptionClient(tenantId, scopes) {
270
+ return __awaiter(this, void 0, void 0, function* () {
271
+ const armSubs = yield Promise.resolve().then(() => require('@azure/arm-resources-subscriptions'));
272
+ const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true });
273
+ if (!session) {
274
+ throw new NotSignedInError_1.NotSignedInError();
275
+ }
276
+ const credential = {
277
+ getToken: () => __awaiter(this, void 0, void 0, function* () {
278
+ return {
279
+ token: session.accessToken,
280
+ expiresOnTimestamp: 0
281
+ };
282
+ })
283
+ };
284
+ const configuredAzureEnv = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
285
+ const endpoint = configuredAzureEnv.resourceManagerEndpointUrl;
286
+ return {
287
+ client: new armSubs.SubscriptionClient(credential, { endpoint }),
288
+ credential: credential,
289
+ authentication: {
290
+ getSession: () => session
291
+ }
292
+ };
293
+ });
294
+ }
295
+ }
296
+ exports.VSCodeAzureSubscriptionProvider = VSCodeAzureSubscriptionProvider;
297
297
  //# sourceMappingURL=VSCodeAzureSubscriptionProvider.js.map
@@ -1,12 +1,12 @@
1
- import * as vscode from "vscode";
2
- /**
3
- * Wraps {@link vscode.authentication.getSession} and handles:
4
- * * Passing the configured auth provider id
5
- * * Getting the list of scopes, adding the tenant id to the scope list if needed
6
- *
7
- * @param scopes - top-level resource scopes (e.g. http://management.azure.com, http://storage.azure.com) or .default scopes. All resources/scopes will be normalized to the `.default` scope for each resource.
8
- * @param tenantId - (Optional) The tenant ID, will be added to the scopes
9
- * @param options - see {@link vscode.AuthenticationGetSessionOptions}
10
- * @returns An authentication session if available, or undefined if there are no sessions
11
- */
12
- export declare function getSessionFromVSCode(scopes?: string | string[], tenantId?: string, options?: vscode.AuthenticationGetSessionOptions): Promise<vscode.AuthenticationSession | undefined>;
1
+ import * as vscode from "vscode";
2
+ /**
3
+ * Wraps {@link vscode.authentication.getSession} and handles:
4
+ * * Passing the configured auth provider id
5
+ * * Getting the list of scopes, adding the tenant id to the scope list if needed
6
+ *
7
+ * @param scopes - top-level resource scopes (e.g. http://management.azure.com, http://storage.azure.com) or .default scopes. All resources/scopes will be normalized to the `.default` scope for each resource.
8
+ * @param tenantId - (Optional) The tenant ID, will be added to the scopes
9
+ * @param options - see {@link vscode.AuthenticationGetSessionOptions}
10
+ * @returns An authentication session if available, or undefined if there are no sessions
11
+ */
12
+ export declare function getSessionFromVSCode(scopes?: string | string[], tenantId?: string, options?: vscode.AuthenticationGetSessionOptions): Promise<vscode.AuthenticationSession | undefined>;