From 16fec6080fdb89d4b237dee411b7bf8f3658ec97 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Sat, 8 Feb 2025 00:25:25 +0000 Subject: [PATCH] chore: Update dist --- dist/cleanup/helpers.d.ts | 1 + dist/cleanup/index.js | 14 ++++++++++++++ dist/index.js | 25 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/dist/cleanup/helpers.d.ts b/dist/cleanup/helpers.d.ts index 350f3ed..aed9a1d 100644 --- a/dist/cleanup/helpers.d.ts +++ b/dist/cleanup/helpers.d.ts @@ -13,4 +13,5 @@ export declare function verifyKeys(creds: Partial | undefined): boo export declare function retryAndBackoff(fn: () => Promise, isRetryable: boolean, maxRetries?: number, retries?: number, base?: number): Promise; export declare function errorMessage(error: unknown): string; export declare function isDefined(i: T | undefined | null): i is T; +export declare function areCredentialsValid(credentialsClient: CredentialsClient): Promise; export {}; diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index d9ed425..21c19de 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -46279,6 +46279,7 @@ exports.verifyKeys = verifyKeys; exports.retryAndBackoff = retryAndBackoff; exports.errorMessage = errorMessage; exports.isDefined = isDefined; +exports.areCredentialsValid = areCredentialsValid; const core = __importStar(__nccwpck_require__(7484)); const client_sts_1 = __nccwpck_require__(1695); const MAX_TAG_VALUE_LENGTH = 256; @@ -46403,6 +46404,19 @@ function isDefined(i) { return i !== undefined && i !== null; } /* c8 ignore stop */ +async function areCredentialsValid(credentialsClient) { + const client = credentialsClient.stsClient; + try { + const identity = await client.send(new client_sts_1.GetCallerIdentityCommand({})); + if (identity.Account) { + return true; + } + return false; + } + catch (_) { + return false; + } +} /***/ }), diff --git a/dist/index.js b/dist/index.js index 8732346..0b7e0e1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -275,6 +275,7 @@ exports.verifyKeys = verifyKeys; exports.retryAndBackoff = retryAndBackoff; exports.errorMessage = errorMessage; exports.isDefined = isDefined; +exports.areCredentialsValid = areCredentialsValid; const core = __importStar(__nccwpck_require__(7484)); const client_sts_1 = __nccwpck_require__(1695); const MAX_TAG_VALUE_LENGTH = 256; @@ -399,6 +400,19 @@ function isDefined(i) { return i !== undefined && i !== null; } /* c8 ignore stop */ +async function areCredentialsValid(credentialsClient) { + const client = credentialsClient.stsClient; + try { + const identity = await client.send(new client_sts_1.GetCallerIdentityCommand({})); + if (identity.Account) { + return true; + } + return false; + } + catch (_) { + return false; + } +} //# sourceMappingURL=helpers.js.map /***/ }), @@ -492,6 +506,8 @@ async function run() { let disableRetry = disableRetryInput.toLowerCase() === 'true'; const specialCharacterWorkaroundInput = core.getInput('special-characters-workaround', { required: false }) || 'false'; const specialCharacterWorkaround = specialCharacterWorkaroundInput.toLowerCase() === 'true'; + const useExistingCredentialsInput = core.getInput('use-existing-credentials', { required: false }) || 'false'; + const useExistingCredentials = useExistingCredentialsInput.toLowerCase() === 'true'; let maxRetries = Number.parseInt(core.getInput('retry-max-attempts', { required: false })) || 12; switch (true) { case specialCharacterWorkaround: @@ -537,6 +553,15 @@ async function run() { const credentialsClient = new CredentialsClient_1.CredentialsClient({ region, proxyServer }); let sourceAccountId; let webIdentityToken; + //if the user wants to attempt to use existing credentials, check if we have some already + if (useExistingCredentials) { + const validCredentials = await (0, helpers_1.areCredentialsValid)(credentialsClient); + if (validCredentials) { + core.notice('Pre-existing credentials are valid. No need to generate new ones.'); + return; + } + core.notice('No valid credentials exist. Running as normal.'); + } // If OIDC is being used, generate token // Else, export credentials provided as input if (useGitHubOIDCProvider()) {