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 path = __importStar(require("path"));
const semver = __importStar(require("semver"));
const util = __importStar(require("util"));
const IS_WINDOWS = process.platform === 'win32';
if (!tempDirectory) {
let baseLocation;
@ -175,39 +174,29 @@ class DotnetCoreInstaller {
getDownloadUrls(osSuffixes, version) {
return __awaiter(this, void 0, void 0, function* () {
let downloadUrls = [];
let releasesJSON = yield this.getReleasesJson();
core.debug('Releases: ' + releasesJSON);
let releasesInfo = JSON.parse(yield releasesJSON.readBody());
var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {});
const releasesJsonUrl = yield this.getReleasesJsonUrl(httpCallbackClient, version.split('.'));
let releasesJSON = yield httpCallbackClient.get(releasesJsonUrl);
let releasesInfo = JSON.parse(yield releasesJSON.readBody())['releases'];
releasesInfo = releasesInfo.filter((releaseInfo) => {
return (releaseInfo['version-sdk'] === version ||
releaseInfo['version-sdk-display'] === version);
return (releaseInfo['sdk']['version'] === version ||
releaseInfo['sdk']['version-display'] === version);
});
if (releasesInfo.length != 0) {
let release = releasesInfo[0];
let blobUrl = release['blob-sdk'];
let dlcUrl = release['dlc--sdk'];
let fileName = release['sdk-' + osSuffixes[0]]
? release['sdk-' + osSuffixes[0]]
: 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));
}
let files = release['sdk']['files'];
files = files.filter((file) => {
if (file['rid'] == osSuffixes[0] || file['rid'] == osSuffixes[1]) {
return (file['url'].endsWith('.zip') || file['url'].endsWith('.tar.gz'));
}
});
if (files.length > 0) {
files.forEach((file) => {
downloadUrls.push(file['url']);
});
}
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 {
@ -221,9 +210,23 @@ class DotnetCoreInstaller {
return downloadUrls;
});
}
getReleasesJson() {
var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {});
return httpCallbackClient.get(DotNetCoreReleasesUrl);
getReleasesJsonUrl(httpCallbackClient, versionParts) {
return __awaiter(this, void 0, void 0, function* () {
// 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) {
return __awaiter(this, void 0, void 0, function* () {
@ -306,4 +309,4 @@ class 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[],
version: string
): Promise<string[]> {
let downloadUrls = [];
let releasesJSON = await this.getReleasesJson();
core.debug('Releases: ' + releasesJSON);
let downloadUrls: string[] = [];
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) => {
return (
releaseInfo['version-sdk'] === version ||
releaseInfo['version-sdk-display'] === version
releaseInfo['sdk']['version'] === version ||
releaseInfo['sdk']['version-display'] === version
);
});
if (releasesInfo.length != 0) {
let release = releasesInfo[0];
let blobUrl: string = release['blob-sdk'];
let dlcUrl: string = release['dlc--sdk'];
let fileName: string = release['sdk-' + osSuffixes[0]]
? release['sdk-' + osSuffixes[0]]
: 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));
}
let files = release['sdk']['files'];
files = files.filter((file: any) => {
if (file['rid'] == osSuffixes[0] || file['rid'] == osSuffixes[1]) {
return (
file['url'].endsWith('.zip') || file['url'].endsWith('.tar.gz')
);
}
});
if (files.length > 0) {
files.forEach((file: any) => {
downloadUrls.push(file['url']);
});
} 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 {
console.log(
@ -241,9 +240,28 @@ export class DotnetCoreInstaller {
return downloadUrls;
}
private getReleasesJson(): Promise<HttpClientResponse> {
var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {});
return httpCallbackClient.get(DotNetCoreReleasesUrl);
private async getReleasesJsonUrl(
httpCallbackClient: httpClient.HttpClient,
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[]> {
@ -350,5 +368,5 @@ export class DotnetCoreInstaller {
private arch: string;
}
const DotNetCoreReleasesUrl: string =
'https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases.json';
const DotNetCoreIndexUrl: string =
'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json';