From 97c66dece89e7157f1ea9c7e6bffb39a0d81b21e Mon Sep 17 00:00:00 2001 From: Akshaya M Date: Tue, 24 Mar 2020 14:17:39 +0530 Subject: [PATCH] added review comments --- src/PowerShell/ServicePrincipalLogin.ts | 6 +++--- src/PowerShell/Utilities/Utils.ts | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/PowerShell/ServicePrincipalLogin.ts b/src/PowerShell/ServicePrincipalLogin.ts index 1bb27daa..3ee2c891 100644 --- a/src/PowerShell/ServicePrincipalLogin.ts +++ b/src/PowerShell/ServicePrincipalLogin.ts @@ -47,9 +47,9 @@ export class ServicePrincipalLogin implements IAzurePowerShellSession { const script: string = new ScriptBuilder().getAzPSLoginScript(ServicePrincipalLogin.scheme, this.tenantId, args); await PowerShellToolRunner.init(); await PowerShellToolRunner.executePowerShellScriptBlock(script, options); - const outputJson: any = JSON.parse(output.trim()); - if (!(Constants.Success in outputJson)) { - throw new Error(`Azure PowerShell login failed with error: ${outputJson[Constants.Error]}`); + const result: any = JSON.parse(output.trim()); + if (!(Constants.Success in result)) { + throw new Error(`Azure PowerShell login failed with error: ${result[Constants.Error]}`); } } diff --git a/src/PowerShell/Utilities/Utils.ts b/src/PowerShell/Utilities/Utils.ts index c8b4a00c..1fa3635e 100644 --- a/src/PowerShell/Utilities/Utils.ts +++ b/src/PowerShell/Utilities/Utils.ts @@ -5,6 +5,15 @@ import ScriptBuilder from './ScriptBuilder'; import PowerShellToolRunner from './PowerShellToolRunner'; export default class Utils { + /** + * Add the folder path where Az modules are present to PSModulePath based on runner + * + * @param azPSVersion + * + * If azPSVersion is empty, folder path in which all Az modules are present are set + * If azPSVersion is not empty, folder path of exact Az module version is set + * + */ static setPSModulePath(azPSVersion: string = "") { let modulePath: string = ""; const runner: string = process.env.RUNNER_OS || os.type(); @@ -37,11 +46,11 @@ export default class Utils { await PowerShellToolRunner.init(); await PowerShellToolRunner.executePowerShellScriptBlock(new ScriptBuilder() .getLatestModuleScript(moduleName), options); - const outputJson = JSON.parse(output.trim()); - if (!(Constants.Success in outputJson)) { - throw new Error(outputJson[Constants.Error]); + const result = JSON.parse(output.trim()); + if (!(Constants.Success in result)) { + throw new Error(result[Constants.Error]); } - const azLatestVersion: string = outputJson[Constants.AzVersion]; + const azLatestVersion: string = result[Constants.AzVersion]; if (!Utils.isValidVersion(azLatestVersion)) { throw new Error(`Invalid AzPSVersion: ${azLatestVersion}`); }