mirror of
https://github.com/azure/login.git
synced 2026-03-15 09:20:56 -04:00
adding user-agent
This commit is contained in:
15
lib/main.js
15
lib/main.js
@@ -17,13 +17,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
|
const crypto = __importStar(require("crypto"));
|
||||||
const exec = __importStar(require("@actions/exec"));
|
const exec = __importStar(require("@actions/exec"));
|
||||||
const io = __importStar(require("@actions/io"));
|
const io = __importStar(require("@actions/io"));
|
||||||
const actions_secret_parser_1 = require("actions-secret-parser");
|
const actions_secret_parser_1 = require("actions-secret-parser");
|
||||||
var azPath;
|
var azPath;
|
||||||
|
var prefix = !!process.env.AZURE_HTTP_USER_AGENT ? `${process.env.AZURE_HTTP_USER_AGENT}` : "";
|
||||||
function main() {
|
function main() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
|
// Set user agent varable
|
||||||
|
let usrAgentRepo = crypto.createHash('sha256').update(`${process.env.GITHUB_REPOSITORY}`).digest('hex');
|
||||||
|
let actionName = 'AzureLogin';
|
||||||
|
let userAgentString = (!!prefix ? `${prefix}+` : '') + `GITHUBACTIONS_${actionName}_${usrAgentRepo}`;
|
||||||
|
core.exportVariable('AZURE_HTTP_USER_AGENT', userAgentString);
|
||||||
azPath = yield io.which("az", true);
|
azPath = yield io.which("az", true);
|
||||||
yield executeAzCliCommand("--version");
|
yield executeAzCliCommand("--version");
|
||||||
let creds = core.getInput('creds', { required: true });
|
let creds = core.getInput('creds', { required: true });
|
||||||
@@ -33,16 +40,20 @@ function main() {
|
|||||||
let tenantId = secrets.getSecret("$.tenantId", false);
|
let tenantId = secrets.getSecret("$.tenantId", false);
|
||||||
let subscriptionId = secrets.getSecret("$.subscriptionId", false);
|
let subscriptionId = secrets.getSecret("$.subscriptionId", false);
|
||||||
if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !subscriptionId) {
|
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. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows");
|
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(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`);
|
||||||
yield executeAzCliCommand(`account set --subscription "${subscriptionId}"`);
|
yield executeAzCliCommand(`account set --subscription "${subscriptionId}"`);
|
||||||
console.log("Login successful.");
|
console.log("Login successful.");
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.log("Login failed. Please check the credentials.");
|
core.error("Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows");
|
||||||
core.setFailed(error);
|
core.setFailed(error);
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
// Reset AZURE_HTTP_USER_AGENT
|
||||||
|
core.exportVariable('AZURE_HTTP_USER_AGENT', prefix);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function executeAzCliCommand(command) {
|
function executeAzCliCommand(command) {
|
||||||
|
|||||||
15
src/main.ts
15
src/main.ts
@@ -1,13 +1,21 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
import * as crypto from "crypto";
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
|
|
||||||
import { FormatType, SecretParser } from 'actions-secret-parser';
|
import { FormatType, SecretParser } from 'actions-secret-parser';
|
||||||
|
|
||||||
var azPath: string;
|
var azPath: string;
|
||||||
|
var prefix = !!process.env.AZURE_HTTP_USER_AGENT ? `${process.env.AZURE_HTTP_USER_AGENT}` : "";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try{
|
try{
|
||||||
|
// Set user agent varable
|
||||||
|
let usrAgentRepo = crypto.createHash('sha256').update(`${process.env.GITHUB_REPOSITORY}`).digest('hex');
|
||||||
|
let actionName = 'AzureLogin';
|
||||||
|
let userAgentString = (!!prefix ? `${prefix}+` : '') + `GITHUBACTIONS_${actionName}_${usrAgentRepo}`;
|
||||||
|
core.exportVariable('AZURE_HTTP_USER_AGENT', userAgentString);
|
||||||
|
|
||||||
azPath = await io.which("az", true);
|
azPath = await io.which("az", true);
|
||||||
await executeAzCliCommand("--version");
|
await executeAzCliCommand("--version");
|
||||||
|
|
||||||
@@ -18,15 +26,18 @@ async function main() {
|
|||||||
let tenantId = secrets.getSecret("$.tenantId", false);
|
let tenantId = secrets.getSecret("$.tenantId", false);
|
||||||
let subscriptionId = secrets.getSecret("$.subscriptionId", false);
|
let subscriptionId = secrets.getSecret("$.subscriptionId", false);
|
||||||
if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !subscriptionId) {
|
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. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows");
|
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret, tenantId and subscriptionId are supplied.");
|
||||||
}
|
}
|
||||||
|
|
||||||
await executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`);
|
await executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`);
|
||||||
await executeAzCliCommand(`account set --subscription "${subscriptionId}"`);
|
await executeAzCliCommand(`account set --subscription "${subscriptionId}"`);
|
||||||
console.log("Login successful.");
|
console.log("Login successful.");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Login failed. Please check the credentials.");
|
core.error("Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows");
|
||||||
core.setFailed(error);
|
core.setFailed(error);
|
||||||
|
} finally {
|
||||||
|
// Reset AZURE_HTTP_USER_AGENT
|
||||||
|
core.exportVariable('AZURE_HTTP_USER_AGENT', prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user