mirror of
https://github.com/azure/login.git
synced 2026-03-15 09:20:56 -04:00
59 lines
2.9 KiB
JavaScript
59 lines
2.9 KiB
JavaScript
"use strict";
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
result["default"] = mod;
|
|
return result;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const core = __importStar(require("@actions/core"));
|
|
const exec = __importStar(require("@actions/exec"));
|
|
const io = __importStar(require("@actions/io"));
|
|
const actions_secret_parser_1 = require("actions-secret-parser");
|
|
var azPath;
|
|
function main() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
try {
|
|
azPath = yield io.which("az", true);
|
|
yield executeAzCliCommand("--version");
|
|
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);
|
|
let servicePrincipalKey = secrets.getSecret("$.clientSecret", true);
|
|
let tenantId = secrets.getSecret("$.tenantId", false);
|
|
let subscriptionId = secrets.getSecret("$.subscriptionId", false);
|
|
if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !subscriptionId) {
|
|
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret, tenantId and subscriptionId are supplied");
|
|
}
|
|
yield executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`);
|
|
yield executeAzCliCommand(`account set --subscription "${subscriptionId}"`);
|
|
console.log("Login successful.");
|
|
}
|
|
catch (error) {
|
|
console.log("Login failed. Please check the credentials.");
|
|
core.setFailed(error);
|
|
}
|
|
});
|
|
}
|
|
function executeAzCliCommand(command) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
try {
|
|
yield exec.exec(`"${azPath}" ${command}`, [], {});
|
|
}
|
|
catch (error) {
|
|
throw new Error(error);
|
|
}
|
|
});
|
|
}
|
|
main();
|