MCPcopy Create free account
hub / github.com/Azure/powershell / downloadTool

Function downloadTool

lib/index.js:3960–3985  ·  view source on GitHub ↗

* Download a tool from an url and stream it into a file * * @param url url of tool to download * @param dest path to download tool * @param auth authorization header * @param headers other headers * @returns path to downloaded tool

(url, dest, auth, headers)

Source from the content-addressed store, hash-verified

3958 * @returns path to downloaded tool
3959 */
3960function downloadTool(url, dest, auth, headers) {
3961 return __awaiter(this, void 0, void 0, function* () {
3962 dest = dest || path.join(_getTempDirectory(), v4_1.default());
3963 yield io.mkdirP(path.dirname(dest));
3964 core.debug(`Downloading ${url}`);
3965 core.debug(`Destination ${dest}`);
3966 const maxAttempts = 3;
3967 const minSeconds = _getGlobal('TEST_DOWNLOAD_TOOL_RETRY_MIN_SECONDS', 10);
3968 const maxSeconds = _getGlobal('TEST_DOWNLOAD_TOOL_RETRY_MAX_SECONDS', 20);
3969 const retryHelper = new retry_helper_1.RetryHelper(maxAttempts, minSeconds, maxSeconds);
3970 return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
3971 return yield downloadToolAttempt(url, dest || '', auth, headers);
3972 }), (err) => {
3973 if (err instanceof HTTPError && err.httpStatusCode) {
3974 // Don't retry anything less than 500, except 408 Request Timeout and 429 Too Many Requests
3975 if (err.httpStatusCode < 500 &&
3976 err.httpStatusCode !== 408 &&
3977 err.httpStatusCode !== 429) {
3978 return false;
3979 }
3980 }
3981 // Otherwise retry
3982 return true;
3983 });
3984 });
3985}
3986exports.downloadTool = downloadTool;
3987function downloadToolAttempt(url, dest, auth, headers) {
3988 return __awaiter(this, void 0, void 0, function* () {

Callers

nothing calls this directly

Calls 4

executeMethod · 0.95
_getTempDirectoryFunction · 0.85
_getGlobalFunction · 0.85
downloadToolAttemptFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…