Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ inputs:
description: 'The type of authentication. Supported values are SERVICE_PRINCIPAL, IDENTITY. Default value is SERVICE_PRINCIPAL'
required: false
default: 'SERVICE_PRINCIPAL'
az-path:
description: 'Override the location of the Azure CLI program'
required: false
branding:
icon: 'login.svg'
color: 'blue'
Expand Down
7 changes: 5 additions & 2 deletions src/Cli/AzureCliLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as io from '@actions/io';
export class AzureCliLogin {
loginConfig: LoginConfig;
azPath: string;
azPathOverridden: boolean;
loginOptions: ExecOptions;
azVersion: string;

Expand All @@ -17,7 +18,8 @@ export class AzureCliLogin {

async login() {
core.info(`Running Azure CLI Login.`);
this.azPath = await io.which("az", true);
this.azPath = this.loginConfig.azPath;
this.azPathOverridden = this.loginConfig.azPathOverridden;
core.debug(`Azure CLI path: ${this.azPath}`);

let output: string = "";
Expand Down Expand Up @@ -159,7 +161,8 @@ export class AzureCliLogin {
silent?: boolean,
execOptions: any = {}) {
execOptions.silent = !!silent;
await exec.exec(`"${this.azPath}"`, args, execOptions);
const azPath = this.azPathOverridden ? this.azPath : `"${this.azPath}`;
await exec.exec(azPath, args, execOptions);
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/common/LoginConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as core from '@actions/core';
import * as io from "@actions/io";

export class LoginConfig {
static readonly AUTH_TYPE_SERVICE_PRINCIPAL = "SERVICE_PRINCIPAL";
Expand All @@ -25,6 +26,8 @@ export class LoginConfig {
enableAzPSSession: boolean;
audience: string;
federatedToken: string;
azPath: string;
azPathOverridden: boolean;

async initialize() {
this.environment = core.getInput("environment").toLowerCase();
Expand All @@ -41,11 +44,23 @@ export class LoginConfig {

this.audience = core.getInput('audience', { required: false });
this.federatedToken = null;
await this.getAzPath();

this.mask(this.servicePrincipalId);
this.mask(this.servicePrincipalSecret);
}

private async getAzPath(): Promise<void> {
this.azPath = core.getInput('az-path', { required: false });
if (this.azPath) {
this.azPathOverridden = true
return;
}

this.azPath = await io.which('az', true);
this.azPathOverridden = false
}

private readParametersFromCreds() {
let creds = core.getInput('creds', { required: false });
if (!creds) {
Expand Down
13 changes: 11 additions & 2 deletions src/common/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ export function setUserAgent(): void {
}

export async function cleanupAzCLIAccounts(): Promise<void> {
let azPath = await io.which("az", true);
let azPath = core.getInput('az-path', { required: false });
let wrap = false
if (!azPath) {
azPath = await io.which('az', true);
wrap = true
}

core.debug(`Azure CLI path: ${azPath}`);
core.info("Clearing azure cli accounts from the local cache.");
await exec.exec(`"${azPath}"`, ["account", "clear"]);
if (wrap) {
azPath = `"${azPath}"`;
}
await exec.exec(azPath, ["account", "clear"]);
}

export async function cleanupAzPSAccounts(): Promise<void> {
Expand Down