From e021afe0dc2c3f2f22e22420d8cf7a75ca46513e Mon Sep 17 00:00:00 2001 From: Balaga Gayatri Date: Mon, 2 May 2022 19:46:30 +0530 Subject: [PATCH] Handling warnings and adding OIDC promotion message (#221) * Handling warnings and adding OIDC promotion message * Implementing NIT suggestions --- lib/main.js | 37 ++++++++++++++++++------------------- src/main.ts | 23 +++++++++++------------ 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/lib/main.js b/lib/main.js index 4e896e56..ccfed1e0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,14 +1,14 @@ "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function (o, m, k, k2) { +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } }); -}) : (function (o, m, k, k2) { + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function (o, v) { +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function (o, v) { +}) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { @@ -40,22 +40,20 @@ function main() { return __awaiter(this, void 0, void 0, function* () { try { //Options for error handling - let commandStdErr = false; const loginOptions = { silent: true, - ignoreReturnCode: true, - failOnStdErr: true, listeners: { stderr: (data) => { let error = data.toString(); - //removing the keyword 'ERROR' to avoid duplicates while throwing error - if (error.toLowerCase().startsWith('error')) { - error = error.slice(5); - } - // printing error - if (error && error.trim().length !== 0) { - commandStdErr = true; - core.error(error); + let startsWithWarning = error.toLowerCase().startsWith('warning'); + let startsWithError = error.toLowerCase().startsWith('error'); + // printing ERROR + if (error && error.trim().length !== 0 && !startsWithWarning) { + if (startsWithError) { + //removing the keyword 'ERROR' to avoid duplicates while throwing error + error = error.slice(5); + } + core.setFailed(error); } } } @@ -190,6 +188,7 @@ function main() { commonArgs = commonArgs.concat("--federated-token", federatedToken); } else { + console.log("Note: Azure/login action also supports OIDC login mechanism. Refer https://github.com/azure/login#configure-a-service-principal-with-a-federated-credential-to-use-oidc-based-authentication for more details."); commonArgs = commonArgs.concat("-p", servicePrincipalKey); } yield executeAzCliCommand(`login`, true, loginOptions, commonArgs); @@ -213,10 +212,10 @@ function main() { } catch (error) { if (!isAzCLISuccess) { - core.setFailed("Az CLI Login failed. Please check the credentials and make sure az is istalled on the runner. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"); + core.setFailed("Az CLI Login failed. Please check the credentials and make sure az is installed on the runner. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"); } else { - core.setFailed(`Azure PowerShell Login failed. Please check the credentials and make sure az is istalled on the runner. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"`); + core.setFailed(`Azure PowerShell Login failed. Please check the credentials and make sure az is installed on the runner. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"`); } } finally { @@ -240,4 +239,4 @@ function jwtParser(federatedToken) { return [decodedPayload['iss'], decodedPayload['sub']]; }); } -main(); +main(); \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 616b3ddc..aff75d14 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,22 +12,20 @@ var azPSHostEnv = !!process.env.AZUREPS_HOST_ENVIRONMENT ? `${process.env.AZUREP async function main() { try { //Options for error handling - let commandStdErr = false; const loginOptions: ExecOptions = { silent: true, - ignoreReturnCode: true, - failOnStdErr: true, listeners: { stderr: (data: Buffer) => { let error = data.toString(); - //removing the keyword 'ERROR' to avoid duplicates while throwing error - if (error.toLowerCase().startsWith('error')) { - error = error.slice(5); - } - // printing error - if (error && error.trim().length !== 0) { - commandStdErr = true; - core.error(error); + let startsWithWarning = error.toLowerCase().startsWith('warning'); + let startsWithError = error.toLowerCase().startsWith('error'); + // printing ERROR + if (error && error.trim().length !== 0 && !startsWithWarning) { + if(startsWithError) { + //removing the keyword 'ERROR' to avoid duplicates while throwing error + error = error.slice(5); + } + core.setFailed(error); } } } @@ -174,6 +172,7 @@ async function main() { commonArgs = commonArgs.concat("--federated-token", federatedToken); } else { + console.log("Note: Azure/login action also supports OIDC login mechanism. Refer https://github.com/azure/login#configure-a-service-principal-with-a-federated-credential-to-use-oidc-based-authentication for more details.") commonArgs = commonArgs.concat("-p", servicePrincipalKey); } await executeAzCliCommand(`login`, true, loginOptions, commonArgs); @@ -235,4 +234,4 @@ async function jwtParser(federatedToken: string) { let decodedPayload = JSON.parse(bufferObj.toString("utf8")); return [decodedPayload['iss'], decodedPayload['sub']]; } -main(); +main(); \ No newline at end of file