Initial commit

This commit is contained in:
Microsoft GitHub User
2019-09-25 01:50:19 -07:00
committed by Sumiran Aggarwal
commit 571e3ac4e7
11 changed files with 869 additions and 0 deletions

43
src/main.ts Normal file
View File

@@ -0,0 +1,43 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
import { FormatType, SecretParser } from 'actions-secret-parser';
var azPath: string;
async function main() {
try{
azPath = await io.which("az", true);
await executeAzCliCommand("--version");
let creds = core.getInput('creds', { required: true });
let secrets = new SecretParser(creds, 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");
}
await executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`);
await executeAzCliCommand(`account set --subscription "${subscriptionId}"`);
console.log("Login successful.");
} catch (error) {
console.log("Login failed. Please check the credentials.");
core.setFailed(error);
}
}
async function executeAzCliCommand(command: string) {
try {
await exec.exec(`"${azPath}" ${command}`, [], {});
}
catch(error) {
throw new Error(error);
}
}
main();