From 8496c299c068203a895b429531a4bcd1a89d4eb4 Mon Sep 17 00:00:00 2001 From: Nathan Turinski Date: Wed, 1 Nov 2023 15:43:42 -0700 Subject: [PATCH] Implement fetch with https.request instead + revert package lock to v1.1.3 --- auth/package-lock.json | 58 ++------------------- auth/package.json | 4 +- auth/src/VSCodeAzureSubscriptionProvider.ts | 31 ++++++++--- 3 files changed, 30 insertions(+), 63 deletions(-) diff --git a/auth/package-lock.json b/auth/package-lock.json index 79e7653623..12302fe757 100644 --- a/auth/package-lock.json +++ b/auth/package-lock.json @@ -10,8 +10,7 @@ "license": "MIT", "dependencies": { "@azure/arm-subscriptions": "^5.1.0", - "@azure/ms-rest-azure-env": "^2.0.0", - "node-fetch": "2.6.7" + "@azure/ms-rest-azure-env": "^2.0.0" }, "devDependencies": { "@azure/core-auth": "^1.4.0", @@ -20,7 +19,6 @@ "@types/html-to-text": "^8.1.0", "@types/mocha": "^7.0.2", "@types/node": "^18.18.7", - "@types/node-fetch": "2.6.7", "@types/semver": "^7.3.9", "@types/uuid": "^9.0.1", "@types/vscode": "1.76.0", @@ -434,24 +432,14 @@ "dev": true }, "node_modules/@types/node": { - "version": "18.18.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.18.7.tgz", - "integrity": "sha512-bw+lEsxis6eqJYW8Ql6+yTqkE6RuFtsQPSe5JxXbqYRFQEER5aJA9a5UH9igqDWm3X4iLHIKOHlnAXLM4mi7uQ==", + "version": "18.18.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.18.8.tgz", + "integrity": "sha512-OLGBaaK5V3VRBS1bAkMVP2/W9B+H8meUfl866OrMNQqt7wDgdpWPp5o6gmIc9pB+lIQHSq4ZL8ypeH1vPxcPaQ==", "dev": true, "dependencies": { "undici-types": "~5.26.4" } }, - "node_modules/@types/node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-lX17GZVpJ/fuCjguZ5b3TjEbSENxmEk1B2z02yoXSK9WMEWRivhdSY73wWMn6bpcCDAOh6qAdktpKHIlkDk2lg==", - "dev": true, - "dependencies": { - "@types/node": "*", - "form-data": "^4.0.0" - } - }, "node_modules/@types/semver": { "version": "7.3.13", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz", @@ -2818,25 +2806,6 @@ "integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==", "dev": true }, - "node_modules/node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -3444,11 +3413,6 @@ "node": ">=8.0" } }, - "node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" - }, "node_modules/tsconfig-paths": { "version": "3.14.2", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz", @@ -3577,20 +3541,6 @@ "uuid": "dist/bin/uuid" } }, - "node_modules/webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" - }, - "node_modules/whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/auth/package.json b/auth/package.json index a91a2ee06b..f254231930 100644 --- a/auth/package.json +++ b/auth/package.json @@ -37,7 +37,6 @@ "@types/html-to-text": "^8.1.0", "@types/mocha": "^7.0.2", "@types/node": "^18.18.7", - "@types/node-fetch": "2.6.7", "@types/semver": "^7.3.9", "@types/uuid": "^9.0.1", "@types/vscode": "1.76.0", @@ -53,7 +52,6 @@ }, "dependencies": { "@azure/arm-subscriptions": "^5.1.0", - "@azure/ms-rest-azure-env": "^2.0.0", - "node-fetch": "2.6.7" + "@azure/ms-rest-azure-env": "^2.0.0" } } diff --git a/auth/src/VSCodeAzureSubscriptionProvider.ts b/auth/src/VSCodeAzureSubscriptionProvider.ts index 62ff2c242a..c80137afab 100644 --- a/auth/src/VSCodeAzureSubscriptionProvider.ts +++ b/auth/src/VSCodeAzureSubscriptionProvider.ts @@ -5,7 +5,7 @@ import type { SubscriptionClient, TenantIdDescription } from '@azure/arm-subscriptions'; // Keep this as `import type` to avoid actually loading the package before necessary import type { TokenCredential } from '@azure/core-auth'; // Keep this as `import type` to avoid actually loading the package (at all, this one is dev-only) -import fetch from 'node-fetch'; // have to explicitly use node-fetch v2.6.7 otherwise when @azure/client-core makes a streaming request, it fails on windows +import { get } from 'https'; import * as vscode from 'vscode'; import type { AzureAuthentication } from './AzureAuthentication'; import type { AzureSubscription, SubscriptionId, TenantId } from './AzureSubscription'; @@ -60,12 +60,31 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement * @returns A list of tenants. */ public async getTenants(): Promise { - const listTenantsResponse = await fetch('https://management.azure.com/tenants?api-version=2022-12-01', { - headers: { - Authorization: `Bearer ${await this.getToken()}`, - } + const bearerToken = `Bearer ${await this.getToken()}`; + return new Promise(function async(resolve, reject) { + const req = get('https://management.azure.com/tenants?api-version=2022-12-01', { + headers: { + Authorization: bearerToken, + } + }, function (res) { + const body: unknown[] = []; + res.on('data', function (chunk: unknown) { + body.push(chunk); + }); + // resolve on end + res.on('end', function () { + let response: TenantIdDescription[] = []; + try { + response = (JSON.parse(Buffer.concat(body as Uint8Array[]).toString()) as { value: TenantIdDescription[] }).value; + } catch (e) { + reject(e); + } + resolve(response); + }); + }); + + req.end(); }); - return (await listTenantsResponse.json() as { value: TenantIdDescription[] }).value; } /**