Update from obsolete endpoint

This commit is contained in:
damccorm 2019-08-29 15:10:05 -04:00
parent a2db70294c
commit f7896b6c4c
2 changed files with 85 additions and 64 deletions

View File

@ -26,7 +26,6 @@ const fs_1 = require("fs");
const os = __importStar(require("os")); const os = __importStar(require("os"));
const path = __importStar(require("path")); const path = __importStar(require("path"));
const semver = __importStar(require("semver")); const semver = __importStar(require("semver"));
const util = __importStar(require("util"));
const IS_WINDOWS = process.platform === 'win32'; const IS_WINDOWS = process.platform === 'win32';
if (!tempDirectory) { if (!tempDirectory) {
let baseLocation; let baseLocation;
@ -175,39 +174,29 @@ class DotnetCoreInstaller {
getDownloadUrls(osSuffixes, version) { getDownloadUrls(osSuffixes, version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let downloadUrls = []; let downloadUrls = [];
let releasesJSON = yield this.getReleasesJson(); var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {});
core.debug('Releases: ' + releasesJSON); const releasesJsonUrl = yield this.getReleasesJsonUrl(httpCallbackClient, version.split('.'));
let releasesInfo = JSON.parse(yield releasesJSON.readBody()); let releasesJSON = yield httpCallbackClient.get(releasesJsonUrl);
let releasesInfo = JSON.parse(yield releasesJSON.readBody())['releases'];
releasesInfo = releasesInfo.filter((releaseInfo) => { releasesInfo = releasesInfo.filter((releaseInfo) => {
return (releaseInfo['version-sdk'] === version || return (releaseInfo['sdk']['version'] === version ||
releaseInfo['version-sdk-display'] === version); releaseInfo['sdk']['version-display'] === version);
}); });
if (releasesInfo.length != 0) { if (releasesInfo.length != 0) {
let release = releasesInfo[0]; let release = releasesInfo[0];
let blobUrl = release['blob-sdk']; let files = release['sdk']['files'];
let dlcUrl = release['dlc--sdk']; files = files.filter((file) => {
let fileName = release['sdk-' + osSuffixes[0]] if (file['rid'] == osSuffixes[0] || file['rid'] == osSuffixes[1]) {
? release['sdk-' + osSuffixes[0]] return (file['url'].endsWith('.zip') || file['url'].endsWith('.tar.gz'));
: release['sdk-' + osSuffixes[1]];
if (!!fileName) {
fileName = fileName.trim();
// For some latest version, the filename itself can be full download url.
// Do a very basic check for url(instead of regex) as the url is only for downloading and
// is coming from .net core releases json and not some ransom user input
if (fileName.toLowerCase().startsWith('https://')) {
downloadUrls.push(fileName);
}
else {
if (!!blobUrl) {
downloadUrls.push(util.format('%s%s', blobUrl.trim(), fileName));
}
if (!!dlcUrl) {
downloadUrls.push(util.format('%s%s', dlcUrl.trim(), fileName));
}
} }
});
if (files.length > 0) {
files.forEach((file) => {
downloadUrls.push(file['url']);
});
} }
else { else {
throw `The specified version's download links are not correctly formed in the supported versions document => ${DotNetCoreReleasesUrl}`; throw `The specified version's download links are not correctly formed in the supported versions document => ${releasesJsonUrl}`;
} }
} }
else { else {
@ -221,9 +210,23 @@ class DotnetCoreInstaller {
return downloadUrls; return downloadUrls;
}); });
} }
getReleasesJson() { getReleasesJsonUrl(httpCallbackClient, versionParts) {
var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {}); return __awaiter(this, void 0, void 0, function* () {
return httpCallbackClient.get(DotNetCoreReleasesUrl); // First, get the location of the correct releases.json then get that.
const releasesIndex = yield httpCallbackClient.get(DotNetCoreIndexUrl);
let releasesInfo = JSON.parse(yield releasesIndex.readBody())['releases-index'];
releasesInfo = releasesInfo.filter((releaseInfo) => {
const sdkParts = releaseInfo['channel-version'].split('.');
if (versionParts.length >= 2 && versionParts[1] != 'x') {
return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1];
}
return versionParts[0] == sdkParts[0];
});
if (releasesInfo.length === 0) {
throw `Could not find info for this version at ${DotNetCoreIndexUrl}`;
}
return releasesInfo[0]['releases.json'];
});
} }
getFallbackDownloadUrls(version) { getFallbackDownloadUrls(version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -306,4 +309,4 @@ class DotnetCoreInstaller {
} }
} }
exports.DotnetCoreInstaller = DotnetCoreInstaller; exports.DotnetCoreInstaller = DotnetCoreInstaller;
const DotNetCoreReleasesUrl = 'https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases.json'; const DotNetCoreIndexUrl = 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json';

