Skip to content

Commit 0ebb9ca

Browse files
committed
add support for custom authorization
1 parent 07221db commit 0ebb9ca

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tool.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ export function findLocalToolVersions(toolName: string, arch?: string) {
197197
* @param url url of tool to download
198198
* @param fileName optional fileName. Should typically not use (will be a guid for reliability). Can pass fileName with an absolute path.
199199
* @param handlers optional handlers array. Auth handlers to pass to the HttpClient for the tool download.
200+
* @param auth optional custom auth header value. This is passed as a HTTP header to the download client.
200201
*/
201-
export async function downloadTool(url: string, fileName?: string, handlers?: ifm.IRequestHandler[]): Promise<string> {
202+
export async function downloadTool(url: string, fileName?: string, handlers?: ifm.IRequestHandler[], auth?: string): Promise<string> {
202203
return new Promise<string>(async (resolve, reject) => {
203204
try {
204205
handlers = handlers || null;
@@ -226,7 +227,13 @@ export async function downloadTool(url: string, fileName?: string, handlers?: if
226227
if (fs.existsSync(destPath)) {
227228
throw new Error("Destination file path already exists");
228229
}
229-
230+
231+
const additionalHeaders: ifm.IHeaders = {};
232+
if (auth) {
233+
tl.debug('adding authorization header');
234+
additionalHeaders['Authorization'] = auth;
235+
}
236+
230237
tl.debug('downloading');
231238
let response: httpm.HttpClientResponse = await http.get(url);
232239

0 commit comments

Comments
 (0)