From f095a2213840584dc7c7dfc0cfd335c7dd085b64 Mon Sep 17 00:00:00 2001 From: Atharva Mulmuley Date: Tue, 4 May 2021 12:58:58 +0530 Subject: [PATCH] removed references to az login and copied execute az command func --- lib/arc-login.js | 25 ++++++++++++++++++------- src/arc-login.ts | 29 ++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/lib/arc-login.js b/lib/arc-login.js index 0f622d60..0a347c73 100644 --- a/lib/arc-login.js +++ b/lib/arc-login.js @@ -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); + } + }); +} diff --git a/src/arc-login.ts b/src/arc-login.ts index db08b416..834bfba1 100644 --- a/src/arc-login.ts +++ b/src/arc-login.ts @@ -2,11 +2,13 @@ import * as core from '@actions/core'; import { rejects } from 'assert'; import { WebRequest, WebRequestOptions, WebResponse, sendRequest } from './client'; import * as querystring from 'querystring'; -import * as az_login from './main'; import * as path from 'path'; import {spawn} from 'child_process'; import * as fs from 'fs'; import * as io from '@actions/io'; +import * as exec from '@actions/exec'; +var azPath: string; + const kubeconfig_timeout = 120;//timeout in seconds async function getAzureAccessToken(servicePrincipalId, servicePrincipalKey, tenantId, authorityUrl, managementEndpointUrl: string): Promise { @@ -65,19 +67,18 @@ export async function getArcKubeconfig(): Promise { if(!clusterName){ throw Error("'clusterName' is not passed for arc cluster.") } - //await az_login.main(); - await az_login.executeAzCliCommand(`account show`, false); + azPath = await io.which("az", true); + await executeAzCliCommand(`account show`, false); try{ - await az_login.executeAzCliCommand(`extension remove -n connectedk8s`, false); + await executeAzCliCommand(`extension remove -n connectedk8s`, false); } catch{ //ignore if this causes an error } - await az_login.executeAzCliCommand(`extension add -n connectedk8s`, false); - await az_login.executeAzCliCommand(`extension list`, false); + await executeAzCliCommand(`extension add -n connectedk8s`, false); + await 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 = await io.which("az", true); if (method == 'service-account'){ let saToken = core.getInput('token'); if(!saToken){ @@ -110,3 +111,17 @@ export async function getArcKubeconfig(): Promise { function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } + +async function executeAzCliCommand( + command: string, + silent?: boolean, + execOptions: any = {}, + args: any = []) { + execOptions.silent = !!silent; + try { + await exec.exec(`"${azPath}" ${command}`, args, execOptions); + } + catch (error) { + throw new Error(error); + } +} \ No newline at end of file