@microsoft/vscode-azext-azureauth 1.4.0 → 2.0.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.4.0 - 2023-11-03
4
+ * [#1619](https://github.com/microsoft/vscode-azuretools/pull/1619) Make `getSession` synchronous to fix an issue that broke app service deployments
5
+
3
6
  ## 1.3.0 - 2023-10-23
4
7
 
5
8
  * [#1610](https://github.com/microsoft/vscode-azuretools/pull/1610) Add `signInToTenant` command which facilitates signing in to a specific tenant.
@@ -1,6 +1,6 @@
1
1
  import type * as vscode from 'vscode';
2
2
  import type { AzureSubscription } from './AzureSubscription';
3
- import { TenantIdDescription } from '@azure/arm-subscriptions';
3
+ import type { TenantIdDescription } from '@azure/arm-resources-subscriptions';
4
4
  /**
5
5
  * An interface for obtaining Azure subscription information
6
6
  */
@@ -1,4 +1,4 @@
1
- import type { TenantIdDescription } from '@azure/arm-subscriptions';
1
+ import type { TenantIdDescription } from '@azure/arm-resources-subscriptions';
2
2
  import * as vscode from 'vscode';
3
3
  import type { AzureSubscription, SubscriptionId, TenantId } from './AzureSubscription';
4
4
  import type { AzureSubscriptionProvider } from './AzureSubscriptionProvider';
@@ -99,5 +99,4 @@ export declare class VSCodeAzureSubscriptionProvider extends vscode.Disposable i
99
99
  * @returns A client, the credential used by the client, and the authentication function
100
100
  */
101
101
  private getSubscriptionClient;
102
- private getToken;
103
102
  }
@@ -74,13 +74,31 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
74
74
  * @returns A list of tenants.
75
75
  */
76
76
  getTenants() {
77
+ var _a, e_1, _b, _c;
77
78
  return __awaiter(this, void 0, void 0, function* () {
78
- const listTenantsResponse = yield fetch('https://management.azure.com/tenants?api-version=2022-12-01', {
79
- headers: {
80
- Authorization: `Bearer ${yield this.getToken()}`,
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);
81
98
  }
82
- });
83
- return (yield listTenantsResponse.json()).value;
99
+ finally { if (e_1) throw e_1.error; }
100
+ }
101
+ return results;
84
102
  });
85
103
  }
86
104
  /**
@@ -99,8 +117,6 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
99
117
  return __awaiter(this, void 0, void 0, function* () {
100
118
  const tenantIds = yield this.getTenantFilters();
101
119
  const shouldFilterTenants = filter && !!tenantIds.length; // If the list is empty it is treated as "no filter"
102
- const subscriptionIds = yield this.getSubscriptionFilters();
103
- const shouldFilterSubscriptions = filter && !!subscriptionIds.length; // If the list is empty it is treated as "no filter"
104
120
  const results = [];
105
121
  try {
106
122
  this.suppressSignInEvents = true;
@@ -117,19 +133,18 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
117
133
  continue;
118
134
  }
119
135
  // For each tenant, get the list of subscriptions
120
- for (const subscription of yield this.getSubscriptionsForTenant(tenantId)) {
121
- // If filtering is enabled, and the current subscription is not in that list, then skip it
122
- if (shouldFilterSubscriptions && !subscriptionIds.includes(subscription.subscriptionId)) {
123
- continue;
124
- }
125
- results.push(subscription);
126
- }
136
+ results.push(...yield this.getSubscriptionsForTenant(tenantId));
127
137
  }
128
138
  }
129
139
  finally {
130
140
  this.suppressSignInEvents = false;
131
141
  }
132
- return results.sort((a, b) => a.name.localeCompare(b.name));
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);
133
148
  });
134
149
  }
135
150
  /**
@@ -206,7 +221,7 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
206
221
  * @returns The list of subscriptions for the tenant.
207
222
  */
208
223
  getSubscriptionsForTenant(tenantId) {
209
- var _a, e_1, _b, _c;
224
+ var _a, e_2, _b, _c;
210
225
  return __awaiter(this, void 0, void 0, function* () {
211
226
  const { client, credential, authentication } = yield this.getSubscriptionClient(tenantId);
212
227
  const environment = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
@@ -234,12 +249,12 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
234
249
  }
235
250
  }
236
251
  }
237
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
252
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
238
253
  finally {
239
254
  try {
240
255
  if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
241
256
  }
242
- finally { if (e_1) throw e_1.error; }
257
+ finally { if (e_2) throw e_2.error; }
243
258
  }
244
259
  return subscriptions;
245
260
  });
@@ -253,7 +268,7 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
253
268
  */
