|
1 | | -"use strict"; |
2 | | -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
3 | | - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
4 | | - return new (P || (P = Promise))(function (resolve, reject) { |
5 | | - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
6 | | - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
7 | | - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
8 | | - step((generator = generator.apply(thisArg, _arguments || [])).next()); |
9 | | - }); |
10 | | -}; |
11 | | -var __importStar = (this && this.__importStar) || function (mod) { |
12 | | - if (mod && mod.__esModule) return mod; |
13 | | - var result = {}; |
14 | | - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; |
15 | | - result["default"] = mod; |
16 | | - return result; |
17 | | -}; |
18 | | -Object.defineProperty(exports, "__esModule", { value: true }); |
19 | | -const core = __importStar(require("@actions/core")); |
20 | | -const crypto = __importStar(require("crypto")); |
21 | | -const exec = __importStar(require("@actions/exec")); |
22 | | -const io = __importStar(require("@actions/io")); |
23 | | -const actions_secret_parser_1 = require("actions-secret-parser"); |
24 | | -var azPath; |
25 | | -var prefix = !!process.env.AZURE_HTTP_USER_AGENT ? `${process.env.AZURE_HTTP_USER_AGENT}` : ""; |
26 | | -function main() { |
27 | | - return __awaiter(this, void 0, void 0, function* () { |
28 | | - try { |
29 | | - // Set user agent varable |
30 | | - let usrAgentRepo = crypto.createHash('sha256').update(`${process.env.GITHUB_REPOSITORY}`).digest('hex'); |
31 | | - let actionName = 'AzureLogin'; |
32 | | - let userAgentString = (!!prefix ? `${prefix}+` : '') + `GITHUBACTIONS_${actionName}_${usrAgentRepo}`; |
33 | | - core.exportVariable('AZURE_HTTP_USER_AGENT', userAgentString); |
34 | | - azPath = yield io.which("az", true); |
35 | | - yield executeAzCliCommand("--version"); |
36 | | - let creds = core.getInput('creds', { required: true }); |
37 | | - let secrets = new actions_secret_parser_1.SecretParser(creds, actions_secret_parser_1.FormatType.JSON); |
38 | | - let servicePrincipalId = secrets.getSecret("$.clientId", false); |
39 | | - let servicePrincipalKey = secrets.getSecret("$.clientSecret", true); |
40 | | - let tenantId = secrets.getSecret("$.tenantId", false); |
41 | | - let subscriptionId = secrets.getSecret("$.subscriptionId", false); |
42 | | - if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !subscriptionId) { |
43 | | - throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret, tenantId and subscriptionId are supplied."); |
44 | | - } |
45 | | - yield executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`); |
46 | | - yield executeAzCliCommand(`account set --subscription "${subscriptionId}"`); |
47 | | - console.log("Login successful."); |
48 | | - } |
49 | | - catch (error) { |
50 | | - core.error("Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"); |
51 | | - core.setFailed(error); |
52 | | - } |
53 | | - finally { |
54 | | - // Reset AZURE_HTTP_USER_AGENT |
55 | | - core.exportVariable('AZURE_HTTP_USER_AGENT', prefix); |
56 | | - } |
57 | | - }); |
58 | | -} |
59 | | -function executeAzCliCommand(command) { |
60 | | - return __awaiter(this, void 0, void 0, function* () { |
61 | | - try { |
62 | | - yield exec.exec(`"${azPath}" ${command}`, [], {}); |
63 | | - } |
64 | | - catch (error) { |
65 | | - throw new Error(error); |
66 | | - } |
67 | | - }); |
68 | | -} |
69 | | -main(); |
| 1 | +"use strict"; |
| 2 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 3 | + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
| 4 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 5 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 6 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 7 | + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
| 8 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 9 | + }); |
| 10 | +}; |
| 11 | +var __importStar = (this && this.__importStar) || function (mod) { |
| 12 | + if (mod && mod.__esModule) return mod; |
| 13 | + var result = {}; |
| 14 | + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; |
| 15 | + result["default"] = mod; |
| 16 | + return result; |
| 17 | +}; |
| 18 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 19 | +const core = __importStar(require("@actions/core")); |
| 20 | +const crypto = __importStar(require("crypto")); |
| 21 | +const exec = __importStar(require("@actions/exec")); |
| 22 | +const io = __importStar(require("@actions/io")); |
| 23 | +const actions_secret_parser_1 = require("actions-secret-parser"); |
| 24 | +var azPath; |
| 25 | +var prefix = !!process.env.AZURE_HTTP_USER_AGENT ? `${process.env.AZURE_HTTP_USER_AGENT}` : ""; |
| 26 | +function main() { |
| 27 | + return __awaiter(this, void 0, void 0, function* () { |
| 28 | + try { |
| 29 | + // Set user agent varable |
| 30 | + let usrAgentRepo = crypto.createHash('sha256').update(`${process.env.GITHUB_REPOSITORY}`).digest('hex'); |
| 31 | + let actionName = 'AzureLogin'; |
| 32 | + let userAgentString = (!!prefix ? `${prefix}+` : '') + `GITHUBACTIONS_${actionName}_${usrAgentRepo}`; |
| 33 | + core.exportVariable('AZURE_HTTP_USER_AGENT', userAgentString); |
| 34 | + azPath = yield io.which("az", true); |
| 35 | + yield executeAzCliCommand("--version"); |
| 36 | + let creds = core.getInput('creds', { required: true }); |
| 37 | + let secrets = new actions_secret_parser_1.SecretParser(creds, actions_secret_parser_1.FormatType.JSON); |
| 38 | + let servicePrincipalId = secrets.getSecret("$.clientId", false); |
| 39 | + let servicePrincipalKey = secrets.getSecret("$.clientSecret", true); |
| 40 | + let tenantId = secrets.getSecret("$.tenantId", false); |
| 41 | + let subscriptionId = secrets.getSecret("$.subscriptionId", false); |
| 42 | + if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !subscriptionId) { |
| 43 | + throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret, tenantId and subscriptionId are supplied."); |
| 44 | + } |
| 45 | + yield executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true); |
| 46 | + yield executeAzCliCommand(`account set --subscription "${subscriptionId}"`, true); |
| 47 | + console.log("Login successful."); |
| 48 | + } |
| 49 | + catch (error) { |
| 50 | + core.error("Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"); |
| 51 | + core.setFailed(error); |
| 52 | + } |
| 53 | + finally { |
| 54 | + // Reset AZURE_HTTP_USER_AGENT |
| 55 | + core.exportVariable('AZURE_HTTP_USER_AGENT', prefix); |
| 56 | + } |
| 57 | + }); |
| 58 | +} |
| 59 | +function executeAzCliCommand(command, silent) { |
| 60 | + return __awaiter(this, void 0, void 0, function* () { |
| 61 | + try { |
| 62 | + yield exec.exec(`"${azPath}" ${command}`, [], { silent: !!silent }); |
| 63 | + } |
| 64 | + catch (error) { |
| 65 | + throw new Error(error); |
| 66 | + } |
| 67 | + }); |
| 68 | +} |
| 69 | +main(); |
0 commit comments