Compare commits

..

3 Commits

Author SHA1 Message Date
aksm-ms
f5c7e9ca7a adding params to escape symbols in az cli (#80)
* adding params to escape symbols in az cli

* addressed review comments
2020-11-06 15:39:04 +05:30
aksm-ms
9801a35baf adding az cli version debug logs (#76) (#78) 2020-11-03 17:27:24 +05:30
aksm-ms
e2ec7a0d58 Added no subscription support (#73) (#77)
* Added no subscription support (#73)

* Added no subscription support

* Added L0s

* added no subcriptions login support

* test changes

Co-authored-by: Ganesh S <ganeshs@CBREV-KESTUR.redmond.corp.microsoft.com>
Co-authored-by: aksm-ms <58936966+aksm-ms@users.noreply.github.com>

* adding lib

Co-authored-by: Ganeshrockz <ganes@microsoft.com>
Co-authored-by: Ganesh S <ganeshs@CBREV-KESTUR.redmond.corp.microsoft.com>
2020-11-03 16:15:14 +05:30
2 changed files with 68 additions and 14 deletions

View File

@@ -36,7 +36,16 @@ function main() {
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);
yield executeAzCliCommand("--version"); let output = "";
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,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) {
@@ -85,10 +111,11 @@ function main() {
} }
}); });
} }
function executeAzCliCommand(command, silent) { function executeAzCliCommand(command, silent, execOptions = {}, args = []) {
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}`, [], { silent: !!silent }); yield exec.exec(`"${azPath}" ${command}`, args, execOptions);
} }
catch (error) { catch (error) {
throw new Error(error); throw new Error(error);

View File

@@ -21,8 +21,17 @@ 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);
await executeAzCliCommand("--version"); let output: string = "";
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);
@@ -41,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) {
@@ -70,13 +96,14 @@ async function main() {
} }
} }
async function executeAzCliCommand(command: string, silent?: boolean) { async function executeAzCliCommand(command: string, silent?: boolean, execOptions: any = {}, args: any = []) {
execOptions.silent = !!silent;
try { try {
await exec.exec(`"${azPath}" ${command}`, [], {silent: !!silent}); await exec.exec(`"${azPath}" ${command}`, args, execOptions);
} }
catch(error) { catch(error) {
throw new Error(error); throw new Error(error);
} }
} }
main(); main();