Skip to content

Commit f805ead

Browse files
committed
code refactor
1 parent a68f90e commit f805ead

2 files changed

Lines changed: 13 additions & 19 deletions

File tree

lib/loginAzurePowerShell.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ const io = __importStar(require("@actions/io"));
2323
var psPath;
2424
exports.initializeAz = (servicePrincipalId, servicePrincipalKey, tenantId, subscriptionId) => __awaiter(void 0, void 0, void 0, function* () {
2525
psPath = yield io.which("pwsh", true);
26+
const prefix = "az_";
2627
setPSModulePath();
27-
setPSModulePath(yield getLatestModule());
28+
const azLatestVersion = yield getLatestAzModule();
29+
setPSModulePath(`${prefix}${azLatestVersion}`);
2830
yield loginToAzure(servicePrincipalId, servicePrincipalKey, tenantId, subscriptionId);
2931
});
3032
function setPSModulePath(azPSVersion = "") {
@@ -45,7 +47,7 @@ function setPSModulePath(azPSVersion = "") {
4547
}
4648
process.env.PSModulePath = `${modulePath}${process.env.PSModulePath}`;
4749
}
48-
function getLatestModule() {
50+
function getLatestAzModule() {
4951
return __awaiter(this, void 0, void 0, function* () {
5052
const moduleName = "Az.Accounts";
5153
let output = "";
@@ -62,7 +64,7 @@ function getLatestModule() {
6264
};
6365
yield executePowerShellCommand(`(Get-Module -Name ${moduleName} -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1).Version.ToString()`, options);
6466
core.debug(`Az Module version used: ${output}`);
65-
return `az_${output}`;
67+
return output;
6668
});
6769
}
6870
function loginToAzure(servicePrincipalId, servicePrincipalKey, tenantId, subscriptionId) {
@@ -79,11 +81,6 @@ function loginToAzure(servicePrincipalId, servicePrincipalKey, tenantId, subscri
7981
}
8082
function executePowerShellCommand(command, options = {}) {
8183
return __awaiter(this, void 0, void 0, function* () {
82-
try {
83-
yield exec.exec(`"${psPath}" -Command "${command}"`, [], options);
84-
}
85-
catch (error) {
86-
throw new Error(error);
87-
}
84+
yield exec.exec(`"${psPath}" -Command "${command}"`, [], options);
8885
});
8986
}

src/loginAzurePowerShell.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import * as os from 'os';
22
import * as core from '@actions/core';
33
import * as exec from '@actions/exec';
44
import * as io from '@actions/io';
5-
import { defaultCoreCipherList } from 'constants';
65

76
var psPath: string;
87

98
export const initializeAz = async (servicePrincipalId: string, servicePrincipalKey: string, tenantId: string, subscriptionId: string) => {
109
psPath = await io.which("pwsh", true);
10+
const prefix = "az_";
1111
setPSModulePath();
12-
setPSModulePath(await getLatestModule());
12+
const azLatestVersion: string = await getLatestAzModule();
13+
setPSModulePath(`${prefix}${azLatestVersion}`);
1314
await loginToAzure(servicePrincipalId, servicePrincipalKey, tenantId, subscriptionId);
1415
}
1516

@@ -32,7 +33,7 @@ function setPSModulePath(azPSVersion: string = "") {
3233
process.env.PSModulePath = `${modulePath}${process.env.PSModulePath}`;
3334
}
3435

35-
async function getLatestModule() {
36+
async function getLatestAzModule() {
3637
const moduleName: string = "Az.Accounts";
3738
let output: string = "";
3839
let error: string = "";
@@ -48,7 +49,7 @@ async function getLatestModule() {
4849
};
4950
await executePowerShellCommand(`(Get-Module -Name ${moduleName} -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1).Version.ToString()`, options);
5051
core.debug(`Az Module version used: ${output}`);
51-
return `az_${output}`;
52+
return output;
5253
}
5354

5455
async function loginToAzure(servicePrincipalId: string, servicePrincipalKey: string, tenantId: string, subscriptionId: string) {
@@ -63,9 +64,5 @@ async function loginToAzure(servicePrincipalId: string, servicePrincipalKey: str
6364
}
6465

6566
async function executePowerShellCommand(command: string, options: any = {}) {
66-
try {
67-
await exec.exec(`"${psPath}" -Command "${command}"`, [], options);
68-
} catch (error) {
69-
throw new Error(error);
70-
}
71-
}
67+
await exec.exec(`"${psPath}" -Command "${command}"`, [], options);
68+
}

0 commit comments

Comments
 (0)