@microsoft/vscode-azext-azureauth 1.3.2 → 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 +3 -0
- package/out/src/AzureSubscriptionProvider.d.ts +1 -1
- package/out/src/VSCodeAzureSubscriptionProvider.d.ts +1 -2
- package/out/src/VSCodeAzureSubscriptionProvider.js +45 -41
- package/out/src/getSessionFromVSCode.js +4 -1
- package/out/src/utils/configuredAzureEnv.js +2 -2
- package/out/src/utils/getUnauthenticatedTenants.d.ts +1 -1
- package/package.json +3 -4
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
|
}
|
|
@@ -21,7 +21,6 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.VSCodeAzureSubscriptionProvider = void 0;
|
|
24
|
-
const node_fetch_1 = require("node-fetch"); // have to explicitly use node-fetch v2.6.7 otherwise when @azure/client-core makes a streaming request, it fails on windows
|
|
25
24
|
const vscode = require("vscode");
|
|
26
25
|
const NotSignedInError_1 = require("./NotSignedInError");
|
|
27
26
|
const getSessionFromVSCode_1 = require("./getSessionFromVSCode");
|
|
@@ -75,13 +74,31 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
75
74
|
* @returns A list of tenants.
|
|
76
75
|
*/
|
|
77
76
|
getTenants() {
|
|
77
|
+
var _a, e_1, _b, _c;
|
|
78
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
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
|
+
}
|
|
82
92
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
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;
|
|
85
102
|
});
|
|
86
103
|
}
|
|
87
104
|
/**
|
|
@@ -100,8 +117,6 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
100
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
118
|
const tenantIds = yield this.getTenantFilters();
|
|
102
119
|
const shouldFilterTenants = filter && !!tenantIds.length; // If the list is empty it is treated as "no filter"
|
|
103
|
-
const subscriptionIds = yield this.getSubscriptionFilters();
|
|
104
|
-
const shouldFilterSubscriptions = filter && !!subscriptionIds.length; // If the list is empty it is treated as "no filter"
|
|
105
120
|
const results = [];
|
|
106
121
|
try {
|
|
107
122
|
this.suppressSignInEvents = true;
|
|
@@ -118,19 +133,18 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
118
133
|
continue;
|
|
119
134
|
}
|
|
120
135
|
// For each tenant, get the list of subscriptions
|
|
121
|
-
|
|
122
|
-
// If filtering is enabled, and the current subscription is not in that list, then skip it
|
|
123
|
-
if (shouldFilterSubscriptions && !subscriptionIds.includes(subscription.subscriptionId)) {
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
results.push(subscription);
|
|
127
|
-
}
|
|
136
|
+
results.push(...yield this.getSubscriptionsForTenant(tenantId));
|
|
128
137
|
}
|
|
129
138
|
}
|
|
130
139
|
finally {
|
|
131
140
|
this.suppressSignInEvents = false;
|
|
132
141
|
}
|
|
133
|
-
|
|
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);
|
|
134
148
|
});
|
|
135
149
|
}
|
|
136
150
|
/**
|
|
@@ -207,7 +221,7 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
207
221
|
* @returns The list of subscriptions for the tenant.
|
|
208
222
|
*/
|
|
209
223
|
getSubscriptionsForTenant(tenantId) {
|
|
210
|
-
var _a,
|
|
224
|
+
var _a, e_2, _b, _c;
|
|
211
225
|
return __awaiter(this, void 0, void 0, function* () {
|
|
212
226
|
const { client, credential, authentication } = yield this.getSubscriptionClient(tenantId);
|
|
213
227
|
const environment = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
|
|
@@ -235,12 +249,12 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
235
249
|
}
|
|
236
250
|
}
|
|
237
251
|
}
|
|
238
|
-
catch (
|
|
252
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
239
253
|
finally {
|
|
240
254
|
try {
|
|
241
255
|
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
242
256
|
}
|
|
243
|
-
finally { if (
|
|
257
|
+
finally { if (e_2) throw e_2.error; }
|
|
244
258
|
}
|
|
245
259
|
return subscriptions;
|
|
246
260
|
});
|
|
@@ -252,42 +266,32 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
252
266
|
*
|
|
253
267
|
* @returns A client, the credential used by the client, and the authentication function
|
|
254
268
|
*/
|
|
255
|
-
getSubscriptionClient(tenantId) {
|
|
269
|
+
getSubscriptionClient(tenantId, scopes) {
|
|
256
270
|
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
-
const armSubs = yield Promise.resolve().then(() => require('@azure/arm-subscriptions'));
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
return session;
|
|
264
|
-
});
|
|
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
|
+
}
|
|
265
276
|
const credential = {
|
|
266
|
-
getToken: (
|
|
277
|
+
getToken: () => __awaiter(this, void 0, void 0, function* () {
|
|
267
278
|
return {
|
|
268
|
-
token:
|
|
279
|
+
token: session.accessToken,
|
|
269
280
|
expiresOnTimestamp: 0
|
|
270
281
|
};
|
|
271
282
|
})
|
|
272
283
|
};
|
|
284
|
+
const configuredAzureEnv = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
|
|
285
|
+
const endpoint = configuredAzureEnv.resourceManagerEndpointUrl;
|
|
273
286
|
return {
|
|
274
|
-
client: new armSubs.SubscriptionClient(credential),
|
|
287
|
+
client: new armSubs.SubscriptionClient(credential, { endpoint }),
|
|
275
288
|
credential: credential,
|
|
276
289
|
authentication: {
|
|
277
|
-
getSession
|
|
290
|
+
getSession: () => session
|
|
278
291
|
}
|
|
279
292
|
};
|
|
280
293
|
});
|
|
281
294
|
}
|
|
282
|
-
getToken(tenantId) {
|
|
283
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
284
|
-
const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)([], tenantId, { createIfNone: false, silent: true });
|
|
285
|
-
if (!session) {
|
|
286
|
-
throw new NotSignedInError_1.NotSignedInError();
|
|
287
|
-
}
|
|
288
|
-
return session.accessToken;
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
295
|
}
|
|
292
296
|
exports.VSCodeAzureSubscriptionProvider = VSCodeAzureSubscriptionProvider;
|
|
293
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 =
|
|
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.
|
|
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.
|
|
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": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"description": "Azure authentication helpers for Visual Studio Code",
|
|
6
6
|
"tags": [
|
|
7
7
|
"azure",
|
|
@@ -52,8 +52,7 @@
|
|
|
52
52
|
"typescript": "^4.9.4"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@azure/arm-subscriptions": "^
|
|
56
|
-
"@azure/ms-rest-azure-env": "^2.0.0"
|
|
57
|
-
"node-fetch": "2.6.7"
|
|
55
|
+
"@azure/arm-resources-subscriptions": "^2.1.0",
|
|
56
|
+
"@azure/ms-rest-azure-env": "^2.0.0"
|
|
58
57
|
}
|
|
59
58
|
}
|