Compare commits

..

2 Commits

Author SHA1 Message Date
aksm-ms
f001fbb0b9 Update main.js 2020-11-16 17:48:14 +05:30
aksm-ms
b4fcf5d07d adding az cli version debug logs (#76) 2020-11-03 17:17:50 +05:30
2 changed files with 20 additions and 50 deletions

View File

@@ -37,15 +37,16 @@ function main() {
core.exportVariable('AZUREPS_HOST_ENVIRONMENT', azurePSHostEnv);
azPath = yield io.which("az", true);
let output = "";
const execOptions = {
const options = {
listeners: {
stdout: (data) => {
output += data.toString();
}
}
};
yield executeAzCliCommand("--version", true, execOptions);
yield executeAzCliCommand("--version", true, options);
core.debug(`az cli version used:\n${output}`);
let creds = core.getInput('creds', { required: true });
let secrets = new actions_secret_parser_1.SecretParser(creds, actions_secret_parser_1.FormatType.JSON);
let servicePrincipalId = secrets.getSecret("$.clientId", false);
@@ -54,6 +55,7 @@ function main() {
let subscriptionId = secrets.getSecret("$.subscriptionId", false);
const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true";
const allowNoSubscriptionsLogin = core.getInput('allow-no-subscriptions').toLowerCase() === "true";
if (!servicePrincipalId || !servicePrincipalKey || !tenantId) {
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret and tenantId are supplied.");
}
@@ -61,29 +63,13 @@ function main() {
throw new Error("Not all values are present in the creds object. Ensure subscriptionId is supplied.");
}
// Attempting Az cli login
console.log(`ak - clientId: ${servicePrincipalId}`);
if (allowNoSubscriptionsLogin) {
let args = [
"--allow-no-subscriptions",
"--service-principal",
"-u", servicePrincipalId,
"-p", servicePrincipalKey,
"--tenant", tenantId
];
yield executeAzCliCommand(`login`, true, {}, args);
yield executeAzCliCommand(`login --allow-no-subscriptions --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
}
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);
yield executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
yield executeAzCliCommand(`account set --subscription "${subscriptionId}"`, true);
}
isAzCLISuccess = true;
if (enableAzPSSession) {
@@ -111,11 +97,12 @@ function main() {
}
});
}
function executeAzCliCommand(command, silent, execOptions = {}, args = []) {
function executeAzCliCommand(command, silent, options = {}) {
return __awaiter(this, void 0, void 0, function* () {
execOptions.silent = !!silent;
options.silent = !!silent;
try {
yield exec.exec(`"${azPath}" ${command}`, args, execOptions);
yield exec.exec(`"${azPath}" ${command}`, [], options);
}
catch (error) {
throw new Error(error);

View File

@@ -22,14 +22,14 @@ async function main() {
azPath = await io.which("az", true);
let output: string = "";
const execOptions: any = {
const options: any = {
listeners: {
stdout: (data: Buffer) => {
output += data.toString();
}
}
};
await executeAzCliCommand("--version", true, execOptions);
await executeAzCliCommand("--version", true, options);
core.debug(`az cli version used:\n${output}`);
let creds = core.getInput('creds', { required: true });
@@ -50,28 +50,11 @@ async function main() {
// Attempting Az cli login
if (allowNoSubscriptionsLogin) {
let args = [
"--allow-no-subscriptions",
"--service-principal",
"-u", servicePrincipalId,
"-p", servicePrincipalKey,
"--tenant", tenantId
];
await executeAzCliCommand(`login`, true, {}, args);
await executeAzCliCommand(`login --allow-no-subscriptions --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
}
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);
await executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
await executeAzCliCommand(`account set --subscription "${subscriptionId}"`, true);
}
isAzCLISuccess = true;
if (enableAzPSSession) {
@@ -96,10 +79,10 @@ async function main() {
}
}
async function executeAzCliCommand(command: string, silent?: boolean, execOptions: any = {}, args: any = []) {
execOptions.silent = !!silent;
async function executeAzCliCommand(command: string, silent?: boolean, options: any = {}) {
options.silent = !!silent;
try {
await exec.exec(`"${azPath}" ${command}`, args, execOptions);
await exec.exec(`"${azPath}" ${command}`, [], options);
}
catch(error) {
throw new Error(error);