mirror of
https://github.com/azure/login.git
synced 2026-03-15 09:20:56 -04:00
Compare commits
2 Commits
users/aksm
...
users/aksm
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
721fa655a7 | ||
|
|
3e0006684e |
39
lib/main.js
39
lib/main.js
@@ -36,16 +36,7 @@ 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);
|
||||||
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);
|
||||||
@@ -62,28 +53,11 @@ function main() {
|
|||||||
}
|
}
|
||||||
// Attempting Az cli login
|
// Attempting Az cli login
|
||||||
if (allowNoSubscriptionsLogin) {
|
if (allowNoSubscriptionsLogin) {
|
||||||
let args = [
|
yield executeAzCliCommand(`login --allow-no-subscriptions --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
|
||||||
"--allow-no-subscriptions",
|
|
||||||
"--service-principal",
|
|
||||||
"-u", servicePrincipalId,
|
|
||||||
"-p", servicePrincipalKey,
|
|
||||||
"--tenant", tenantId
|
|
||||||
];
|
|
||||||
yield executeAzCliCommand(`login`, true, {}, args);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let args = [
|
yield executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
|
||||||
"--service-principal",
|
yield executeAzCliCommand(`account set --subscription "${subscriptionId}"`, true);
|
||||||
"-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) {
|
||||||
@@ -111,11 +85,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);
|
||||||
|
|||||||
39
src/main.ts
39
src/main.ts
@@ -21,16 +21,7 @@ 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);
|
||||||
@@ -50,28 +41,11 @@ async function main() {
|
|||||||
|
|
||||||
// Attempting Az cli login
|
// Attempting Az cli login
|
||||||
if (allowNoSubscriptionsLogin) {
|
if (allowNoSubscriptionsLogin) {
|
||||||
let args = [
|
await executeAzCliCommand(`login --allow-no-subscriptions --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
|
||||||
"--allow-no-subscriptions",
|
|
||||||
"--service-principal",
|
|
||||||
"-u", servicePrincipalId,
|
|
||||||
"-p", servicePrincipalKey,
|
|
||||||
"--tenant", tenantId
|
|
||||||
];
|
|
||||||
await executeAzCliCommand(`login`, true, {}, args);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let args = [
|
await executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
|
||||||
"--service-principal",
|
await executeAzCliCommand(`account set --subscription "${subscriptionId}"`, true);
|
||||||
"-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) {
|
||||||
@@ -96,10 +70,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