254
269
  getSubscriptionClient(tenantId, scopes) {
255
270
  return __awaiter(this, void 0, void 0, function* () {
256
- const armSubs = yield Promise.resolve().then(() => require('@azure/arm-subscriptions'));
271
+ const armSubs = yield Promise.resolve().then(() => require('@azure/arm-resources-subscriptions'));
257
272
  const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true });
258
273
  if (!session) {
259
274
  throw new NotSignedInError_1.NotSignedInError();
@@ -266,8 +281,10 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
266
281
  };
267
282
  })
268
283
  };
284
+ const configuredAzureEnv = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
285
+ const endpoint = configuredAzureEnv.resourceManagerEndpointUrl;
269
286
  return {
270
- client: new armSubs.SubscriptionClient(credential),
287
+ client: new armSubs.SubscriptionClient(credential, { endpoint }),
271
288
  credential: credential,
272
289
  authentication: {
273
290
  getSession: () => session
@@ -275,15 +292,6 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
275
292
  };
276
293
  });
277
294
  }
278
- getToken(tenantId) {
279
- return __awaiter(this, void 0, void 0, function* () {
280
- const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)([], tenantId, { createIfNone: false, silent: true });
281
- if (!session) {
282
- throw new NotSignedInError_1.NotSignedInError();
283
- }
284
- return session.accessToken;
285
- });
286
- }
287
295
  }
288
296
  exports.VSCodeAzureSubscriptionProvider = VSCodeAzureSubscriptionProvider;
289
297
  //# sourceMappingURL=VSCodeAzureSubscriptionProvider.js.map
@@ -16,9 +16,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.getSessionFromVSCode = void 0;
17
17
  const configuredAzureEnv_1 = require("./utils/configuredAzureEnv");
18
18
  const vscode = require("vscode");
19
+ function ensureEndingSlash(value) {
20
+ return value.endsWith('/') ? value : `${value}/`;
21
+ }
19
22
  function getResourceScopes(scopes) {
20
23
  if (scopes === undefined || scopes === "" || scopes.length === 0) {
21
- scopes = `${(0, configuredAzureEnv_1.getConfiguredAzureEnv)().resourceManagerEndpointUrl}.default`;
24
+ scopes = ensureEndingSlash((0, configuredAzureEnv_1.getConfiguredAzureEnv)().resourceManagerEndpointUrl);
22
25
  }
23
26
  const arrScopes = (Array.isArray(scopes) ? scopes : [scopes])
24
27
  .map((scope) => {
@@ -35,10 +35,10 @@ function getConfiguredAzureEnv() {
35
35
  const authProviderConfig = vscode.workspace.getConfiguration(CustomCloudConfigurationSection);
36
36
  const environmentSettingValue = authProviderConfig.get(CloudEnvironmentSettingName);
37
37
  if (environmentSettingValue === CloudEnvironmentSettingValue.ChinaCloud) {
38
- return Object.assign(Object.assign({}, azureEnv.Environment.get(azureEnv.Environment.ChinaCloud.name)), { isCustomCloud: false });
38
+ return Object.assign(Object.assign({}, azureEnv.Environment.ChinaCloud), { isCustomCloud: false });
39
39
  }
40
40
  else if (environmentSettingValue === CloudEnvironmentSettingValue.USGovernment) {
41
- return Object.assign(Object.assign({}, azureEnv.Environment.get(azureEnv.Environment.USGovernment.name)), { isCustomCloud: false });
41
+ return Object.assign(Object.assign({}, azureEnv.Environment.USGovernment), { isCustomCloud: false });
42
42
  }
43
43
  else if (environmentSettingValue === CloudEnvironmentSettingValue.Custom) {
44
44
  const customCloud = authProviderConfig.get(CustomEnvironmentSettingName);
@@ -1,4 +1,4 @@
1
- import type { TenantIdDescription } from "@azure/arm-subscriptions";
1
+ import type { TenantIdDescription } from "@azure/arm-resources-subscriptions";
2
2
  import type { AzureSubscriptionProvider } from "../AzureSubscriptionProvider";
3
3
  /**
4
4
  * @returns list of tenants that VS Code doesn't have sessions for
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@microsoft/vscode-azext-azureauth",
3
3
  "author": "Microsoft Corporation",
4
- "version": "1.4.0",
4
+ "version": "2.0.0",
5
5
  "description": "Azure authentication helpers for Visual Studio Code",
6
6
  "tags": [
7
7
  "azure",
@@ -52,7 +52,7 @@
52
52
  "typescript": "^4.9.4"
53
53
  },
54
54
  "dependencies": {
55
- "@azure/arm-subscriptions": "^5.1.0",
55
+ "@azure/arm-resources-subscriptions": "^2.1.0",
56
56
  "@azure/ms-rest-azure-env": "^2.0.0"
57
57
  }
58
58
  }