Add proxy support (#218)

This commit is contained in:
Seth Vargo 2022-08-31 16:13:51 -07:00 committed by GitHub
parent 246692c248
commit c4e906d161
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 252 additions and 269 deletions

2
dist/main/index.js vendored

File diff suppressed because one or more lines are too long

283
package-lock.json generated
View File

@ -10,23 +10,24 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@actions/core": "^1.9.1", "@actions/core": "^1.9.1",
"@actions/http-client": "^2.0.1",
"@google-github-actions/actions-utils": "^0.4.2" "@google-github-actions/actions-utils": "^0.4.2"
}, },
"devDependencies": { "devDependencies": {
"@types/chai": "^4.3.3", "@types/chai": "^4.3.3",
"@types/mocha": "^9.1.1", "@types/mocha": "^9.1.1",
"@types/node": "^18.7.13", "@types/node": "^18.7.14",
"@typescript-eslint/eslint-plugin": "^5.34.0", "@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.34.0", "@typescript-eslint/parser": "^5.36.1",
"@vercel/ncc": "^0.34.0", "@vercel/ncc": "^0.34.0",
"chai": "^4.3.6", "chai": "^4.3.6",
"eslint": "^8.22.0", "eslint": "^8.23.0",
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1", "eslint-plugin-prettier": "^4.2.1",
"mocha": "^10.0.0", "mocha": "^10.0.0",
"prettier": "^2.7.1", "prettier": "^2.7.1",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"typescript": "^4.7.4" "typescript": "^4.8.2"
} }
}, },
"node_modules/@actions/core": { "node_modules/@actions/core": {
@ -59,14 +60,14 @@
} }
}, },
"node_modules/@eslint/eslintrc": { "node_modules/@eslint/eslintrc": {
"version": "1.3.0", "version": "1.3.1",
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.0.tgz", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.1.tgz",
"integrity": "sha512-UWW0TMTmk2d7hLcWD1/e2g5HDM/HQ3csaLSqXCfqwh4uNDuNqlaKWXmEsL4Cs41Z0KnILNvwbHAah3C2yt06kw==", "integrity": "sha512-OhSY22oQQdw3zgPOOwdoj01l/Dzl1Z+xyUP33tkSN+aqyEhymJCcPHyXt+ylW8FSe0TfRC2VG+ROQOapD0aZSQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"ajv": "^6.12.4", "ajv": "^6.12.4",
"debug": "^4.3.2", "debug": "^4.3.2",
"espree": "^9.3.2", "espree": "^9.4.0",
"globals": "^13.15.0", "globals": "^13.15.0",
"ignore": "^5.2.0", "ignore": "^5.2.0",
"import-fresh": "^3.2.1", "import-fresh": "^3.2.1",
@ -76,6 +77,9 @@
}, },
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"funding": {
"url": "https://opencollective.com/eslint"
} }
}, },
"node_modules/@google-github-actions/actions-utils": { "node_modules/@google-github-actions/actions-utils": {
@ -110,6 +114,19 @@
"url": "https://github.com/sponsors/nzakas" "url": "https://github.com/sponsors/nzakas"
} }
}, },
"node_modules/@humanwhocodes/module-importer": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz",
"integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==",
"dev": true,
"engines": {
"node": ">=12.22"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/nzakas"
}
},
"node_modules/@humanwhocodes/object-schema": { "node_modules/@humanwhocodes/object-schema": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz",
@ -219,20 +236,20 @@
"dev": true "dev": true
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "18.7.13", "version": "18.7.14",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.13.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.14.tgz",
"integrity": "sha512-46yIhxSe5xEaJZXWdIBP7GU4HDTG8/eo0qd9atdiL+lFpA03y8KS+lkTN834TWJj5767GbWv4n/P6efyTFt1Dw==", "integrity": "sha512-6bbDaETVi8oyIARulOE9qF1/Qdi/23z6emrUh0fNJRUmjznqrixD4MpGDdgOFk5Xb0m2H6Xu42JGdvAxaJR/wA==",
"dev": true "dev": true
}, },
"node_modules/@typescript-eslint/eslint-plugin": { "node_modules/@typescript-eslint/eslint-plugin": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.36.1.tgz",
"integrity": "sha512-eRfPPcasO39iwjlUAMtjeueRGuIrW3TQ9WseIDl7i5UWuFbf83yYaU7YPs4j8+4CxUMIsj1k+4kV+E+G+6ypDQ==", "integrity": "sha512-iC40UK8q1tMepSDwiLbTbMXKDxzNy+4TfPWgIL661Ym0sD42vRcQU93IsZIrmi+x292DBr60UI/gSwfdVYexCA==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/scope-manager": "5.34.0", "@typescript-eslint/scope-manager": "5.36.1",
"@typescript-eslint/type-utils": "5.34.0", "@typescript-eslint/type-utils": "5.36.1",
"@typescript-eslint/utils": "5.34.0", "@typescript-eslint/utils": "5.36.1",
"debug": "^4.3.4", "debug": "^4.3.4",
"functional-red-black-tree": "^1.0.1", "functional-red-black-tree": "^1.0.1",
"ignore": "^5.2.0", "ignore": "^5.2.0",
@ -258,14 +275,14 @@
} }
}, },
"node_modules/@typescript-eslint/parser": { "node_modules/@typescript-eslint/parser": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.36.1.tgz",
"integrity": "sha512-SZ3NEnK4usd2CXkoV3jPa/vo1mWX1fqRyIVUQZR4As1vyp4fneknBNJj+OFtV8WAVgGf+rOHMSqQbs2Qn3nFZQ==", "integrity": "sha512-/IsgNGOkBi7CuDfUbwt1eOqUXF9WGVBW9dwEe1pi+L32XrTsZIgmDFIi2RxjzsvB/8i+MIf5JIoTEH8LOZ368A==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/scope-manager": "5.34.0", "@typescript-eslint/scope-manager": "5.36.1",
"@typescript-eslint/types": "5.34.0", "@typescript-eslint/types": "5.36.1",
"@typescript-eslint/typescript-estree": "5.34.0", "@typescript-eslint/typescript-estree": "5.36.1",
"debug": "^4.3.4" "debug": "^4.3.4"
}, },
"engines": { "engines": {
@ -285,13 +302,13 @@
} }
}, },
"node_modules/@typescript-eslint/scope-manager": { "node_modules/@typescript-eslint/scope-manager": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.36.1.tgz",
"integrity": "sha512-HNvASMQlah5RsBW6L6c7IJ0vsm+8Sope/wu5sEAf7joJYWNb1LDbJipzmdhdUOnfrDFE6LR1j57x1EYVxrY4ow==", "integrity": "sha512-pGC2SH3/tXdu9IH3ItoqciD3f3RRGCh7hb9zPdN2Drsr341zgd6VbhP5OHQO/reUqihNltfPpMpTNihFMarP2w==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/types": "5.34.0", "@typescript-eslint/types": "5.36.1",
"@typescript-eslint/visitor-keys": "5.34.0" "@typescript-eslint/visitor-keys": "5.36.1"
}, },
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
@ -302,12 +319,13 @@
} }
}, },
"node_modules/@typescript-eslint/type-utils": { "node_modules/@typescript-eslint/type-utils": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.36.1.tgz",
"integrity": "sha512-Pxlno9bjsQ7hs1pdWRUv9aJijGYPYsHpwMeCQ/Inavhym3/XaKt1ZKAA8FIw4odTBfowBdZJDMxf2aavyMDkLg==", "integrity": "sha512-xfZhfmoQT6m3lmlqDvDzv9TiCYdw22cdj06xY0obSznBsT///GK5IEZQdGliXpAOaRL34o8phEvXzEo/VJx13Q==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/utils": "5.34.0", "@typescript-eslint/typescript-estree": "5.36.1",
"@typescript-eslint/utils": "5.36.1",
"debug": "^4.3.4", "debug": "^4.3.4",
"tsutils": "^3.21.0" "tsutils": "^3.21.0"
}, },
@ -328,9 +346,9 @@
} }
}, },
"node_modules/@typescript-eslint/types": { "node_modules/@typescript-eslint/types": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.36.1.tgz",
"integrity": "sha512-49fm3xbbUPuzBIOcy2CDpYWqy/X7VBkxVN+DC21e0zIm3+61Z0NZi6J9mqPmSW1BDVk9FIOvuCFyUPjXz93sjA==", "integrity": "sha512-jd93ShpsIk1KgBTx9E+hCSEuLCUFwi9V/urhjOWnOaksGZFbTOxAT47OH2d4NLJnLhkVD+wDbB48BuaycZPLBg==",
"dev": true, "dev": true,
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
@ -341,13 +359,13 @@
} }
}, },
"node_modules/@typescript-eslint/typescript-estree": { "node_modules/@typescript-eslint/typescript-estree": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.36.1.tgz",
"integrity": "sha512-mXHAqapJJDVzxauEkfJI96j3D10sd567LlqroyCeJaHnu42sDbjxotGb3XFtGPYKPD9IyLjhsoULML1oI3M86A==", "integrity": "sha512-ih7V52zvHdiX6WcPjsOdmADhYMDN15SylWRZrT2OMy80wzKbc79n8wFW0xpWpU0x3VpBz/oDgTm2xwDAnFTl+g==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/types": "5.34.0", "@typescript-eslint/types": "5.36.1",
"@typescript-eslint/visitor-keys": "5.34.0", "@typescript-eslint/visitor-keys": "5.36.1",
"debug": "^4.3.4", "debug": "^4.3.4",
"globby": "^11.1.0", "globby": "^11.1.0",
"is-glob": "^4.0.3", "is-glob": "^4.0.3",
@ -368,15 +386,15 @@
} }
}, },
"node_modules/@typescript-eslint/utils": { "node_modules/@typescript-eslint/utils": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.36.1.tgz",
"integrity": "sha512-kWRYybU4Rn++7lm9yu8pbuydRyQsHRoBDIo11k7eqBWTldN4xUdVUMCsHBiE7aoEkFzrUEaZy3iH477vr4xHAQ==", "integrity": "sha512-lNj4FtTiXm5c+u0pUehozaUWhh7UYKnwryku0nxJlYUEWetyG92uw2pr+2Iy4M/u0ONMKzfrx7AsGBTCzORmIg==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@types/json-schema": "^7.0.9", "@types/json-schema": "^7.0.9",
"@typescript-eslint/scope-manager": "5.34.0", "@typescript-eslint/scope-manager": "5.36.1",
"@typescript-eslint/types": "5.34.0", "@typescript-eslint/types": "5.36.1",
"@typescript-eslint/typescript-estree": "5.34.0", "@typescript-eslint/typescript-estree": "5.36.1",
"eslint-scope": "^5.1.1", "eslint-scope": "^5.1.1",
"eslint-utils": "^3.0.0" "eslint-utils": "^3.0.0"
}, },
@ -392,12 +410,12 @@
} }
}, },
"node_modules/@typescript-eslint/visitor-keys": { "node_modules/@typescript-eslint/visitor-keys": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.36.1.tgz",
"integrity": "sha512-O1moYjOSrab0a2fUvFpsJe0QHtvTC+cR+ovYpgKrAVXzqQyc74mv76TgY6z+aEtjQE2vgZux3CQVtGryqdcOAw==", "integrity": "sha512-ojB9aRyRFzVMN3b5joSYni6FAS10BBSCAfKJhjJAV08t/a95aM6tAhz+O1jF+EtgxktuSO3wJysp2R+Def/IWQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@typescript-eslint/types": "5.34.0", "@typescript-eslint/types": "5.36.1",
"eslint-visitor-keys": "^3.3.0" "eslint-visitor-keys": "^3.3.0"
}, },
"engines": { "engines": {
@ -854,14 +872,15 @@
} }
}, },
"node_modules/eslint": { "node_modules/eslint": {
"version": "8.22.0", "version": "8.23.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.22.0.tgz", "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.23.0.tgz",
"integrity": "sha512-ci4t0sz6vSRKdmkOGmprBo6fmI4PrphDFMy5JEq/fNS0gQkJM3rLmrqcp8ipMcdobH3KtUP40KniAE9W19S4wA==", "integrity": "sha512-pBG/XOn0MsJcKcTRLr27S5HpzQo4kLr+HjLQIyK4EiCsijDl/TB+h5uEuJU6bQ8Edvwz1XWOjpaP2qgnXGpTcA==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@eslint/eslintrc": "^1.3.0", "@eslint/eslintrc": "^1.3.1",
"@humanwhocodes/config-array": "^0.10.4", "@humanwhocodes/config-array": "^0.10.4",
"@humanwhocodes/gitignore-to-minimatch": "^1.0.2", "@humanwhocodes/gitignore-to-minimatch": "^1.0.2",
"@humanwhocodes/module-importer": "^1.0.1",
"ajv": "^6.10.0", "ajv": "^6.10.0",
"chalk": "^4.0.0", "chalk": "^4.0.0",
"cross-spawn": "^7.0.2", "cross-spawn": "^7.0.2",
@ -871,7 +890,7 @@
"eslint-scope": "^7.1.1", "eslint-scope": "^7.1.1",
"eslint-utils": "^3.0.0", "eslint-utils": "^3.0.0",
"eslint-visitor-keys": "^3.3.0", "eslint-visitor-keys": "^3.3.0",
"espree": "^9.3.3", "espree": "^9.4.0",
"esquery": "^1.4.0", "esquery": "^1.4.0",
"esutils": "^2.0.2", "esutils": "^2.0.2",
"fast-deep-equal": "^3.1.3", "fast-deep-equal": "^3.1.3",
@ -896,8 +915,7 @@
"regexpp": "^3.2.0", "regexpp": "^3.2.0",
"strip-ansi": "^6.0.1", "strip-ansi": "^6.0.1",
"strip-json-comments": "^3.1.0", "strip-json-comments": "^3.1.0",
"text-table": "^0.2.0", "text-table": "^0.2.0"
"v8-compile-cache": "^2.0.3"
}, },
"bin": { "bin": {
"eslint": "bin/eslint.js" "eslint": "bin/eslint.js"
@ -1014,9 +1032,9 @@
} }
}, },
"node_modules/espree": { "node_modules/espree": {
"version": "9.3.3", "version": "9.4.0",
"resolved": "https://registry.npmjs.org/espree/-/espree-9.3.3.tgz", "resolved": "https://registry.npmjs.org/espree/-/espree-9.4.0.tgz",
"integrity": "sha512-ORs1Rt/uQTqUKjDdGCyrtYxbazf5umATSf/K4qxjmZHORR6HJk+2s/2Pqe+Kk49HHINC/xNIrGfgh8sZcll0ng==", "integrity": "sha512-DQmnRpLj7f6TgN/NYb0MTzJXL+vJF9h3pHy4JhCIs3zwcgez8xmGg3sXHcEO97BrmO2OSvCwMdfdlyl+E9KjOw==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"acorn": "^8.8.0", "acorn": "^8.8.0",
@ -2279,9 +2297,9 @@
} }
}, },
"node_modules/typescript": { "node_modules/typescript": {
"version": "4.7.4", "version": "4.8.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.2.tgz",
"integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", "integrity": "sha512-C0I1UsrrDHo2fYI5oaCGbSejwX4ch+9Y5jTQELvovfmFkK3HHSZJB8MSJcWLmCUBzQBchCrZ9rMRV6GuNrvGtw==",
"dev": true, "dev": true,
"bin": { "bin": {
"tsc": "bin/tsc", "tsc": "bin/tsc",
@ -2308,12 +2326,6 @@
"uuid": "dist/bin/uuid" "uuid": "dist/bin/uuid"
} }
}, },
"node_modules/v8-compile-cache": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz",
"integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==",
"dev": true
},
"node_modules/v8-compile-cache-lib": { "node_modules/v8-compile-cache-lib": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz",
@ -2488,14 +2500,14 @@
} }
}, },
"@eslint/eslintrc": { "@eslint/eslintrc": {
"version": "1.3.0", "version": "1.3.1",
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.0.tgz", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.1.tgz",
"integrity": "sha512-UWW0TMTmk2d7hLcWD1/e2g5HDM/HQ3csaLSqXCfqwh4uNDuNqlaKWXmEsL4Cs41Z0KnILNvwbHAah3C2yt06kw==", "integrity": "sha512-OhSY22oQQdw3zgPOOwdoj01l/Dzl1Z+xyUP33tkSN+aqyEhymJCcPHyXt+ylW8FSe0TfRC2VG+ROQOapD0aZSQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"ajv": "^6.12.4", "ajv": "^6.12.4",
"debug": "^4.3.2", "debug": "^4.3.2",
"espree": "^9.3.2", "espree": "^9.4.0",
"globals": "^13.15.0", "globals": "^13.15.0",
"ignore": "^5.2.0", "ignore": "^5.2.0",
"import-fresh": "^3.2.1", "import-fresh": "^3.2.1",
@ -2529,6 +2541,12 @@
"integrity": "sha512-rSqmMJDdLFUsyxR6FMtD00nfQKKLFb1kv+qBbOVKqErvloEIJLo5bDTJTQNTYgeyp78JsA7u/NPi5jT1GR/MuA==", "integrity": "sha512-rSqmMJDdLFUsyxR6FMtD00nfQKKLFb1kv+qBbOVKqErvloEIJLo5bDTJTQNTYgeyp78JsA7u/NPi5jT1GR/MuA==",
"dev": true "dev": true
}, },
"@humanwhocodes/module-importer": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz",
"integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==",
"dev": true
},
"@humanwhocodes/object-schema": { "@humanwhocodes/object-schema": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz",
@ -2626,20 +2644,20 @@
"dev": true "dev": true
}, },
"@types/node": { "@types/node": {
"version": "18.7.13", "version": "18.7.14",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.13.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.14.tgz",
"integrity": "sha512-46yIhxSe5xEaJZXWdIBP7GU4HDTG8/eo0qd9atdiL+lFpA03y8KS+lkTN834TWJj5767GbWv4n/P6efyTFt1Dw==", "integrity": "sha512-6bbDaETVi8oyIARulOE9qF1/Qdi/23z6emrUh0fNJRUmjznqrixD4MpGDdgOFk5Xb0m2H6Xu42JGdvAxaJR/wA==",
"dev": true "dev": true
}, },
"@typescript-eslint/eslint-plugin": { "@typescript-eslint/eslint-plugin": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.36.1.tgz",
"integrity": "sha512-eRfPPcasO39iwjlUAMtjeueRGuIrW3TQ9WseIDl7i5UWuFbf83yYaU7YPs4j8+4CxUMIsj1k+4kV+E+G+6ypDQ==", "integrity": "sha512-iC40UK8q1tMepSDwiLbTbMXKDxzNy+4TfPWgIL661Ym0sD42vRcQU93IsZIrmi+x292DBr60UI/gSwfdVYexCA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/scope-manager": "5.34.0", "@typescript-eslint/scope-manager": "5.36.1",
"@typescript-eslint/type-utils": "5.34.0", "@typescript-eslint/type-utils": "5.36.1",
"@typescript-eslint/utils": "5.34.0", "@typescript-eslint/utils": "5.36.1",
"debug": "^4.3.4", "debug": "^4.3.4",
"functional-red-black-tree": "^1.0.1", "functional-red-black-tree": "^1.0.1",
"ignore": "^5.2.0", "ignore": "^5.2.0",
@ -2649,52 +2667,53 @@
} }
}, },
"@typescript-eslint/parser": { "@typescript-eslint/parser": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.36.1.tgz",
"integrity": "sha512-SZ3NEnK4usd2CXkoV3jPa/vo1mWX1fqRyIVUQZR4As1vyp4fneknBNJj+OFtV8WAVgGf+rOHMSqQbs2Qn3nFZQ==", "integrity": "sha512-/IsgNGOkBi7CuDfUbwt1eOqUXF9WGVBW9dwEe1pi+L32XrTsZIgmDFIi2RxjzsvB/8i+MIf5JIoTEH8LOZ368A==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/scope-manager": "5.34.0", "@typescript-eslint/scope-manager": "5.36.1",
"@typescript-eslint/types": "5.34.0", "@typescript-eslint/types": "5.36.1",
"@typescript-eslint/typescript-estree": "5.34.0", "@typescript-eslint/typescript-estree": "5.36.1",
"debug": "^4.3.4" "debug": "^4.3.4"
} }
}, },
"@typescript-eslint/scope-manager": { "@typescript-eslint/scope-manager": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.36.1.tgz",
"integrity": "sha512-HNvASMQlah5RsBW6L6c7IJ0vsm+8Sope/wu5sEAf7joJYWNb1LDbJipzmdhdUOnfrDFE6LR1j57x1EYVxrY4ow==", "integrity": "sha512-pGC2SH3/tXdu9IH3ItoqciD3f3RRGCh7hb9zPdN2Drsr341zgd6VbhP5OHQO/reUqihNltfPpMpTNihFMarP2w==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/types": "5.34.0", "@typescript-eslint/types": "5.36.1",
"@typescript-eslint/visitor-keys": "5.34.0" "@typescript-eslint/visitor-keys": "5.36.1"
} }
}, },
"@typescript-eslint/type-utils": { "@typescript-eslint/type-utils": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.36.1.tgz",
"integrity": "sha512-Pxlno9bjsQ7hs1pdWRUv9aJijGYPYsHpwMeCQ/Inavhym3/XaKt1ZKAA8FIw4odTBfowBdZJDMxf2aavyMDkLg==", "integrity": "sha512-xfZhfmoQT6m3lmlqDvDzv9TiCYdw22cdj06xY0obSznBsT///GK5IEZQdGliXpAOaRL34o8phEvXzEo/VJx13Q==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/utils": "5.34.0", "@typescript-eslint/typescript-estree": "5.36.1",
"@typescript-eslint/utils": "5.36.1",
"debug": "^4.3.4", "debug": "^4.3.4",
"tsutils": "^3.21.0" "tsutils": "^3.21.0"
} }
}, },
"@typescript-eslint/types": { "@typescript-eslint/types": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.36.1.tgz",
"integrity": "sha512-49fm3xbbUPuzBIOcy2CDpYWqy/X7VBkxVN+DC21e0zIm3+61Z0NZi6J9mqPmSW1BDVk9FIOvuCFyUPjXz93sjA==", "integrity": "sha512-jd93ShpsIk1KgBTx9E+hCSEuLCUFwi9V/urhjOWnOaksGZFbTOxAT47OH2d4NLJnLhkVD+wDbB48BuaycZPLBg==",
"dev": true "dev": true
}, },
"@typescript-eslint/typescript-estree": { "@typescript-eslint/typescript-estree": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.36.1.tgz",
"integrity": "sha512-mXHAqapJJDVzxauEkfJI96j3D10sd567LlqroyCeJaHnu42sDbjxotGb3XFtGPYKPD9IyLjhsoULML1oI3M86A==", "integrity": "sha512-ih7V52zvHdiX6WcPjsOdmADhYMDN15SylWRZrT2OMy80wzKbc79n8wFW0xpWpU0x3VpBz/oDgTm2xwDAnFTl+g==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/types": "5.34.0", "@typescript-eslint/types": "5.36.1",
"@typescript-eslint/visitor-keys": "5.34.0", "@typescript-eslint/visitor-keys": "5.36.1",
"debug": "^4.3.4", "debug": "^4.3.4",
"globby": "^11.1.0", "globby": "^11.1.0",
"is-glob": "^4.0.3", "is-glob": "^4.0.3",
@ -2703,26 +2722,26 @@
} }
}, },
"@typescript-eslint/utils": { "@typescript-eslint/utils": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.36.1.tgz",
"integrity": "sha512-kWRYybU4Rn++7lm9yu8pbuydRyQsHRoBDIo11k7eqBWTldN4xUdVUMCsHBiE7aoEkFzrUEaZy3iH477vr4xHAQ==", "integrity": "sha512-lNj4FtTiXm5c+u0pUehozaUWhh7UYKnwryku0nxJlYUEWetyG92uw2pr+2Iy4M/u0ONMKzfrx7AsGBTCzORmIg==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/json-schema": "^7.0.9", "@types/json-schema": "^7.0.9",
"@typescript-eslint/scope-manager": "5.34.0", "@typescript-eslint/scope-manager": "5.36.1",
"@typescript-eslint/types": "5.34.0", "@typescript-eslint/types": "5.36.1",
"@typescript-eslint/typescript-estree": "5.34.0", "@typescript-eslint/typescript-estree": "5.36.1",
"eslint-scope": "^5.1.1", "eslint-scope": "^5.1.1",
"eslint-utils": "^3.0.0" "eslint-utils": "^3.0.0"
} }
}, },
"@typescript-eslint/visitor-keys": { "@typescript-eslint/visitor-keys": {
"version": "5.34.0", "version": "5.36.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.34.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.36.1.tgz",
"integrity": "sha512-O1moYjOSrab0a2fUvFpsJe0QHtvTC+cR+ovYpgKrAVXzqQyc74mv76TgY6z+aEtjQE2vgZux3CQVtGryqdcOAw==", "integrity": "sha512-ojB9aRyRFzVMN3b5joSYni6FAS10BBSCAfKJhjJAV08t/a95aM6tAhz+O1jF+EtgxktuSO3wJysp2R+Def/IWQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/types": "5.34.0", "@typescript-eslint/types": "5.36.1",
"eslint-visitor-keys": "^3.3.0" "eslint-visitor-keys": "^3.3.0"
} }
}, },
@ -3053,14 +3072,15 @@
"dev": true "dev": true
}, },
"eslint": { "eslint": {
"version": "8.22.0", "version": "8.23.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.22.0.tgz", "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.23.0.tgz",
"integrity": "sha512-ci4t0sz6vSRKdmkOGmprBo6fmI4PrphDFMy5JEq/fNS0gQkJM3rLmrqcp8ipMcdobH3KtUP40KniAE9W19S4wA==", "integrity": "sha512-pBG/XOn0MsJcKcTRLr27S5HpzQo4kLr+HjLQIyK4EiCsijDl/TB+h5uEuJU6bQ8Edvwz1XWOjpaP2qgnXGpTcA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@eslint/eslintrc": "^1.3.0", "@eslint/eslintrc": "^1.3.1",
"@humanwhocodes/config-array": "^0.10.4", "@humanwhocodes/config-array": "^0.10.4",
"@humanwhocodes/gitignore-to-minimatch": "^1.0.2", "@humanwhocodes/gitignore-to-minimatch": "^1.0.2",
"@humanwhocodes/module-importer": "^1.0.1",
"ajv": "^6.10.0", "ajv": "^6.10.0",
"chalk": "^4.0.0", "chalk": "^4.0.0",
"cross-spawn": "^7.0.2", "cross-spawn": "^7.0.2",
@ -3070,7 +3090,7 @@
"eslint-scope": "^7.1.1", "eslint-scope": "^7.1.1",
"eslint-utils": "^3.0.0", "eslint-utils": "^3.0.0",
"eslint-visitor-keys": "^3.3.0", "eslint-visitor-keys": "^3.3.0",
"espree": "^9.3.3", "espree": "^9.4.0",
"esquery": "^1.4.0", "esquery": "^1.4.0",
"esutils": "^2.0.2", "esutils": "^2.0.2",
"fast-deep-equal": "^3.1.3", "fast-deep-equal": "^3.1.3",
@ -3095,8 +3115,7 @@
"regexpp": "^3.2.0", "regexpp": "^3.2.0",
"strip-ansi": "^6.0.1", "strip-ansi": "^6.0.1",
"strip-json-comments": "^3.1.0", "strip-json-comments": "^3.1.0",
"text-table": "^0.2.0", "text-table": "^0.2.0"
"v8-compile-cache": "^2.0.3"
}, },
"dependencies": { "dependencies": {
"eslint-scope": { "eslint-scope": {
@ -3167,9 +3186,9 @@
"dev": true "dev": true
}, },
"espree": { "espree": {
"version": "9.3.3", "version": "9.4.0",
"resolved": "https://registry.npmjs.org/espree/-/espree-9.3.3.tgz", "resolved": "https://registry.npmjs.org/espree/-/espree-9.4.0.tgz",
"integrity": "sha512-ORs1Rt/uQTqUKjDdGCyrtYxbazf5umATSf/K4qxjmZHORR6HJk+2s/2Pqe+Kk49HHINC/xNIrGfgh8sZcll0ng==", "integrity": "sha512-DQmnRpLj7f6TgN/NYb0MTzJXL+vJF9h3pHy4JhCIs3zwcgez8xmGg3sXHcEO97BrmO2OSvCwMdfdlyl+E9KjOw==",
"dev": true, "dev": true,
"requires": { "requires": {
"acorn": "^8.8.0", "acorn": "^8.8.0",
@ -4056,9 +4075,9 @@
"dev": true "dev": true
}, },
"typescript": { "typescript": {
"version": "4.7.4", "version": "4.8.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.2.tgz",
"integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", "integrity": "sha512-C0I1UsrrDHo2fYI5oaCGbSejwX4ch+9Y5jTQELvovfmFkK3HHSZJB8MSJcWLmCUBzQBchCrZ9rMRV6GuNrvGtw==",
"dev": true "dev": true
}, },
"uri-js": { "uri-js": {
@ -4075,12 +4094,6 @@
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
}, },
"v8-compile-cache": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz",
"integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==",
"dev": true
},
"v8-compile-cache-lib": { "v8-compile-cache-lib": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz",

View File

@ -24,22 +24,23 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@actions/core": "^1.9.1", "@actions/core": "^1.9.1",
"@actions/http-client": "^2.0.1",
"@google-github-actions/actions-utils": "^0.4.2" "@google-github-actions/actions-utils": "^0.4.2"
}, },
"devDependencies": { "devDependencies": {
"@types/chai": "^4.3.3", "@types/chai": "^4.3.3",
"@types/mocha": "^9.1.1", "@types/mocha": "^9.1.1",
"@types/node": "^18.7.13", "@types/node": "^18.7.14",
"@typescript-eslint/eslint-plugin": "^5.34.0", "@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.34.0", "@typescript-eslint/parser": "^5.36.1",
"@vercel/ncc": "^0.34.0", "@vercel/ncc": "^0.34.0",
"chai": "^4.3.6", "chai": "^4.3.6",
"eslint": "^8.22.0", "eslint": "^8.23.0",
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1", "eslint-plugin-prettier": "^4.2.1",
"mocha": "^10.0.0", "mocha": "^10.0.0",
"prettier": "^2.7.1", "prettier": "^2.7.1",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"typescript": "^4.7.4" "typescript": "^4.8.2"
} }
} }

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
import https, { RequestOptions } from 'https'; import { HttpClient } from '@actions/http-client';
import { URL, URLSearchParams } from 'url'; import { URLSearchParams } from 'url';
import { import {
GoogleAccessTokenParameters, GoogleAccessTokenParameters,
GoogleAccessTokenResponse, GoogleAccessTokenResponse,
@ -13,63 +13,32 @@ import {
// eslint-disable-next-line @typescript-eslint/no-var-requires // eslint-disable-next-line @typescript-eslint/no-var-requires
const { version: appVersion } = require('../package.json'); const { version: appVersion } = require('../package.json');
// userAgent is the default user agent.
const userAgent = `google-github-actions:auth/${appVersion}`;
/**
* BaseClient is the default HTTP client for interacting with the IAM
* credentials API.
*/
export class BaseClient { export class BaseClient {
/** /**
* request is a high-level helper that returns a promise from the executed * client is the HTTP client.
* request.
*/ */
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types protected readonly client: HttpClient;
static request(opts: RequestOptions, data?: any): Promise<string> {
if (!opts.headers) {
opts.headers = {};
}
if (!opts.headers['User-Agent']) { constructor() {
opts.headers['User-Agent'] = `google-github-actions:auth/${appVersion}`; this.client = new HttpClient(userAgent);
}
return new Promise((resolve, reject) => {
const req = https.request(opts, (res) => {
res.setEncoding('utf8');
let body = '';
res.on('data', (data) => {
body += data;
});
res.on('end', () => {
if (res.statusCode && res.statusCode >= 400) {
reject(body);
} else {
resolve(body);
}
});
});
req.on('error', (err) => {
reject(err);
});
if (data != null) {
req.write(data);
}
req.end();
});
} }
/** /**
* googleIDToken generates a Google Cloud ID token for the provided * googleIDToken generates a Google Cloud ID token for the provided
* service account email or unique id. * service account email or unique id.
*/ */
static async googleIDToken( async googleIDToken(
token: string, token: string,
{ serviceAccount, audience, delegates, includeEmail }: GoogleIDTokenParameters, { serviceAccount, audience, delegates, includeEmail }: GoogleIDTokenParameters,
): Promise<GoogleIDTokenResponse> { ): Promise<GoogleIDTokenResponse> {
const serviceAccountID = `projects/-/serviceAccounts/${serviceAccount}`; const pth = `https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/${serviceAccount}:generateIdToken`;
const tokenURL = new URL(
`https://iamcredentials.googleapis.com/v1/${serviceAccountID}:generateIdToken`,
);
const data = { const data = {
delegates: delegates, delegates: delegates,
@ -77,21 +46,20 @@ export class BaseClient {
includeEmail: includeEmail, includeEmail: includeEmail,
}; };
const opts = { const headers = {
hostname: tokenURL.hostname, 'Authorization': `Bearer ${token}`,
port: tokenURL.port, 'Accept': 'application/json',
path: tokenURL.pathname + tokenURL.search, 'Content-Type': 'application/json',
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Accept': 'application/json',
'Content-Type': 'application/json',
},
}; };
try { try {
const resp = await BaseClient.request(opts, JSON.stringify(data)); const resp = await this.client.request('POST', pth, JSON.stringify(data), headers);
const parsed = JSON.parse(resp); const body = await resp.readBody();
const statusCode = resp.message.statusCode || 500;
if (statusCode >= 400) {
throw new Error(`(${statusCode}) ${body}`);
}
const parsed = JSON.parse(body);
return { return {
token: parsed['token'], token: parsed['token'],
}; };
@ -104,14 +72,11 @@ export class BaseClient {
* googleAccessToken generates a Google Cloud access token for the provided * googleAccessToken generates a Google Cloud access token for the provided
* service account email or unique id. * service account email or unique id.
*/ */
static async googleAccessToken( async googleAccessToken(
token: string, token: string,
{ serviceAccount, delegates, scopes, lifetime }: GoogleAccessTokenParameters, { serviceAccount, delegates, scopes, lifetime }: GoogleAccessTokenParameters,
): Promise<GoogleAccessTokenResponse> { ): Promise<GoogleAccessTokenResponse> {
const serviceAccountID = `projects/-/serviceAccounts/${serviceAccount}`; const pth = `https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/${serviceAccount}:generateAccessToken`;
const tokenURL = new URL(
`https://iamcredentials.googleapis.com/v1/${serviceAccountID}:generateAccessToken`,
);
const data: Record<string, string | Array<string>> = {}; const data: Record<string, string | Array<string>> = {};
if (delegates && delegates.length > 0) { if (delegates && delegates.length > 0) {
@ -125,21 +90,20 @@ export class BaseClient {
data.lifetime = `${lifetime}s`; data.lifetime = `${lifetime}s`;
} }
const opts = { const headers = {
hostname: tokenURL.hostname, 'Authorization': `Bearer ${token}`,
port: tokenURL.port, 'Accept': 'application/json',
path: tokenURL.pathname + tokenURL.search, 'Content-Type': 'application/json',
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Accept': 'application/json',
'Content-Type': 'application/json',
},
}; };
try { try {
const resp = await BaseClient.request(opts, JSON.stringify(data)); const resp = await this.client.request('POST', pth, JSON.stringify(data), headers);
const parsed = JSON.parse(resp); const body = await resp.readBody();
const statusCode = resp.message.statusCode || 500;
if (statusCode >= 400) {
throw new Error(`(${statusCode}) ${body}`);
}
const parsed = JSON.parse(body);
return { return {
accessToken: parsed['accessToken'], accessToken: parsed['accessToken'],
expiration: parsed['expireTime'], expiration: parsed['expireTime'],
@ -155,18 +119,12 @@ export class BaseClient {
* *
* @param assertion A signed JWT. * @param assertion A signed JWT.
*/ */
static async googleOAuthToken(assertion: string): Promise<GoogleAccessTokenResponse> { async googleOAuthToken(assertion: string): Promise<GoogleAccessTokenResponse> {
const tokenURL = new URL('https://oauth2.googleapis.com/token'); const pth = `https://oauth2.googleapis.com/token`;
const opts = { const headers = {
hostname: tokenURL.hostname, 'Accept': 'application/json',
port: tokenURL.port, 'Content-Type': 'application/x-www-form-urlencoded',
path: tokenURL.pathname + tokenURL.search,
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
},
}; };
const data = new URLSearchParams(); const data = new URLSearchParams();
@ -174,8 +132,13 @@ export class BaseClient {
data.append('assertion', assertion); data.append('assertion', assertion);
try { try {
const resp = await BaseClient.request(opts, data.toString()); const resp = await this.client.request('POST', pth, data.toString(), headers);
const parsed = JSON.parse(resp); const body = await resp.readBody();
const statusCode = resp.message.statusCode || 500;
if (statusCode >= 400) {
throw new Error(`(${statusCode}) ${body}`);
}
const parsed = JSON.parse(body);
// Normalize the expiration to be a timestamp like the iamcredentials API. // Normalize the expiration to be a timestamp like the iamcredentials API.
// This API returns the number of seconds until expiration, so convert // This API returns the number of seconds until expiration, so convert

View File

@ -9,6 +9,16 @@ export interface AuthClient {
getProjectID(): Promise<string>; getProjectID(): Promise<string>;
getServiceAccount(): Promise<string>; getServiceAccount(): Promise<string>;
createCredentialsFile(outputDir: string): Promise<string>; createCredentialsFile(outputDir: string): Promise<string>;
/**
* Provided by BaseClient.
*/
googleIDToken(token: string, params: GoogleIDTokenParameters): Promise<GoogleIDTokenResponse>;
googleAccessToken(
token: string,
params: GoogleAccessTokenParameters,
): Promise<GoogleAccessTokenResponse>;
googleOAuthToken(assertion: string): Promise<GoogleAccessTokenResponse>;
} }
/** /**

View File

@ -10,6 +10,7 @@ import {
} from '@google-github-actions/actions-utils'; } from '@google-github-actions/actions-utils';
import { AuthClient } from './auth_client'; import { AuthClient } from './auth_client';
import { BaseClient } from '../base';
/** /**
* Available options to create the CredentialsJSONClient. * Available options to create the CredentialsJSONClient.
@ -27,11 +28,13 @@ interface CredentialsJSONClientOptions {
* CredentialsJSONClient is a client that accepts a service account key JSON * CredentialsJSONClient is a client that accepts a service account key JSON
* credential. * credential.
*/ */
export class CredentialsJSONClient implements AuthClient { export class CredentialsJSONClient extends BaseClient implements AuthClient {
readonly #projectID: string; readonly #projectID: string;
readonly #credentials: ServiceAccountKey; readonly #credentials: ServiceAccountKey;
constructor(opts: CredentialsJSONClientOptions) { constructor(opts: CredentialsJSONClientOptions) {
super();
const credentials = parseCredential(opts.credentialsJSON); const credentials = parseCredential(opts.credentialsJSON);
if (!isServiceAccountKey(credentials)) { if (!isServiceAccountKey(credentials)) {
throw new Error(`Provided credential is not a valid service account key JSON`); throw new Error(`Provided credential is not a valid service account key JSON`);

View File

@ -35,7 +35,7 @@ interface WorkloadIdentityClientOptions {
* WorkloadIdentityClient is a client that uses the GitHub Actions runtime to * WorkloadIdentityClient is a client that uses the GitHub Actions runtime to
* authentication via Workload Identity. * authentication via Workload Identity.
*/ */
export class WorkloadIdentityClient implements AuthClient { export class WorkloadIdentityClient extends BaseClient implements AuthClient {
readonly #projectID: string; readonly #projectID: string;
readonly #providerID: string; readonly #providerID: string;
readonly #serviceAccount: string; readonly #serviceAccount: string;
@ -46,6 +46,8 @@ export class WorkloadIdentityClient implements AuthClient {
readonly #oidcTokenRequestToken: string; readonly #oidcTokenRequestToken: string;
constructor(opts: WorkloadIdentityClientOptions) { constructor(opts: WorkloadIdentityClientOptions) {
super();
this.#providerID = opts.providerID; this.#providerID = opts.providerID;
this.#serviceAccount = opts.serviceAccount; this.#serviceAccount = opts.serviceAccount;
this.#token = opts.token; this.#token = opts.token;
@ -85,7 +87,7 @@ export class WorkloadIdentityClient implements AuthClient {
* OIDC token and Workload Identity Provider. * OIDC token and Workload Identity Provider.
*/ */
async getAuthToken(): Promise<string> { async getAuthToken(): Promise<string> {
const stsURL = new URL('https://sts.googleapis.com/v1/token'); const pth = `https://sts.googleapis.com/v1/token`;
const data = { const data = {
audience: '//iam.googleapis.com/' + this.#providerID, audience: '//iam.googleapis.com/' + this.#providerID,
@ -96,20 +98,19 @@ export class WorkloadIdentityClient implements AuthClient {
subjectToken: this.#token, subjectToken: this.#token,
}; };
const opts = { const headers = {
hostname: stsURL.hostname, 'Accept': 'application/json',
port: stsURL.port, 'Content-Type': 'application/json',
path: stsURL.pathname + stsURL.search,
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
}; };
try { try {
const resp = await BaseClient.request(opts, JSON.stringify(data)); const resp = await this.client.request('POST', pth, JSON.stringify(data), headers);
const parsed = JSON.parse(resp); const body = await resp.readBody();
const statusCode = resp.message.statusCode || 500;
if (statusCode >= 400) {
throw new Error(`(${statusCode}) ${body}`);
}
const parsed = JSON.parse(body);
return parsed['access_token']; return parsed['access_token'];
} catch (err) { } catch (err) {
throw new Error( throw new Error(
@ -129,9 +130,7 @@ export class WorkloadIdentityClient implements AuthClient {
const serviceAccount = await this.getServiceAccount(); const serviceAccount = await this.getServiceAccount();
const federatedToken = await this.getAuthToken(); const federatedToken = await this.getAuthToken();
const signJWTURL = new URL( const pth = `https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/${serviceAccount}:signJwt`;
`https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/${serviceAccount}:signJwt`,
);
const data: Record<string, string | Array<string>> = { const data: Record<string, string | Array<string>> = {
payload: unsignedJWT, payload: unsignedJWT,
@ -140,21 +139,20 @@ export class WorkloadIdentityClient implements AuthClient {
data.delegates = delegates; data.delegates = delegates;
} }
const opts = { const headers = {
hostname: signJWTURL.hostname, 'Accept': 'application/json',
port: signJWTURL.port, 'Authorization': `Bearer ${federatedToken}`,
path: signJWTURL.pathname + signJWTURL.search, 'Content-Type': 'application/json',
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${federatedToken}`,
'Content-Type': 'application/json',
},
}; };
try { try {
const resp = await BaseClient.request(opts, JSON.stringify(data)); const resp = await this.client.request('POST', pth, JSON.stringify(data), headers);
const parsed = JSON.parse(resp); const body = await resp.readBody();
const statusCode = resp.message.statusCode || 500;
if (statusCode >= 400) {
throw new Error(`(${statusCode}) ${body}`);
}
const parsed = JSON.parse(body);
return parsed['signedJwt']; return parsed['signedJwt'];
} catch (err) { } catch (err) {
throw new Error(`Failed to sign JWT using ${serviceAccount}: ${err}`); throw new Error(`Failed to sign JWT using ${serviceAccount}: ${err}`);

View File

@ -28,7 +28,6 @@ import {
import { WorkloadIdentityClient } from './client/workload_identity_client'; import { WorkloadIdentityClient } from './client/workload_identity_client';
import { CredentialsJSONClient } from './client/credentials_json_client'; import { CredentialsJSONClient } from './client/credentials_json_client';
import { AuthClient } from './client/auth_client'; import { AuthClient } from './client/auth_client';
import { BaseClient } from './base';
import { buildDomainWideDelegationJWT, generateCredentialsFilename } from './utils'; import { buildDomainWideDelegationJWT, generateCredentialsFilename } from './utils';
const secretsWarning = const secretsWarning =
@ -249,10 +248,10 @@ async function main() {
accessTokenLifetime, accessTokenLifetime,
); );
const signedJWT = await client.signJWT(unsignedJWT, delegates); const signedJWT = await client.signJWT(unsignedJWT, delegates);
({ accessToken, expiration } = await BaseClient.googleOAuthToken(signedJWT)); ({ accessToken, expiration } = await client.googleOAuthToken(signedJWT));
} else { } else {
const authToken = await client.getAuthToken(); const authToken = await client.getAuthToken();
({ accessToken, expiration } = await BaseClient.googleAccessToken(authToken, { ({ accessToken, expiration } = await client.googleAccessToken(authToken, {
serviceAccount, serviceAccount,
delegates, delegates,
scopes: accessTokenScopes, scopes: accessTokenScopes,
@ -273,7 +272,7 @@ async function main() {
const serviceAccount = await client.getServiceAccount(); const serviceAccount = await client.getServiceAccount();
const authToken = await client.getAuthToken(); const authToken = await client.getAuthToken();
const { token } = await BaseClient.googleIDToken(authToken, { const { token } = await client.googleIDToken(authToken, {
serviceAccount, serviceAccount,
audience: idTokenAudience, audience: idTokenAudience,
delegates, delegates,

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
import { getBooleanInput, setFailed, info as logInfo } from '@actions/core'; import { getBooleanInput, setFailed, info as logInfo } from '@actions/core';
import { errorMessage, removeFile } from '@google-github-actions/actions-utils'; import { errorMessage, forceRemove } from '@google-github-actions/actions-utils';
/** /**
* Executes the post action, documented inline. * Executes the post action, documented inline.
@ -31,12 +31,8 @@ export async function run(): Promise<void> {
} }
// Remove the file. // Remove the file.
const removed = await removeFile(credentialsPath); await forceRemove(credentialsPath);
if (removed) { logInfo(`Removed exported credentials at "${credentialsPath}".`);
logInfo(`Removed exported credentials at "${credentialsPath}".`);
} else {
logInfo(`No exported credentials were found at "${credentialsPath}".`);
}
} catch (err) { } catch (err) {
const msg = errorMessage(err); const msg = errorMessage(err);
setFailed(`google-github-actions/auth post failed with: ${msg}`); setFailed(`google-github-actions/auth post failed with: ${msg}`);