Skip to content

Commit fc45d08

Browse files
authored
support any auth header (#460)
1 parent 02809fb commit fc45d08

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

packages/tool-cache/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@actions/tool-cache",
3-
"version": "1.5.3",
3+
"version": "1.5.4",
44
"description": "Actions tool-cache lib",
55
"keywords": [
66
"github",

packages/tool-cache/src/tool-cache.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ const userAgent = 'actions/tool-cache'
3030
*
3131
* @param url url of tool to download
3232
* @param dest path to download tool
33+
* @param auth authorization header
3334
* @returns path to downloaded tool
3435
*/
3536
export async function downloadTool(
3637
url: string,
3738
dest?: string,
38-
token?: string
39+
auth?: string
3940
): Promise<string> {
4041
dest = dest || path.join(_getTempDirectory(), uuidV4())
4142
await io.mkdirP(path.dirname(dest))
@@ -54,7 +55,7 @@ export async function downloadTool(
5455
const retryHelper = new RetryHelper(maxAttempts, minSeconds, maxSeconds)
5556
return await retryHelper.execute(
5657
async () => {
57-
return await downloadToolAttempt(url, dest || '', token)
58+
return await downloadToolAttempt(url, dest || '', auth)
5859
},
5960
(err: Error) => {
6061
if (err instanceof HTTPError && err.httpStatusCode) {
@@ -77,7 +78,7 @@ export async function downloadTool(
7778
async function downloadToolAttempt(
7879
url: string,
7980
dest: string,
80-
token?: string
81+
auth?: string
8182
): Promise<string> {
8283
if (fs.existsSync(dest)) {
8384
throw new Error(`Destination file path ${dest} already exists`)
@@ -89,9 +90,10 @@ async function downloadToolAttempt(
8990
})
9091

9192
let headers: IHeaders | undefined
92-
if (token) {
93+
if (auth) {
94+
core.debug('set auth')
9395
headers = {
94-
authorization: `token ${token}`
96+
authorization: auth
9597
}
9698
}
9799

@@ -501,15 +503,17 @@ interface GitHubTree {
501503
export async function getManifestFromRepo(
502504
owner: string,
503505
repo: string,
504-
token: string,
506+
auth?: string,
505507
branch = 'master'
506508
): Promise<IToolRelease[]> {
507509
let releases: IToolRelease[] = []
508510
const treeUrl = `https://api.github.com/repos/${owner}/${repo}/git/trees/${branch}`
509511

510512
const http: httpm.HttpClient = new httpm.HttpClient('tool-cache')
511-
const headers: IHeaders = {
512-
authorization: `token ${token}`
513+
const headers: IHeaders = {}
514+
if (auth) {
515+
core.debug('set auth')
516+
headers.authorization = auth
513517
}
514518

515519
const response = await http.getJson<GitHubTree>(treeUrl, headers)

0 commit comments

Comments
 (0)