View File

@ -186,44 +186,43 @@ export class DotnetCoreInstaller {
osSuffixes: string[], osSuffixes: string[],
version: string version: string
): Promise<string[]> { ): Promise<string[]> {
let downloadUrls = []; let downloadUrls: string[] = [];
let releasesJSON = await this.getReleasesJson();
core.debug('Releases: ' + releasesJSON);
let releasesInfo = JSON.parse(await releasesJSON.readBody()); var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {});
const releasesJsonUrl = await this.getReleasesJsonUrl(
httpCallbackClient,
version.split('.')
);
let releasesJSON = await httpCallbackClient.get(releasesJsonUrl);
let releasesInfo: any[] = JSON.parse(await releasesJSON.readBody())[
'releases'
];
releasesInfo = releasesInfo.filter((releaseInfo: any) => { releasesInfo = releasesInfo.filter((releaseInfo: any) => {
return ( return (
releaseInfo['version-sdk'] === version || releaseInfo['sdk']['version'] === version ||
releaseInfo['version-sdk-display'] === version releaseInfo['sdk']['version-display'] === version
); );
}); });
if (releasesInfo.length != 0) { if (releasesInfo.length != 0) {
let release = releasesInfo[0]; let release = releasesInfo[0];
let blobUrl: string = release['blob-sdk']; let files = release['sdk']['files'];
let dlcUrl: string = release['dlc--sdk']; files = files.filter((file: any) => {
let fileName: string = release['sdk-' + osSuffixes[0]] if (file['rid'] == osSuffixes[0] || file['rid'] == osSuffixes[1]) {
? release['sdk-' + osSuffixes[0]] return (
: release['sdk-' + osSuffixes[1]]; file['url'].endsWith('.zip') || file['url'].endsWith('.tar.gz')
);
if (!!fileName) {
fileName = fileName.trim();
// For some latest version, the filename itself can be full download url.
// Do a very basic check for url(instead of regex) as the url is only for downloading and
// is coming from .net core releases json and not some ransom user input
if (fileName.toLowerCase().startsWith('https://')) {
downloadUrls.push(fileName);
} else {
if (!!blobUrl) {
downloadUrls.push(util.format('%s%s', blobUrl.trim(), fileName));
}
if (!!dlcUrl) {
downloadUrls.push(util.format('%s%s', dlcUrl.trim(), fileName));
}
} }
});
if (files.length > 0) {
files.forEach((file: any) => {
downloadUrls.push(file['url']);
});
} else { } else {
throw `The specified version's download links are not correctly formed in the supported versions document => ${DotNetCoreReleasesUrl}`; throw `The specified version's download links are not correctly formed in the supported versions document => ${releasesJsonUrl}`;
} }
} else { } else {
console.log( console.log(
@ -241,9 +240,28 @@ export class DotnetCoreInstaller {
return downloadUrls; return downloadUrls;
} }
private getReleasesJson(): Promise<HttpClientResponse> { private async getReleasesJsonUrl(
var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {}); httpCallbackClient: httpClient.HttpClient,
return httpCallbackClient.get(DotNetCoreReleasesUrl); versionParts: string[]
): Promise<string> {
// First, get the location of the correct releases.json then get that.
const releasesIndex: HttpClientResponse = await httpCallbackClient.get(
DotNetCoreIndexUrl
);
let releasesInfo = JSON.parse(await releasesIndex.readBody())[
'releases-index'
];
releasesInfo = releasesInfo.filter((releaseInfo: any) => {
const sdkParts: string[] = releaseInfo['channel-version'].split('.');
if (versionParts.length >= 2 && versionParts[1] != 'x') {
return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1];
}
return versionParts[0] == sdkParts[0];
});
if (releasesInfo.length === 0) {
throw `Could not find info for this version at ${DotNetCoreIndexUrl}`;
}
return releasesInfo[0]['releases.json'];
} }
private async getFallbackDownloadUrls(version: string): Promise<string[]> { private async getFallbackDownloadUrls(version: string): Promise<string[]> {
@ -350,5 +368,5 @@ export class DotnetCoreInstaller {
private arch: string; private arch: string;
} }
const DotNetCoreReleasesUrl: string = const DotNetCoreIndexUrl: string =
'https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases.json'; 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json';