From 9801a35baff5850a97d2f2855092ebea3c579837 Mon Sep 17 00:00:00 2001 From: aksm-ms <58936966+aksm-ms@users.noreply.github.com> Date: Tue, 3 Nov 2020 17:27:24 +0530 Subject: [PATCH] adding az cli version debug logs (#76) (#78) --- lib/main.js | 19 ++++++++++++++++--- src/main.ts | 20 +++++++++++++++----- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index eb708357..1527cd26 100644 --- a/lib/main.js +++ b/lib/main.js @@ -36,7 +36,17 @@ function main() { core.exportVariable('AZURE_HTTP_USER_AGENT', userAgentString); core.exportVariable('AZUREPS_HOST_ENVIRONMENT', azurePSHostEnv); azPath = yield io.which("az", true); - yield executeAzCliCommand("--version"); + let output = ""; + const options = { + listeners: { + stdout: (data) => { + output += data.toString(); + } + } + }; + yield executeAzCliCommand("--version", true, options); + core.debug(`az cli version used:\n${output}`); + let creds = core.getInput('creds', { required: true }); let secrets = new actions_secret_parser_1.SecretParser(creds, actions_secret_parser_1.FormatType.JSON); let servicePrincipalId = secrets.getSecret("$.clientId", false); @@ -45,6 +55,7 @@ function main() { let subscriptionId = secrets.getSecret("$.subscriptionId", false); const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true"; const allowNoSubscriptionsLogin = core.getInput('allow-no-subscriptions').toLowerCase() === "true"; + if (!servicePrincipalId || !servicePrincipalKey || !tenantId) { throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret and tenantId are supplied."); } @@ -85,10 +96,12 @@ function main() { } }); } -function executeAzCliCommand(command, silent) { + +function executeAzCliCommand(command, silent, options = {}) { return __awaiter(this, void 0, void 0, function* () { + options.silent = !!silent; try { - yield exec.exec(`"${azPath}" ${command}`, [], { silent: !!silent }); + yield exec.exec(`"${azPath}" ${command}`, [], options); } catch (error) { throw new Error(error); diff --git a/src/main.ts b/src/main.ts index 572c352c..3288986e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,8 +21,17 @@ async function main() { core.exportVariable('AZUREPS_HOST_ENVIRONMENT', azurePSHostEnv); azPath = await io.which("az", true); - await executeAzCliCommand("--version"); - + let output: string = ""; + const options: any = { + listeners: { + stdout: (data: Buffer) => { + output += data.toString(); + } + } + }; + await executeAzCliCommand("--version", true, options); + core.debug(`az cli version used:\n${output}`); + let creds = core.getInput('creds', { required: true }); let secrets = new SecretParser(creds, FormatType.JSON); let servicePrincipalId = secrets.getSecret("$.clientId", false); @@ -70,13 +79,14 @@ async function main() { } } -async function executeAzCliCommand(command: string, silent?: boolean) { +async function executeAzCliCommand(command: string, silent?: boolean, options: any = {}) { + options.silent = !!silent; try { - await exec.exec(`"${azPath}" ${command}`, [], {silent: !!silent}); + await exec.exec(`"${azPath}" ${command}`, [], options); } catch(error) { throw new Error(error); } } -main(); +main(); \ No newline at end of file