commented unwanted parts
This commit is contained in:
parent
9584d802fc
commit
b182570c21
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@ -6,7 +6,7 @@ name: k8s-set-context
|
|||||||
on:
|
on:
|
||||||
# Triggers the workflow on push or pull request events but only for the master branch
|
# Triggers the workflow on push or pull request events but only for the master branch
|
||||||
push:
|
push:
|
||||||
branches: [ cluster-connect ]
|
branches: [ cluster-connect-2 ]
|
||||||
|
|
||||||
# Allows you to run this workflow manually from the Actions tab
|
# Allows you to run this workflow manually from the Actions tab
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
@ -23,7 +23,7 @@ jobs:
|
|||||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: Azure/k8s-set-context@cluster-connect
|
- uses: atharvamulmuley/k8s-set-context@cluster-connect-2
|
||||||
with:
|
with:
|
||||||
method: spn
|
method: spn
|
||||||
cluster-type: 'arc'
|
cluster-type: 'arc'
|
||||||
|
16
action.yml
16
action.yml
@ -46,18 +46,18 @@ inputs:
|
|||||||
default: ''
|
default: ''
|
||||||
|
|
||||||
# inputs for az login
|
# inputs for az login
|
||||||
enable-AzPSSession:
|
# enable-AzPSSession:
|
||||||
description: 'Set this value to true to enable Azure PowerShell Login in addition to Az CLI login'
|
# description: 'Set this value to true to enable Azure PowerShell Login in addition to Az CLI login'
|
||||||
required: false
|
# required: false
|
||||||
default: false
|
# default: false
|
||||||
environment:
|
environment:
|
||||||
description: 'Name of the environment. Supported values are azurecloud, azurestack, azureusgovernment, azurechinacloud, azuregermancloud. Default being azurecloud'
|
description: 'Name of the environment. Supported values are azurecloud, azurestack, azureusgovernment, azurechinacloud, azuregermancloud. Default being azurecloud'
|
||||||
required: false
|
required: false
|
||||||
default: AzureCloud
|
default: AzureCloud
|
||||||
allow-no-subscriptions:
|
# allow-no-subscriptions:
|
||||||
description: 'Set this value to true to enable support for accessing tenants without subscriptions'
|
# description: 'Set this value to true to enable support for accessing tenants without subscriptions'
|
||||||
required: false
|
# required: false
|
||||||
default: false
|
# default: false
|
||||||
branding:
|
branding:
|
||||||
color: 'green' # optional, decorates the entry in the GitHub Marketplace
|
color: 'green' # optional, decorates the entry in the GitHub Marketplace
|
||||||
runs:
|
runs:
|
||||||
|
84
lib/main.js
84
lib/main.js
@ -13,7 +13,6 @@ const core = require("@actions/core");
|
|||||||
const exec = require("@actions/exec");
|
const exec = require("@actions/exec");
|
||||||
const io = require("@actions/io");
|
const io = require("@actions/io");
|
||||||
const actions_secret_parser_1 = require("actions-secret-parser");
|
const actions_secret_parser_1 = require("actions-secret-parser");
|
||||||
const ServicePrincipalLogin_1 = require("./PowerShell/ServicePrincipalLogin");
|
|
||||||
var azPath;
|
var azPath;
|
||||||
var prefix = !!process.env.AZURE_HTTP_USER_AGENT ? `${process.env.AZURE_HTTP_USER_AGENT}` : "";
|
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}` : "";
|
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 subscriptionId = secrets.getSecret("$.subscriptionId", false);
|
||||||
let resourceManagerEndpointUrl = secrets.getSecret("$.resourceManagerEndpointUrl", false);
|
let resourceManagerEndpointUrl = secrets.getSecret("$.resourceManagerEndpointUrl", false);
|
||||||
let environment = core.getInput("environment").toLowerCase();
|
let environment = core.getInput("environment").toLowerCase();
|
||||||
const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true";
|
// const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true";
|
||||||
const allowNoSubscriptionsLogin = core.getInput('allow-no-subscriptions').toLowerCase() === "true";
|
// const allowNoSubscriptionsLogin = core.getInput('allow-no-subscriptions').toLowerCase() === "true";
|
||||||
if (!servicePrincipalId || !servicePrincipalKey || !tenantId) {
|
if (!servicePrincipalId || !servicePrincipalKey || !tenantId) {
|
||||||
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret and tenantId are supplied.");
|
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.");
|
throw new Error("Not all values are present in the creds object. Ensure subscriptionId is supplied.");
|
||||||
}
|
}
|
||||||
if (!azureSupportedCloudName.has(environment)) {
|
if (!azureSupportedCloudName.has(environment)) {
|
||||||
@ -97,47 +96,54 @@ function main() {
|
|||||||
yield executeAzCliCommand(`cloud set -n "${environment}"`, false);
|
yield executeAzCliCommand(`cloud set -n "${environment}"`, false);
|
||||||
console.log(`Done setting cloud: "${environment}"`);
|
console.log(`Done setting cloud: "${environment}"`);
|
||||||
// Attempting Az cli login
|
// Attempting Az cli login
|
||||||
if (allowNoSubscriptionsLogin) {
|
// if (allowNoSubscriptionsLogin) {
|
||||||
let args = [
|
// let args = [
|
||||||
"--allow-no-subscriptions",
|
// "--allow-no-subscriptions",
|
||||||
"--service-principal",
|
// "--service-principal",
|
||||||
"-u", servicePrincipalId,
|
// "-u", servicePrincipalId,
|
||||||
"-p", servicePrincipalKey,
|
// "-p", servicePrincipalKey,
|
||||||
"--tenant", tenantId
|
// "--tenant", tenantId
|
||||||
];
|
// ];
|
||||||
yield executeAzCliCommand(`login`, true, {}, args);
|
// await executeAzCliCommand(`login`, true, {}, args);
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
let args = [
|
// }
|
||||||
"--service-principal",
|
let args = [
|
||||||
"-u", servicePrincipalId,
|
"--service-principal",
|
||||||
"-p", servicePrincipalKey,
|
"-u", servicePrincipalId,
|
||||||
"--tenant", tenantId
|
"-p", servicePrincipalKey,
|
||||||
];
|
"--tenant", tenantId
|
||||||
yield executeAzCliCommand(`login`, true, {}, args);
|
];
|
||||||
args = [
|
yield executeAzCliCommand(`login`, true, {}, args);
|
||||||
"--subscription",
|
args = [
|
||||||
subscriptionId
|
"--subscription",
|
||||||
];
|
subscriptionId
|
||||||
yield executeAzCliCommand(`account set`, true, {}, args);
|
];
|
||||||
}
|
yield executeAzCliCommand(`account set`, true, {}, args);
|
||||||
isAzCLISuccess = true;
|
isAzCLISuccess = true;
|
||||||
if (enableAzPSSession) {
|
// if (enableAzPSSession) {
|
||||||
// Attempting Az PS login
|
// // Attempting Az PS login
|
||||||
console.log(`Running Azure PS Login`);
|
// console.log(`Running Azure PS Login`);
|
||||||
const spnlogin = new ServicePrincipalLogin_1.ServicePrincipalLogin(servicePrincipalId, servicePrincipalKey, tenantId, subscriptionId, allowNoSubscriptionsLogin, environment, resourceManagerEndpointUrl);
|
// const spnlogin: ServicePrincipalLogin = new ServicePrincipalLogin(
|
||||||
yield spnlogin.initialize();
|
// servicePrincipalId,
|
||||||
yield spnlogin.login();
|
// servicePrincipalKey,
|
||||||
}
|
// tenantId,
|
||||||
|
// subscriptionId,
|
||||||
|
// allowNoSubscriptionsLogin,
|
||||||
|
// environment,
|
||||||
|
// resourceManagerEndpointUrl);
|
||||||
|
// await spnlogin.initialize();
|
||||||
|
// await spnlogin.login();
|
||||||
|
// }
|
||||||
console.log("Login successful.");
|
console.log("Login successful.");
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
if (!isAzCLISuccess) {
|
if (!isAzCLISuccess) {
|
||||||
core.error("Az CLI Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows");
|
core.error("Az CLI Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows");
|
||||||
}
|
}
|
||||||
else {
|
// else {
|
||||||
core.error(`Azure PowerShell Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"`);
|
// 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);
|
core.setFailed(error);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@ -160,4 +166,4 @@ function executeAzCliCommand(command, silent, execOptions = {}, args = []) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.executeAzCliCommand = executeAzCliCommand;
|
exports.executeAzCliCommand = executeAzCliCommand;
|
||||||
main();
|
//main();
|
||||||
|
91
src/main.ts
91
src/main.ts
@ -47,14 +47,14 @@ export async function main() {
|
|||||||
let subscriptionId = secrets.getSecret("$.subscriptionId", false);
|
let subscriptionId = secrets.getSecret("$.subscriptionId", false);
|
||||||
let resourceManagerEndpointUrl = secrets.getSecret("$.resourceManagerEndpointUrl", false);
|
let resourceManagerEndpointUrl = secrets.getSecret("$.resourceManagerEndpointUrl", false);
|
||||||
let environment = core.getInput("environment").toLowerCase();
|
let environment = core.getInput("environment").toLowerCase();
|
||||||
const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true";
|
// const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true";
|
||||||
const allowNoSubscriptionsLogin = core.getInput('allow-no-subscriptions').toLowerCase() === "true";
|
// const allowNoSubscriptionsLogin = core.getInput('allow-no-subscriptions').toLowerCase() === "true";
|
||||||
|
|
||||||
if (!servicePrincipalId || !servicePrincipalKey || !tenantId) {
|
if (!servicePrincipalId || !servicePrincipalKey || !tenantId) {
|
||||||
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret and tenantId are supplied.");
|
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.");
|
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}"`);
|
console.log(`Done setting cloud: "${environment}"`);
|
||||||
|
|
||||||
// Attempting Az cli login
|
// Attempting Az cli login
|
||||||
if (allowNoSubscriptionsLogin) {
|
// if (allowNoSubscriptionsLogin) {
|
||||||
let args = [
|
// let args = [
|
||||||
"--allow-no-subscriptions",
|
// "--allow-no-subscriptions",
|
||||||
"--service-principal",
|
// "--service-principal",
|
||||||
"-u", servicePrincipalId,
|
// "-u", servicePrincipalId,
|
||||||
"-p", servicePrincipalKey,
|
// "-p", servicePrincipalKey,
|
||||||
"--tenant", tenantId
|
// "--tenant", tenantId
|
||||||
];
|
// ];
|
||||||
await executeAzCliCommand(`login`, true, {}, args);
|
// await executeAzCliCommand(`login`, true, {}, args);
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
let args = [
|
|
||||||
"--service-principal",
|
// }
|
||||||
"-u", servicePrincipalId,
|
let args = [
|
||||||
"-p", servicePrincipalKey,
|
"--service-principal",
|
||||||
"--tenant", tenantId
|
"-u", servicePrincipalId,
|
||||||
];
|
"-p", servicePrincipalKey,
|
||||||
await executeAzCliCommand(`login`, true, {}, args);
|
"--tenant", tenantId
|
||||||
args = [
|
];
|
||||||
"--subscription",
|
await executeAzCliCommand(`login`, true, {}, args);
|
||||||
subscriptionId
|
args = [
|
||||||
];
|
"--subscription",
|
||||||
await executeAzCliCommand(`account set`, true, {}, args);
|
subscriptionId
|
||||||
}
|
];
|
||||||
|
await executeAzCliCommand(`account set`, true, {}, args);
|
||||||
|
|
||||||
isAzCLISuccess = true;
|
isAzCLISuccess = true;
|
||||||
if (enableAzPSSession) {
|
// if (enableAzPSSession) {
|
||||||
// Attempting Az PS login
|
// // Attempting Az PS login
|
||||||
console.log(`Running Azure PS Login`);
|
// console.log(`Running Azure PS Login`);
|
||||||
const spnlogin: ServicePrincipalLogin = new ServicePrincipalLogin(
|
// const spnlogin: ServicePrincipalLogin = new ServicePrincipalLogin(
|
||||||
servicePrincipalId,
|
// servicePrincipalId,
|
||||||
servicePrincipalKey,
|
// servicePrincipalKey,
|
||||||
tenantId,
|
// tenantId,
|
||||||
subscriptionId,
|
// subscriptionId,
|
||||||
allowNoSubscriptionsLogin,
|
// allowNoSubscriptionsLogin,
|
||||||
environment,
|
// environment,
|
||||||
resourceManagerEndpointUrl);
|
// resourceManagerEndpointUrl);
|
||||||
await spnlogin.initialize();
|
// await spnlogin.initialize();
|
||||||
await spnlogin.login();
|
// await spnlogin.login();
|
||||||
}
|
// }
|
||||||
|
|
||||||
console.log("Login successful.");
|
console.log("Login successful.");
|
||||||
}
|
}
|
||||||
@ -146,9 +147,9 @@ export async function main() {
|
|||||||
if (!isAzCLISuccess) {
|
if (!isAzCLISuccess) {
|
||||||
core.error("Az CLI Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows");
|
core.error("Az CLI Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows");
|
||||||
}
|
}
|
||||||
else {
|
// else {
|
||||||
core.error(`Azure PowerShell Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"`);
|
// 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);
|
core.setFailed(error);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@ -173,4 +174,4 @@ export async function executeAzCliCommand(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
//main();
|
Loading…
x
Reference in New Issue
Block a user