mirror of
https://github.com/azure/login.git
synced 2026-03-15 09:20:56 -04:00
Compare commits
4 Commits
users/aksm
...
users/amka
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f46858e96a | ||
|
|
6f417f0b69 | ||
|
|
ba7c65aab7 | ||
|
|
c4a046bb16 |
@@ -5,7 +5,7 @@ jest.mock('../../src/PowerShell/Utilities/PowerShellToolRunner');
|
|||||||
let spnlogin: ServicePrincipalLogin;
|
let spnlogin: ServicePrincipalLogin;
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
spnlogin = new ServicePrincipalLogin("servicePrincipalID", "servicePrinicipalkey", "tenantId", "subscriptionId", false);
|
spnlogin = new ServicePrincipalLogin("servicePrincipalID", "servicePrinicipalkey", "tenantId", "subscriptionId");
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
import ScriptBuilder from "../../../src/PowerShell/Utilities/ScriptBuilder";
|
|
||||||
import Constants from "../../../src/PowerShell/Constants";
|
|
||||||
|
|
||||||
describe("Getting AzLogin PS script" , () => {
|
|
||||||
const scheme = Constants.ServicePrincipal;
|
|
||||||
let args: any = {
|
|
||||||
servicePrincipalId: "service-principal-id",
|
|
||||||
servicePrincipalKey: "service-principal-key",
|
|
||||||
environment: "environment",
|
|
||||||
scopeLevel: Constants.Subscription,
|
|
||||||
subscriptionId: "subId",
|
|
||||||
allowNoSubscriptionsLogin: true
|
|
||||||
}
|
|
||||||
|
|
||||||
test("PS script should not set context while passing allowNoSubscriptionsLogin as true", () => {
|
|
||||||
const loginScript = new ScriptBuilder().getAzPSLoginScript(scheme, "tenant-id", args);
|
|
||||||
expect(loginScript.includes("Set-AzContext -SubscriptionId")).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("PS script should set context while passing allowNoSubscriptionsLogin as false", () => {
|
|
||||||
args["allowNoSubscriptionsLogin"] = false;
|
|
||||||
const loginScript = new ScriptBuilder().getAzPSLoginScript(scheme, "tenant-id", args);
|
|
||||||
expect(loginScript.includes("Set-AzContext -SubscriptionId")).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -9,10 +9,6 @@ inputs:
|
|||||||
description: 'Set this value to true to enable Azure PowerShell Login in addition to Az CLI login'
|
description: 'Set this value to true to enable Azure PowerShell Login in addition to Az CLI login'
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: false
|
||||||
allow-no-subscriptions:
|
|
||||||
description: 'Set this value to true to enable support for accessing tenants without subscriptions'
|
|
||||||
required: false
|
|
||||||
default: false
|
|
||||||
branding:
|
branding:
|
||||||
icon: 'login.svg'
|
icon: 'login.svg'
|
||||||
color: 'blue'
|
color: 'blue'
|
||||||
|
|||||||
@@ -25,12 +25,11 @@ const PowerShellToolRunner_1 = __importDefault(require("./Utilities/PowerShellTo
|
|||||||
const ScriptBuilder_1 = __importDefault(require("./Utilities/ScriptBuilder"));
|
const ScriptBuilder_1 = __importDefault(require("./Utilities/ScriptBuilder"));
|
||||||
const Constants_1 = __importDefault(require("./Constants"));
|
const Constants_1 = __importDefault(require("./Constants"));
|
||||||
class ServicePrincipalLogin {
|
class ServicePrincipalLogin {
|
||||||
constructor(servicePrincipalId, servicePrincipalKey, tenantId, subscriptionId, allowNoSubscriptionsLogin) {
|
constructor(servicePrincipalId, servicePrincipalKey, tenantId, subscriptionId) {
|
||||||
this.servicePrincipalId = servicePrincipalId;
|
this.servicePrincipalId = servicePrincipalId;
|
||||||
this.servicePrincipalKey = servicePrincipalKey;
|
this.servicePrincipalKey = servicePrincipalKey;
|
||||||
this.tenantId = tenantId;
|
this.tenantId = tenantId;
|
||||||
this.subscriptionId = subscriptionId;
|
this.subscriptionId = subscriptionId;
|
||||||
this.allowNoSubscriptionsLogin = allowNoSubscriptionsLogin;
|
|
||||||
}
|
}
|
||||||
initialize() {
|
initialize() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
@@ -55,8 +54,7 @@ class ServicePrincipalLogin {
|
|||||||
servicePrincipalKey: this.servicePrincipalKey,
|
servicePrincipalKey: this.servicePrincipalKey,
|
||||||
subscriptionId: this.subscriptionId,
|
subscriptionId: this.subscriptionId,
|
||||||
environment: ServicePrincipalLogin.environment,
|
environment: ServicePrincipalLogin.environment,
|
||||||
scopeLevel: ServicePrincipalLogin.scopeLevel,
|
scopeLevel: ServicePrincipalLogin.scopeLevel
|
||||||
allowNoSubscriptionsLogin: this.allowNoSubscriptionsLogin
|
|
||||||
};
|
};
|
||||||
const script = new ScriptBuilder_1.default().getAzPSLoginScript(ServicePrincipalLogin.scheme, this.tenantId, args);
|
const script = new ScriptBuilder_1.default().getAzPSLoginScript(ServicePrincipalLogin.scheme, this.tenantId, args);
|
||||||
yield PowerShellToolRunner_1.default.init();
|
yield PowerShellToolRunner_1.default.init();
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class ScriptBuilder {
|
|||||||
command += `Connect-AzAccount -ServicePrincipal -Tenant '${tenantId}' -Credential \
|
command += `Connect-AzAccount -ServicePrincipal -Tenant '${tenantId}' -Credential \
|
||||||
(New-Object System.Management.Automation.PSCredential('${args.servicePrincipalId}',(ConvertTo-SecureString '${args.servicePrincipalKey.replace("'", "''")}' -AsPlainText -Force))) \
|
(New-Object System.Management.Automation.PSCredential('${args.servicePrincipalId}',(ConvertTo-SecureString '${args.servicePrincipalKey.replace("'", "''")}' -AsPlainText -Force))) \
|
||||||
-Environment '${args.environment}' | out-null;`;
|
-Environment '${args.environment}' | out-null;`;
|
||||||
if (args.scopeLevel === Constants_1.default.Subscription && !args.allowNoSubscriptionsLogin) {
|
if (args.scopeLevel === Constants_1.default.Subscription) {
|
||||||
command += `Set-AzContext -SubscriptionId '${args.subscriptionId}' -TenantId '${tenantId}' | out-null;`;
|
command += `Set-AzContext -SubscriptionId '${args.subscriptionId}' -TenantId '${tenantId}' | out-null;`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
55
lib/main.js
55
lib/main.js
@@ -17,6 +17,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
|
const crypto = __importStar(require("crypto"));
|
||||||
const exec = __importStar(require("@actions/exec"));
|
const exec = __importStar(require("@actions/exec"));
|
||||||
const io = __importStar(require("@actions/io"));
|
const io = __importStar(require("@actions/io"));
|
||||||
const actions_secret_parser_1 = require("actions-secret-parser");
|
const actions_secret_parser_1 = require("actions-secret-parser");
|
||||||
@@ -29,23 +30,14 @@ function main() {
|
|||||||
try {
|
try {
|
||||||
// Set user agent variable
|
// Set user agent variable
|
||||||
var isAzCLISuccess = false;
|
var isAzCLISuccess = false;
|
||||||
let usrAgentRepo = `${process.env.GITHUB_REPOSITORY}`;
|
let usrAgentRepo = crypto.createHash('sha256').update(`${process.env.GITHUB_REPOSITORY}`).digest('hex');
|
||||||
let actionName = 'AzureLogin';
|
let actionName = 'AzureLogin';
|
||||||
let userAgentString = (!!prefix ? `${prefix}+` : '') + `GITHUBACTIONS/${actionName}@v1_${usrAgentRepo}`;
|
let userAgentString = (!!prefix ? `${prefix}+` : '') + `GITHUBACTIONS/${actionName}@v1_${usrAgentRepo}`;
|
||||||
let azurePSHostEnv = (!!azPSHostEnv ? `${azPSHostEnv}+` : '') + `GITHUBACTIONS/${actionName}@v1_${usrAgentRepo}`;
|
let azurePSHostEnv = (!!azPSHostEnv ? `${azPSHostEnv}+` : '') + `GITHUBACTIONS/${actionName}@v1_${usrAgentRepo}`;
|
||||||
core.exportVariable('AZURE_HTTP_USER_AGENT', userAgentString);
|
core.exportVariable('AZURE_HTTP_USER_AGENT', userAgentString);
|
||||||
core.exportVariable('AZUREPS_HOST_ENVIRONMENT', azurePSHostEnv);
|
core.exportVariable('AZUREPS_HOST_ENVIRONMENT', azurePSHostEnv);
|
||||||
azPath = yield io.which("az", true);
|
azPath = yield io.which("az", true);
|
||||||
let output = "";
|
yield executeAzCliCommand("--version");
|
||||||
const execOptions = {
|
|
||||||
listeners: {
|
|
||||||
stdout: (data) => {
|
|
||||||
output += data.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
yield executeAzCliCommand("--version", true, execOptions);
|
|
||||||
core.debug(`az cli version used:\n${output}`);
|
|
||||||
let creds = core.getInput('creds', { required: true });
|
let creds = core.getInput('creds', { required: true });
|
||||||
let secrets = new actions_secret_parser_1.SecretParser(creds, actions_secret_parser_1.FormatType.JSON);
|
let secrets = new actions_secret_parser_1.SecretParser(creds, actions_secret_parser_1.FormatType.JSON);
|
||||||
let servicePrincipalId = secrets.getSecret("$.clientId", false);
|
let servicePrincipalId = secrets.getSecret("$.clientId", false);
|
||||||
@@ -53,43 +45,17 @@ function main() {
|
|||||||
let tenantId = secrets.getSecret("$.tenantId", false);
|
let tenantId = secrets.getSecret("$.tenantId", false);
|
||||||
let subscriptionId = secrets.getSecret("$.subscriptionId", false);
|
let subscriptionId = secrets.getSecret("$.subscriptionId", false);
|
||||||
const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true";
|
const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true";
|
||||||
const allowNoSubscriptionsLogin = core.getInput('allow-no-subscriptions').toLowerCase() === "true";
|
if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !subscriptionId) {
|
||||||
if (!servicePrincipalId || !servicePrincipalKey || !tenantId) {
|
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret, tenantId and subscriptionId are supplied.");
|
||||||
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret and tenantId are supplied.");
|
|
||||||
}
|
|
||||||
if (!subscriptionId && !allowNoSubscriptionsLogin) {
|
|
||||||
throw new Error("Not all values are present in the creds object. Ensure subscriptionId is supplied.");
|
|
||||||
}
|
}
|
||||||
// Attempting Az cli login
|
// Attempting Az cli login
|
||||||
if (allowNoSubscriptionsLogin) {
|
yield executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
|
||||||
let args = [
|
yield executeAzCliCommand(`account set --subscription "${subscriptionId}"`, true);
|
||||||
"--allow-no-subscriptions",
|
|
||||||
"--service-principal",
|
|
||||||
"-u", servicePrincipalId,
|
|
||||||
"-p", servicePrincipalKey,
|
|
||||||
"--tenant", tenantId
|
|
||||||
];
|
|
||||||
yield executeAzCliCommand(`login`, true, {}, args);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
let args = [
|
|
||||||
"--service-principal",
|
|
||||||
"-u", servicePrincipalId,
|
|
||||||
"-p", servicePrincipalKey,
|
|
||||||
"--tenant", tenantId
|
|
||||||
];
|
|
||||||
yield executeAzCliCommand(`login`, true, {}, args);
|
|
||||||
args = [
|
|
||||||
"--subscription",
|
|
||||||
subscriptionId
|
|
||||||
];
|
|
||||||
yield executeAzCliCommand(`account set`, true, {}, args);
|
|
||||||
}
|
|
||||||
isAzCLISuccess = true;
|
isAzCLISuccess = true;
|
||||||
if (enableAzPSSession) {
|
if (enableAzPSSession) {
|
||||||
// Attempting Az PS login
|
// Attempting Az PS login
|
||||||
console.log(`Running Azure PS Login`);
|
console.log(`Running Azure PS Login`);
|
||||||
const spnlogin = new ServicePrincipalLogin_1.ServicePrincipalLogin(servicePrincipalId, servicePrincipalKey, tenantId, subscriptionId, allowNoSubscriptionsLogin);
|
const spnlogin = new ServicePrincipalLogin_1.ServicePrincipalLogin(servicePrincipalId, servicePrincipalKey, tenantId, subscriptionId);
|
||||||
yield spnlogin.initialize();
|
yield spnlogin.initialize();
|
||||||
yield spnlogin.login();
|
yield spnlogin.login();
|
||||||
}
|
}
|
||||||
@@ -111,11 +77,10 @@ function main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function executeAzCliCommand(command, silent, execOptions = {}, args = []) {
|
function executeAzCliCommand(command, silent) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
execOptions.silent = !!silent;
|
|
||||||
try {
|
try {
|
||||||
yield exec.exec(`"${azPath}" ${command}`, args, execOptions);
|
yield exec.exec(`"${azPath}" ${command}`, [], { silent: !!silent });
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
|
|||||||
@@ -13,18 +13,12 @@ export class ServicePrincipalLogin implements IAzurePowerShellSession {
|
|||||||
servicePrincipalKey: string;
|
servicePrincipalKey: string;
|
||||||
tenantId: string;
|
tenantId: string;
|
||||||
subscriptionId: string;
|
subscriptionId: string;
|
||||||
allowNoSubscriptionsLogin: boolean;
|
|
||||||
|
|
||||||
constructor(servicePrincipalId: string,
|
constructor(servicePrincipalId: string, servicePrincipalKey: string, tenantId: string, subscriptionId: string) {
|
||||||
servicePrincipalKey: string,
|
|
||||||
tenantId: string,
|
|
||||||
subscriptionId: string,
|
|
||||||
allowNoSubscriptionsLogin: boolean) {
|
|
||||||
this.servicePrincipalId = servicePrincipalId;
|
this.servicePrincipalId = servicePrincipalId;
|
||||||
this.servicePrincipalKey = servicePrincipalKey;
|
this.servicePrincipalKey = servicePrincipalKey;
|
||||||
this.tenantId = tenantId;
|
this.tenantId = tenantId;
|
||||||
this.subscriptionId = subscriptionId;
|
this.subscriptionId = subscriptionId;
|
||||||
this.allowNoSubscriptionsLogin = allowNoSubscriptionsLogin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async initialize() {
|
async initialize() {
|
||||||
@@ -48,8 +42,7 @@ export class ServicePrincipalLogin implements IAzurePowerShellSession {
|
|||||||
servicePrincipalKey: this.servicePrincipalKey,
|
servicePrincipalKey: this.servicePrincipalKey,
|
||||||
subscriptionId: this.subscriptionId,
|
subscriptionId: this.subscriptionId,
|
||||||
environment: ServicePrincipalLogin.environment,
|
environment: ServicePrincipalLogin.environment,
|
||||||
scopeLevel: ServicePrincipalLogin.scopeLevel,
|
scopeLevel: ServicePrincipalLogin.scopeLevel
|
||||||
allowNoSubscriptionsLogin: this.allowNoSubscriptionsLogin
|
|
||||||
}
|
}
|
||||||
const script: string = new ScriptBuilder().getAzPSLoginScript(ServicePrincipalLogin.scheme, this.tenantId, args);
|
const script: string = new ScriptBuilder().getAzPSLoginScript(ServicePrincipalLogin.scheme, this.tenantId, args);
|
||||||
await PowerShellToolRunner.init();
|
await PowerShellToolRunner.init();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export default class ScriptBuilder {
|
|||||||
command += `Connect-AzAccount -ServicePrincipal -Tenant '${tenantId}' -Credential \
|
command += `Connect-AzAccount -ServicePrincipal -Tenant '${tenantId}' -Credential \
|
||||||
(New-Object System.Management.Automation.PSCredential('${args.servicePrincipalId}',(ConvertTo-SecureString '${args.servicePrincipalKey.replace("'", "''")}' -AsPlainText -Force))) \
|
(New-Object System.Management.Automation.PSCredential('${args.servicePrincipalId}',(ConvertTo-SecureString '${args.servicePrincipalKey.replace("'", "''")}' -AsPlainText -Force))) \
|
||||||
-Environment '${args.environment}' | out-null;`;
|
-Environment '${args.environment}' | out-null;`;
|
||||||
if (args.scopeLevel === Constants.Subscription && !args.allowNoSubscriptionsLogin) {
|
if (args.scopeLevel === Constants.Subscription) {
|
||||||
command += `Set-AzContext -SubscriptionId '${args.subscriptionId}' -TenantId '${tenantId}' | out-null;`;
|
command += `Set-AzContext -SubscriptionId '${args.subscriptionId}' -TenantId '${tenantId}' | out-null;`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
59
src/main.ts
59
src/main.ts
@@ -1,4 +1,5 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
import * as crypto from "crypto";
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ async function main() {
|
|||||||
try {
|
try {
|
||||||
// Set user agent variable
|
// Set user agent variable
|
||||||
var isAzCLISuccess = false;
|
var isAzCLISuccess = false;
|
||||||
let usrAgentRepo = `${process.env.GITHUB_REPOSITORY}`;
|
let usrAgentRepo = crypto.createHash('sha256').update(`${process.env.GITHUB_REPOSITORY}`).digest('hex');
|
||||||
let actionName = 'AzureLogin';
|
let actionName = 'AzureLogin';
|
||||||
let userAgentString = (!!prefix ? `${prefix}+` : '') + `GITHUBACTIONS/${actionName}@v1_${usrAgentRepo}`;
|
let userAgentString = (!!prefix ? `${prefix}+` : '') + `GITHUBACTIONS/${actionName}@v1_${usrAgentRepo}`;
|
||||||
let azurePSHostEnv = (!!azPSHostEnv ? `${azPSHostEnv}+` : '') + `GITHUBACTIONS/${actionName}@v1_${usrAgentRepo}`;
|
let azurePSHostEnv = (!!azPSHostEnv ? `${azPSHostEnv}+` : '') + `GITHUBACTIONS/${actionName}@v1_${usrAgentRepo}`;
|
||||||
@@ -21,17 +22,8 @@ async function main() {
|
|||||||
core.exportVariable('AZUREPS_HOST_ENVIRONMENT', azurePSHostEnv);
|
core.exportVariable('AZUREPS_HOST_ENVIRONMENT', azurePSHostEnv);
|
||||||
|
|
||||||
azPath = await io.which("az", true);
|
azPath = await io.which("az", true);
|
||||||
let output: string = "";
|
await executeAzCliCommand("--version");
|
||||||
const execOptions: any = {
|
|
||||||
listeners: {
|
|
||||||
stdout: (data: Buffer) => {
|
|
||||||
output += data.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
await executeAzCliCommand("--version", true, execOptions);
|
|
||||||
core.debug(`az cli version used:\n${output}`);
|
|
||||||
|
|
||||||
let creds = core.getInput('creds', { required: true });
|
let creds = core.getInput('creds', { required: true });
|
||||||
let secrets = new SecretParser(creds, FormatType.JSON);
|
let secrets = new SecretParser(creds, FormatType.JSON);
|
||||||
let servicePrincipalId = secrets.getSecret("$.clientId", false);
|
let servicePrincipalId = secrets.getSecret("$.clientId", false);
|
||||||
@@ -39,45 +31,17 @@ async function main() {
|
|||||||
let tenantId = secrets.getSecret("$.tenantId", false);
|
let tenantId = secrets.getSecret("$.tenantId", false);
|
||||||
let subscriptionId = secrets.getSecret("$.subscriptionId", false);
|
let subscriptionId = secrets.getSecret("$.subscriptionId", false);
|
||||||
const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true";
|
const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true";
|
||||||
const allowNoSubscriptionsLogin = core.getInput('allow-no-subscriptions').toLowerCase() === "true";
|
if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !subscriptionId) {
|
||||||
if (!servicePrincipalId || !servicePrincipalKey || !tenantId) {
|
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret, tenantId and subscriptionId are supplied.");
|
||||||
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret and tenantId are supplied.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!subscriptionId && !allowNoSubscriptionsLogin) {
|
|
||||||
throw new Error("Not all values are present in the creds object. Ensure subscriptionId is supplied.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempting Az cli login
|
// Attempting Az cli login
|
||||||
if (allowNoSubscriptionsLogin) {
|
await executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
|
||||||
let args = [
|
await executeAzCliCommand(`account set --subscription "${subscriptionId}"`, true);
|
||||||
"--allow-no-subscriptions",
|
|
||||||
"--service-principal",
|
|
||||||
"-u", servicePrincipalId,
|
|
||||||
"-p", servicePrincipalKey,
|
|
||||||
"--tenant", tenantId
|
|
||||||
];
|
|
||||||
await executeAzCliCommand(`login`, true, {}, args);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
let args = [
|
|
||||||
"--service-principal",
|
|
||||||
"-u", servicePrincipalId,
|
|
||||||
"-p", servicePrincipalKey,
|
|
||||||
"--tenant", tenantId
|
|
||||||
];
|
|
||||||
await executeAzCliCommand(`login`, true, {}, args);
|
|
||||||
args = [
|
|
||||||
"--subscription",
|
|
||||||
subscriptionId
|
|
||||||
];
|
|
||||||
await executeAzCliCommand(`account set`, true, {}, args);
|
|
||||||
}
|
|
||||||
isAzCLISuccess = true;
|
isAzCLISuccess = true;
|
||||||
if (enableAzPSSession) {
|
if (enableAzPSSession) {
|
||||||
// Attempting Az PS login
|
// Attempting Az PS login
|
||||||
console.log(`Running Azure PS Login`);
|
console.log(`Running Azure PS Login`);
|
||||||
const spnlogin: ServicePrincipalLogin = new ServicePrincipalLogin(servicePrincipalId, servicePrincipalKey, tenantId, subscriptionId, allowNoSubscriptionsLogin);
|
const spnlogin: ServicePrincipalLogin = new ServicePrincipalLogin(servicePrincipalId, servicePrincipalKey, tenantId, subscriptionId);
|
||||||
await spnlogin.initialize();
|
await spnlogin.initialize();
|
||||||
await spnlogin.login();
|
await spnlogin.login();
|
||||||
}
|
}
|
||||||
@@ -96,10 +60,9 @@ async function main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function executeAzCliCommand(command: string, silent?: boolean, execOptions: any = {}, args: any = []) {
|
async function executeAzCliCommand(command: string, silent?: boolean) {
|
||||||
execOptions.silent = !!silent;
|
|
||||||
try {
|
try {
|
||||||
await exec.exec(`"${azPath}" ${command}`, args, execOptions);
|
await exec.exec(`"${azPath}" ${command}`, [], {silent: !!silent});
|
||||||
}
|
}
|
||||||
catch(error) {
|
catch(error) {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user