mirror of
https://github.com/azure/login.git
synced 2026-03-15 09:20:56 -04:00
adding params to escape symbols in az cli (#80)
* adding params to escape symbols in az cli * addressed review comments
This commit is contained in:
36
lib/main.js
36
lib/main.js
@@ -37,16 +37,15 @@ function main() {
|
|||||||
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 = "";
|
let output = "";
|
||||||
const options = {
|
const execOptions = {
|
||||||
listeners: {
|
listeners: {
|
||||||
stdout: (data) => {
|
stdout: (data) => {
|
||||||
output += data.toString();
|
output += data.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
yield executeAzCliCommand("--version", true, options);
|
yield executeAzCliCommand("--version", true, execOptions);
|
||||||
core.debug(`az cli version used:\n${output}`);
|
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);
|
||||||
@@ -55,7 +54,6 @@ function main() {
|
|||||||
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";
|
const allowNoSubscriptionsLogin = core.getInput('allow-no-subscriptions').toLowerCase() === "true";
|
||||||
|
|
||||||
if (!servicePrincipalId || !servicePrincipalKey || !tenantId) {
|
if (!servicePrincipalId || !servicePrincipalKey || !tenantId) {
|
||||||
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret and tenantId are supplied.");
|
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret and tenantId are supplied.");
|
||||||
}
|
}
|
||||||
@@ -64,11 +62,28 @@ function main() {
|
|||||||
}
|
}
|
||||||
// Attempting Az cli login
|
// Attempting Az cli login
|
||||||
if (allowNoSubscriptionsLogin) {
|
if (allowNoSubscriptionsLogin) {
|
||||||
yield executeAzCliCommand(`login --allow-no-subscriptions --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
|
let args = [
|
||||||
|
"--allow-no-subscriptions",
|
||||||
|
"--service-principal",
|
||||||
|
"-u", servicePrincipalId,
|
||||||
|
"-p", servicePrincipalKey,
|
||||||
|
"--tenant", tenantId
|
||||||
|
];
|
||||||
|
yield executeAzCliCommand(`login`, true, {}, args);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
yield executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
|
let args = [
|
||||||
yield executeAzCliCommand(`account set --subscription "${subscriptionId}"`, true);
|
"--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) {
|
||||||
@@ -96,12 +111,11 @@ function main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function executeAzCliCommand(command, silent, execOptions = {}, args = []) {
|
||||||
function executeAzCliCommand(command, silent, options = {}) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
options.silent = !!silent;
|
execOptions.silent = !!silent;
|
||||||
try {
|
try {
|
||||||
yield exec.exec(`"${azPath}" ${command}`, [], options);
|
yield exec.exec(`"${azPath}" ${command}`, args, execOptions);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
|
|||||||
33
src/main.ts
33
src/main.ts
@@ -22,14 +22,14 @@ async function main() {
|
|||||||
|
|
||||||
azPath = await io.which("az", true);
|
azPath = await io.which("az", true);
|
||||||
let output: string = "";
|
let output: string = "";
|
||||||
const options: any = {
|
const execOptions: any = {
|
||||||
listeners: {
|
listeners: {
|
||||||
stdout: (data: Buffer) => {
|
stdout: (data: Buffer) => {
|
||||||
output += data.toString();
|
output += data.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
await executeAzCliCommand("--version", true, options);
|
await executeAzCliCommand("--version", true, execOptions);
|
||||||
core.debug(`az cli version used:\n${output}`);
|
core.debug(`az cli version used:\n${output}`);
|
||||||
|
|
||||||
let creds = core.getInput('creds', { required: true });
|
let creds = core.getInput('creds', { required: true });
|
||||||
@@ -50,11 +50,28 @@ async function main() {
|
|||||||
|
|
||||||
// Attempting Az cli login
|
// Attempting Az cli login
|
||||||
if (allowNoSubscriptionsLogin) {
|
if (allowNoSubscriptionsLogin) {
|
||||||
await executeAzCliCommand(`login --allow-no-subscriptions --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
|
let args = [
|
||||||
|
"--allow-no-subscriptions",
|
||||||
|
"--service-principal",
|
||||||
|
"-u", servicePrincipalId,
|
||||||
|
"-p", servicePrincipalKey,
|
||||||
|
"--tenant", tenantId
|
||||||
|
];
|
||||||
|
await executeAzCliCommand(`login`, true, {}, args);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
|
let args = [
|
||||||
await executeAzCliCommand(`account set --subscription "${subscriptionId}"`, true);
|
"--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) {
|
||||||
@@ -79,10 +96,10 @@ async function main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function executeAzCliCommand(command: string, silent?: boolean, options: any = {}) {
|
async function executeAzCliCommand(command: string, silent?: boolean, execOptions: any = {}, args: any = []) {
|
||||||
options.silent = !!silent;
|
execOptions.silent = !!silent;
|
||||||
try {
|
try {
|
||||||
await exec.exec(`"${azPath}" ${command}`, [], options);
|
await exec.exec(`"${azPath}" ${command}`, args, execOptions);
|
||||||
}
|
}
|
||||||
catch(error) {
|
catch(error) {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user