commented unwanted parts
This commit is contained in:
84
lib/main.js
84
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();
|
||||
|
Reference in New Issue
Block a user