Skip to content

Commit

Permalink
Merge pull request #150 from DaniilShmelev/users/DaniilShmelev/add-to…
Browse files Browse the repository at this point in the history
…ol-download-auth

Add support for custom authorization header value
  • Loading branch information
mmrazik authored Mar 17, 2022
2 parents 6beaeee + 496c0bc commit 5dbfaf3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azure-pipelines-tool-lib",
"version": "1.1.0",
"version": "1.2.0",
"description": "Azure Pipelines Tool Installer Lib for CI/CD Tasks",
"main": "tool.js",
"scripts": {
Expand Down
18 changes: 12 additions & 6 deletions tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,17 @@ export function findLocalToolVersions(toolName: string, arch?: string) {
/**
* Download a tool from an url and stream it into a file
*
* @param url url of tool to download
* @param fileName optional fileName. Should typically not use (will be a guid for reliability). Can pass fileName with an absolute path.
* @param handlers optional handlers array. Auth handlers to pass to the HttpClient for the tool download.
* @param url url of tool to download
* @param fileName optional fileName. Should typically not use (will be a guid for reliability). Can pass fileName with an absolute path.
* @param handlers optional handlers array. Auth handlers to pass to the HttpClient for the tool download.
* @param additionalHeaders optional custom HTTP headers. This is passed to the REST client that downloads the tool.
*/
export async function downloadTool(url: string, fileName?: string, handlers?: ifm.IRequestHandler[]): Promise<string> {
export async function downloadTool(
url: string,
fileName?: string,
handlers?: ifm.IRequestHandler[],
additionalHeaders?: ifm.IHeaders
): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
try {
handlers = handlers || null;
Expand Down Expand Up @@ -226,9 +232,9 @@ export async function downloadTool(url: string, fileName?: string, handlers?: if
if (fs.existsSync(destPath)) {
throw new Error("Destination file path already exists");
}

tl.debug('downloading');
let response: httpm.HttpClientResponse = await http.get(url);
let response: httpm.HttpClientResponse = await http.get(url, additionalHeaders);

if (response.message.statusCode != 200) {
let err: Error = new Error('Unexpected HTTP response: ' + response.message.statusCode);
Expand Down

0 comments on commit 5dbfaf3

Please sign in to comment.