-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to new azure-sdk-for-js #2257
Changes from all commits
f45d568
a106c32
a76e7b7
dececa3
27ce737
f5b48c3
0ef2fec
b9c6474
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ | |
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { HttpOperationResponse } from '@azure/ms-rest-js'; | ||
import * as fse from 'fs-extra'; | ||
import * as path from 'path'; | ||
import { Progress } from 'vscode'; | ||
import * as xml2js from 'xml2js'; | ||
import { localize } from '../../../localize'; | ||
import { confirmOverwriteFile } from "../../../utils/fs"; | ||
import { requestUtils } from '../../../utils/requestUtils'; | ||
|
@@ -97,43 +97,24 @@ export class PowerShellProjectCreateStep extends ScriptProjectCreateStep { | |
}); | ||
|
||
try { | ||
const xmlResult: string = await this.getPSGalleryAzModuleInfo(); | ||
const versionResult: string = await this.parseLatestAzModuleVersion(xmlResult); | ||
const response: HttpOperationResponse = await requestUtils.sendRequestWithTimeout({ method: 'GET', url: this.azModuleGalleryUrl }); | ||
const versionResult: string = this.parseLatestAzModuleVersion(response); | ||
const [major]: string[] = versionResult.split('.'); | ||
return parseInt(major); | ||
} catch { | ||
return undefined; | ||
} | ||
} | ||
|
||
private async getPSGalleryAzModuleInfo(): Promise<string> { | ||
const request: requestUtils.Request = await requestUtils.getDefaultRequestWithTimeout(this.azModuleGalleryUrl, undefined, 'GET'); | ||
return await requestUtils.sendRequest(request); | ||
} | ||
|
||
private async parseLatestAzModuleVersion(azModuleInfo: string): Promise<string> { | ||
const moduleInfo: string = await new Promise(( | ||
resolve: (ret: string) => void, | ||
// tslint:disable-next-line:no-any | ||
rejects: (reason: any) => void): void => { | ||
// tslint:disable-next-line:no-any | ||
xml2js.parseString(azModuleInfo, { explicitArray: false }, (err: any, result: string): void => { | ||
if (err) { | ||
rejects(err); | ||
} else { | ||
resolve(result); | ||
} | ||
}); | ||
}); | ||
|
||
// tslint:disable-next-line:no-string-literal no-unsafe-any | ||
if (moduleInfo['feed'] && moduleInfo['feed']['entry'] && Array.isArray(moduleInfo['feed']['entry'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come you were able to get rid of this logic completely? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new sdk will automatically parse xml and return it in |
||
// tslint:disable-next-line:no-string-literal no-unsafe-any | ||
const releasedVersions: string[] = moduleInfo['feed']['entry'] | ||
// tslint:disable-next-line:no-string-literal no-unsafe-any | ||
.filter(entry => entry['m:properties']['d:IsPrerelease']['_'] === 'false') | ||
// tslint:disable-next-line:no-string-literal no-unsafe-any | ||
private parseLatestAzModuleVersion(response: HttpOperationResponse): string { | ||
// tslint:disable-next-line: no-any | ||
const moduleInfo: any = response.parsedBody; | ||
// tslint:disable: no-unsafe-any | ||
if (moduleInfo?.entry && Array.isArray(moduleInfo.entry)) { | ||
const releasedVersions: string[] = moduleInfo.entry | ||
.filter(entry => entry['m:properties']['d:IsPrerelease']._ === 'false') | ||
.map(entry => entry['m:properties']['d:Version']); | ||
// tslint:enable: no-unsafe-any | ||
|
||
// Select the latest version | ||
if (releasedVersions.length > 0) { | ||
|
@@ -143,6 +124,6 @@ export class PowerShellProjectCreateStep extends ScriptProjectCreateStep { | |
} | ||
|
||
// If no version is found, throw exception | ||
throw new Error(`Failed to parse latest Az module version ${azModuleInfo}`); | ||
throw new Error(`Failed to parse latest Az module version ${response.bodyAsText}`); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change this to use Insiders only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Azure Account extension stuff is a part of VS Code 1.48 (see this comment), so we have to run tests on insiders until 1.48 goes stable