removed references to az login and copied execute az command func

This commit is contained in:
Atharva Mulmuley
2021-05-04 12:58:58 +05:30
parent 542c3fbc66
commit f095a22138
2 changed files with 40 additions and 14 deletions

View File

@@ -12,11 +12,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
const core = require("@actions/core");
const client_1 = require("./client");
const querystring = require("querystring");
const az_login = require("./main");
const path = require("path");
const child_process_1 = require("child_process");
const fs = require("fs");
const io = require("@actions/io");
const exec = require("@actions/exec");
var azPath;
const kubeconfig_timeout = 120; //timeout in seconds
function getAzureAccessToken(servicePrincipalId, servicePrincipalKey, tenantId, authorityUrl, managementEndpointUrl) {
return __awaiter(this, void 0, void 0, function* () {
@@ -70,19 +71,18 @@ function getArcKubeconfig() {
if (!clusterName) {
throw Error("'clusterName' is not passed for arc cluster.");
}
//await az_login.main();
yield az_login.executeAzCliCommand(`account show`, false);
azPath = yield io.which("az", true);
yield executeAzCliCommand(`account show`, false);
try {
yield az_login.executeAzCliCommand(`extension remove -n connectedk8s`, false);
yield executeAzCliCommand(`extension remove -n connectedk8s`, false);
}
catch (_a) {
//ignore if this causes an error
}
yield az_login.executeAzCliCommand(`extension add -n connectedk8s`, false);
yield az_login.executeAzCliCommand(`extension list`, false);
yield executeAzCliCommand(`extension add -n connectedk8s`, false);
yield executeAzCliCommand(`extension list`, false);
const runnerTempDirectory = process.env['RUNNER_TEMP']; // Using process.env until the core libs are updated
const kubeconfigPath = path.join(runnerTempDirectory, `kubeconfig_${Date.now()}`);
let azPath = yield io.which("az", true);
if (method == 'service-account') {
let saToken = core.getInput('token');
if (!saToken) {
@@ -118,3 +118,14 @@ exports.getArcKubeconfig = getArcKubeconfig;
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function executeAzCliCommand(command, silent, execOptions = {}, args = []) {
return __awaiter(this, void 0, void 0, function* () {
execOptions.silent = !!silent;
try {
yield exec.exec(`"${azPath}" ${command}`, args, execOptions);
}
catch (error) {
throw new Error(error);
}
});
}