From b182570c2154fc02aafe3f86d2660d20a2fb0126 Mon Sep 17 00:00:00 2001 From: Atharva Mulmuley Date: Wed, 28 Apr 2021 16:05:09 +0530 Subject: [PATCH] commented unwanted parts --- .github/workflows/main.yml | 4 +- action.yml | 16 +++---- lib/main.js | 84 +++++++++++++++++++---------------- src/main.ts | 91 +++++++++++++++++++------------------- 4 files changed, 101 insertions(+), 94 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dbe329e7..1a6ed74c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,7 +6,7 @@ name: k8s-set-context on: # Triggers the workflow on push or pull request events but only for the master branch push: - branches: [ cluster-connect ] + branches: [ cluster-connect-2 ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -23,7 +23,7 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - - uses: Azure/k8s-set-context@cluster-connect + - uses: atharvamulmuley/k8s-set-context@cluster-connect-2 with: method: spn cluster-type: 'arc' diff --git a/action.yml b/action.yml index f84f7568..6b61d320 100644 --- a/action.yml +++ b/action.yml @@ -46,18 +46,18 @@ inputs: default: '' # inputs for az login - enable-AzPSSession: - description: 'Set this value to true to enable Azure PowerShell Login in addition to Az CLI login' - required: false - default: false + # enable-AzPSSession: + # description: 'Set this value to true to enable Azure PowerShell Login in addition to Az CLI login' + # required: false + # default: false environment: description: 'Name of the environment. Supported values are azurecloud, azurestack, azureusgovernment, azurechinacloud, azuregermancloud. Default being azurecloud' required: false default: AzureCloud - allow-no-subscriptions: - description: 'Set this value to true to enable support for accessing tenants without subscriptions' - required: false - default: false + # allow-no-subscriptions: + # description: 'Set this value to true to enable support for accessing tenants without subscriptions' + # required: false + # default: false branding: color: 'green' # optional, decorates the entry in the GitHub Marketplace runs: diff --git a/lib/main.js b/lib/main.js index 6cc9c48d..3ac278fc 100644 --- a/lib/main.js +++ b/lib/main.js @@ -13,7 +13,6 @@ const core = require("@actions/core"); const exec = require("@actions/exec"); const io = require("@actions/io"); const actions_secret_parser_1 = require("actions-secret-parser"); -const ServicePrincipalLogin_1 = require("./PowerShell/ServicePrincipalLogin"); var azPath; var prefix = !!process.env.AZURE_HTTP_USER_AGENT ? `${process.env.AZURE_HTTP_USER_AGENT}` : ""; var azPSHostEnv = !!process.env.AZUREPS_HOST_ENVIRONMENT ? `${process.env.AZUREPS_HOST_ENVIRONMENT}` : ""; @@ -54,12 +53,12 @@ function main() { let subscriptionId = secrets.getSecret("$.subscriptionId", false); let resourceManagerEndpointUrl = secrets.getSecret("$.resourceManagerEndpointUrl", false); let environment = core.getInput("environment").toLowerCase(); - const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true"; - const allowNoSubscriptionsLogin = core.getInput('allow-no-subscriptions').toLowerCase() === "true"; + // const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true"; + // const allowNoSubscriptionsLogin = core.getInput('allow-no-subscriptions').toLowerCase() === "true"; if (!servicePrincipalId || !servicePrincipalKey || !tenantId) { throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret and tenantId are supplied."); } - if (!subscriptionId && !allowNoSubscriptionsLogin) { + if (!subscriptionId) { throw new Error("Not all values are present in the creds object. Ensure subscriptionId is supplied."); } if (!azureSupportedCloudName.has(environment)) { @@ -97,47 +96,54 @@ function main() { yield executeAzCliCommand(`cloud set -n "${environment}"`, false); console.log(`Done setting cloud: "${environment}"`); // Attempting Az cli login - if (allowNoSubscriptionsLogin) { - let args = [ - "--allow-no-subscriptions", - "--service-principal", - "-u", servicePrincipalId, - "-p", servicePrincipalKey, - "--tenant", tenantId - ]; - yield executeAzCliCommand(`login`, true, {}, args); - } - else { - let args = [ - "--service-principal", - "-u", servicePrincipalId, - "-p", servicePrincipalKey, - "--tenant", tenantId - ]; - yield executeAzCliCommand(`login`, true, {}, args); - args = [ - "--subscription", - subscriptionId - ]; - yield executeAzCliCommand(`account set`, true, {}, args); - } + // if (allowNoSubscriptionsLogin) { + // let args = [ + // "--allow-no-subscriptions", + // "--service-principal", + // "-u", servicePrincipalId, + // "-p", servicePrincipalKey, + // "--tenant", tenantId + // ]; + // await executeAzCliCommand(`login`, true, {}, args); + // } + // else { + // } + let args = [ + "--service-principal", + "-u", servicePrincipalId, + "-p", servicePrincipalKey, + "--tenant", tenantId + ]; + yield executeAzCliCommand(`login`, true, {}, args); + args = [ + "--subscription", + subscriptionId + ]; + yield executeAzCliCommand(`account set`, true, {}, args); isAzCLISuccess = true; - if (enableAzPSSession) { - // Attempting Az PS login - console.log(`Running Azure PS Login`); - const spnlogin = new ServicePrincipalLogin_1.ServicePrincipalLogin(servicePrincipalId, servicePrincipalKey, tenantId, subscriptionId, allowNoSubscriptionsLogin, environment, resourceManagerEndpointUrl); - yield spnlogin.initialize(); - yield spnlogin.login(); - } + // if (enableAzPSSession) { + // // Attempting Az PS login + // console.log(`Running Azure PS Login`); + // const spnlogin: ServicePrincipalLogin = new ServicePrincipalLogin( + // servicePrincipalId, + // servicePrincipalKey, + // tenantId, + // subscriptionId, + // allowNoSubscriptionsLogin, + // environment, + // resourceManagerEndpointUrl); + // await spnlogin.initialize(); + // await spnlogin.login(); + // } console.log("Login successful."); } catch (error) { if (!isAzCLISuccess) { core.error("Az CLI Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"); } - else { - core.error(`Azure PowerShell Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"`); - } + // else { + // core.error(`Azure PowerShell Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"`); + // } core.setFailed(error); } finally { @@ -160,4 +166,4 @@ function executeAzCliCommand(command, silent, execOptions = {}, args = []) { }); } exports.executeAzCliCommand = executeAzCliCommand; -main(); +//main(); diff --git a/src/main.ts b/src/main.ts index f80cd5b1..19a66a49 100644 --- a/src/main.ts +++ b/src/main.ts @@ -47,14 +47,14 @@ export async function main() { let subscriptionId = secrets.getSecret("$.subscriptionId", false); let resourceManagerEndpointUrl = secrets.getSecret("$.resourceManagerEndpointUrl", false); let environment = core.getInput("environment").toLowerCase(); - const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true"; - const allowNoSubscriptionsLogin = core.getInput('allow-no-subscriptions').toLowerCase() === "true"; + // const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true"; + // const allowNoSubscriptionsLogin = core.getInput('allow-no-subscriptions').toLowerCase() === "true"; if (!servicePrincipalId || !servicePrincipalKey || !tenantId) { throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret and tenantId are supplied."); } - if (!subscriptionId && !allowNoSubscriptionsLogin) { + if (!subscriptionId) { throw new Error("Not all values are present in the creds object. Ensure subscriptionId is supplied."); } @@ -99,46 +99,47 @@ export async function main() { console.log(`Done setting cloud: "${environment}"`); // Attempting Az cli login - if (allowNoSubscriptionsLogin) { - let args = [ - "--allow-no-subscriptions", - "--service-principal", - "-u", servicePrincipalId, - "-p", servicePrincipalKey, - "--tenant", tenantId - ]; - await executeAzCliCommand(`login`, true, {}, args); - } - else { - let args = [ - "--service-principal", - "-u", servicePrincipalId, - "-p", servicePrincipalKey, - "--tenant", tenantId - ]; - await executeAzCliCommand(`login`, true, {}, args); - args = [ - "--subscription", - subscriptionId - ]; - await executeAzCliCommand(`account set`, true, {}, args); - } + // if (allowNoSubscriptionsLogin) { + // let args = [ + // "--allow-no-subscriptions", + // "--service-principal", + // "-u", servicePrincipalId, + // "-p", servicePrincipalKey, + // "--tenant", tenantId + // ]; + // await executeAzCliCommand(`login`, true, {}, args); + // } + // else { + + // } + let args = [ + "--service-principal", + "-u", servicePrincipalId, + "-p", servicePrincipalKey, + "--tenant", tenantId + ]; + await executeAzCliCommand(`login`, true, {}, args); + args = [ + "--subscription", + subscriptionId + ]; + await executeAzCliCommand(`account set`, true, {}, args); isAzCLISuccess = true; - if (enableAzPSSession) { - // Attempting Az PS login - console.log(`Running Azure PS Login`); - const spnlogin: ServicePrincipalLogin = new ServicePrincipalLogin( - servicePrincipalId, - servicePrincipalKey, - tenantId, - subscriptionId, - allowNoSubscriptionsLogin, - environment, - resourceManagerEndpointUrl); - await spnlogin.initialize(); - await spnlogin.login(); - } + // if (enableAzPSSession) { + // // Attempting Az PS login + // console.log(`Running Azure PS Login`); + // const spnlogin: ServicePrincipalLogin = new ServicePrincipalLogin( + // servicePrincipalId, + // servicePrincipalKey, + // tenantId, + // subscriptionId, + // allowNoSubscriptionsLogin, + // environment, + // resourceManagerEndpointUrl); + // await spnlogin.initialize(); + // await spnlogin.login(); + // } console.log("Login successful."); } @@ -146,9 +147,9 @@ export async function main() { if (!isAzCLISuccess) { core.error("Az CLI Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"); } - else { - core.error(`Azure PowerShell Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"`); - } + // else { + // core.error(`Azure PowerShell Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"`); + // } core.setFailed(error); } finally { @@ -173,4 +174,4 @@ export async function executeAzCliCommand( } } -main(); \ No newline at end of file +//main(); \ No newline at end of file