mirror of
https://github.com/azure/login.git
synced 2026-03-15 09:20:56 -04:00
Compare commits
12 Commits
AzureStack
...
releases/a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4610f2b768 | ||
|
|
ab062435f9 | ||
|
|
e22df6b974 | ||
|
|
c23434512d | ||
|
|
78d65b04b4 | ||
|
|
b7f16dbb80 | ||
|
|
d71ab3132d | ||
|
|
dbd3c8ef8d | ||
|
|
61f3da0eb1 | ||
|
|
b5bd602263 | ||
|
|
8476f79486 | ||
|
|
ebd3ce082b |
44
lib/main.js
44
lib/main.js
@@ -1,4 +1,23 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
@@ -8,13 +27,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
|
||||||
if (mod && mod.__esModule) return mod;
|
|
||||||
var result = {};
|
|
||||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
||||||
result["default"] = mod;
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const crypto = __importStar(require("crypto"));
|
const crypto = __importStar(require("crypto"));
|
||||||
@@ -38,6 +50,7 @@ function main() {
|
|||||||
core.exportVariable('AZUREPS_HOST_ENVIRONMENT', azurePSHostEnv);
|
core.exportVariable('AZUREPS_HOST_ENVIRONMENT', azurePSHostEnv);
|
||||||
azPath = yield io.which("az", true);
|
azPath = yield io.which("az", true);
|
||||||
yield executeAzCliCommand("--version");
|
yield executeAzCliCommand("--version");
|
||||||
|
let azureSupportedCloudName = new Set(["azureusgovernment", "azurechinacloud", "azuregermancloud", "azurecloud", "azurestack"]);
|
||||||
let creds = core.getInput('creds', { required: true });
|
let creds = core.getInput('creds', { required: true });
|
||||||
let secrets = new actions_secret_parser_1.SecretParser(creds, actions_secret_parser_1.FormatType.JSON);
|
let secrets = new actions_secret_parser_1.SecretParser(creds, actions_secret_parser_1.FormatType.JSON);
|
||||||
let servicePrincipalId = secrets.getSecret("$.clientId", false);
|
let servicePrincipalId = secrets.getSecret("$.clientId", false);
|
||||||
@@ -45,13 +58,16 @@ function main() {
|
|||||||
let tenantId = secrets.getSecret("$.tenantId", false);
|
let tenantId = secrets.getSecret("$.tenantId", false);
|
||||||
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");
|
let environment = core.getInput("environment").toLowerCase();
|
||||||
const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true";
|
const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true";
|
||||||
if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !subscriptionId) {
|
if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !subscriptionId) {
|
||||||
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret, tenantId and subscriptionId are supplied.");
|
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret, tenantId and subscriptionId are supplied.");
|
||||||
}
|
}
|
||||||
|
if (!azureSupportedCloudName.has(environment)) {
|
||||||
|
throw new Error("Unsupported value for environment is passed.The list of supported values for environment are ‘azureusgovernment', ‘azurechinacloud’, ‘azuregermancloud’, ‘azurecloud’ or ’azurestack’");
|
||||||
|
}
|
||||||
// Attempting Az cli login
|
// Attempting Az cli login
|
||||||
if (environment.toLowerCase() == "azurestack") {
|
if (environment == "azurestack") {
|
||||||
if (!resourceManagerEndpointUrl) {
|
if (!resourceManagerEndpointUrl) {
|
||||||
throw new Error("resourceManagerEndpointUrl is a required parameter when environment is defined.");
|
throw new Error("resourceManagerEndpointUrl is a required parameter when environment is defined.");
|
||||||
}
|
}
|
||||||
@@ -77,11 +93,10 @@ function main() {
|
|||||||
catch (error) {
|
catch (error) {
|
||||||
core.error(`Error while trying to register cloud "${environment}": "${error}"`);
|
core.error(`Error while trying to register cloud "${environment}": "${error}"`);
|
||||||
}
|
}
|
||||||
yield executeAzCliCommand(`cloud set -n "${environment}"`, false);
|
|
||||||
console.log(`Done registering cloud: "${environment}"`);
|
console.log(`Done registering cloud: "${environment}"`);
|
||||||
}
|
}
|
||||||
yield executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
|
yield executeAzCliCommand(`cloud set -n "${environment}"`, false);
|
||||||
yield executeAzCliCommand(`account set --subscription "${subscriptionId}"`, true);
|
console.log(`Done setting cloud: "${environment}"`);
|
||||||
isAzCLISuccess = true;
|
isAzCLISuccess = true;
|
||||||
if (enableAzPSSession) {
|
if (enableAzPSSession) {
|
||||||
// Attempting Az PS login
|
// Attempting Az PS login
|
||||||
@@ -90,6 +105,11 @@ function main() {
|
|||||||
yield spnlogin.initialize();
|
yield spnlogin.initialize();
|
||||||
yield spnlogin.login();
|
yield spnlogin.login();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// login using az cli
|
||||||
|
yield executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
|
||||||
|
yield executeAzCliCommand(`account set --subscription "${subscriptionId}"`, true);
|
||||||
|
}
|
||||||
console.log("Login successful.");
|
console.log("Login successful.");
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|||||||
44
src/main.ts
44
src/main.ts
@@ -2,7 +2,6 @@ import * as core from '@actions/core';
|
|||||||
import * as crypto from "crypto";
|
import * as crypto from "crypto";
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
|
|
||||||
import { FormatType, SecretParser } from 'actions-secret-parser';
|
import { FormatType, SecretParser } from 'actions-secret-parser';
|
||||||
import { ServicePrincipalLogin } from './PowerShell/ServicePrincipalLogin';
|
import { ServicePrincipalLogin } from './PowerShell/ServicePrincipalLogin';
|
||||||
|
|
||||||
@@ -24,6 +23,7 @@ async function main() {
|
|||||||
azPath = await io.which("az", true);
|
azPath = await io.which("az", true);
|
||||||
await executeAzCliCommand("--version");
|
await executeAzCliCommand("--version");
|
||||||
|
|
||||||
|
let azureSupportedCloudName = new Set(["azureusgovernment", "azurechinacloud", "azuregermancloud","azurecloud","azurestack"]);
|
||||||
let creds = core.getInput('creds', { required: true });
|
let creds = core.getInput('creds', { required: true });
|
||||||
let secrets = new SecretParser(creds, FormatType.JSON);
|
let secrets = new SecretParser(creds, FormatType.JSON);
|
||||||
let servicePrincipalId = secrets.getSecret("$.clientId", false);
|
let servicePrincipalId = secrets.getSecret("$.clientId", false);
|
||||||
@@ -31,23 +31,32 @@ async function main() {
|
|||||||
let tenantId = secrets.getSecret("$.tenantId", false);
|
let tenantId = secrets.getSecret("$.tenantId", false);
|
||||||
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");
|
let environment = core.getInput("environment").toLowerCase();
|
||||||
const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true";
|
const enableAzPSSession = core.getInput('enable-AzPSSession').toLowerCase() === "true";
|
||||||
|
|
||||||
if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !subscriptionId) {
|
if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !subscriptionId) {
|
||||||
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret, tenantId and subscriptionId are supplied.");
|
throw new Error("Not all values are present in the creds object. Ensure clientId, clientSecret, tenantId and subscriptionId are supplied.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!azureSupportedCloudName.has(environment)){
|
||||||
|
throw new Error("Unsupported value for environment is passed.The list of supported values for environment are ‘azureusgovernment', ‘azurechinacloud’, ‘azuregermancloud’, ‘azurecloud’ or ’azurestack’");
|
||||||
|
}
|
||||||
|
|
||||||
// Attempting Az cli login
|
// Attempting Az cli login
|
||||||
if (environment.toLowerCase() == "azurestack") {
|
if (environment == "azurestack") {
|
||||||
if (!resourceManagerEndpointUrl) {
|
if (!resourceManagerEndpointUrl) {
|
||||||
throw new Error("resourceManagerEndpointUrl is a required parameter when environment is defined.");
|
throw new Error("resourceManagerEndpointUrl is a required parameter when environment is defined.");
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Unregistering cloud: "${environment}" first if it exists`);
|
console.log(`Unregistering cloud: "${environment}" first if it exists`);
|
||||||
try {
|
try {
|
||||||
await executeAzCliCommand(`cloud set -n AzureCloud`, true);
|
await executeAzCliCommand(`cloud set -n AzureCloud`, true);
|
||||||
await executeAzCliCommand(`cloud unregister -n "${environment}"`, false);
|
await executeAzCliCommand(`cloud unregister -n "${environment}"`, false);
|
||||||
} catch (error) {
|
}
|
||||||
|
catch (error) {
|
||||||
console.log(`Ignore cloud not registered error: "${error}"`);
|
console.log(`Ignore cloud not registered error: "${error}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Registering cloud: "${environment}" with ARM endpoint: "${resourceManagerEndpointUrl}"`);
|
console.log(`Registering cloud: "${environment}" with ARM endpoint: "${resourceManagerEndpointUrl}"`);
|
||||||
try {
|
try {
|
||||||
let baseUri = resourceManagerEndpointUrl;
|
let baseUri = resourceManagerEndpointUrl;
|
||||||
@@ -58,14 +67,17 @@ async function main() {
|
|||||||
let suffixStorage = baseUri.substring(baseUri.indexOf('.')+1); // storage suffix starts without .
|
let suffixStorage = baseUri.substring(baseUri.indexOf('.')+1); // storage suffix starts without .
|
||||||
let profileVersion = "2019-03-01-hybrid";
|
let profileVersion = "2019-03-01-hybrid";
|
||||||
await executeAzCliCommand(`cloud register -n "${environment}" --endpoint-resource-manager "${resourceManagerEndpointUrl}" --suffix-keyvault-dns "${suffixKeyvault}" --suffix-storage-endpoint "${suffixStorage}" --profile "${profileVersion}"`, false);
|
await executeAzCliCommand(`cloud register -n "${environment}" --endpoint-resource-manager "${resourceManagerEndpointUrl}" --suffix-keyvault-dns "${suffixKeyvault}" --suffix-storage-endpoint "${suffixStorage}" --profile "${profileVersion}"`, false);
|
||||||
} catch (error) {
|
}
|
||||||
|
catch (error) {
|
||||||
core.error(`Error while trying to register cloud "${environment}": "${error}"`);
|
core.error(`Error while trying to register cloud "${environment}": "${error}"`);
|
||||||
}
|
}
|
||||||
await executeAzCliCommand(`cloud set -n "${environment}"`, false);
|
|
||||||
console.log(`Done registering cloud: "${environment}"`);
|
console.log(`Done registering cloud: "${environment}"`)
|
||||||
}
|
}
|
||||||
await executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
|
|
||||||
await executeAzCliCommand(`account set --subscription "${subscriptionId}"`, true);
|
await executeAzCliCommand(`cloud set -n "${environment}"`, false);
|
||||||
|
console.log(`Done setting cloud: "${environment}"`);
|
||||||
|
|
||||||
isAzCLISuccess = true;
|
isAzCLISuccess = true;
|
||||||
if (enableAzPSSession) {
|
if (enableAzPSSession) {
|
||||||
// Attempting Az PS login
|
// Attempting Az PS login
|
||||||
@@ -74,15 +86,23 @@ async function main() {
|
|||||||
await spnlogin.initialize();
|
await spnlogin.initialize();
|
||||||
await spnlogin.login();
|
await spnlogin.login();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// login using az cli
|
||||||
|
await executeAzCliCommand(`login --service-principal -u "${servicePrincipalId}" -p "${servicePrincipalKey}" --tenant "${tenantId}"`, true);
|
||||||
|
await executeAzCliCommand(`account set --subscription "${subscriptionId}"`, true);
|
||||||
|
}
|
||||||
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 {
|
||||||
// Reset AZURE_HTTP_USER_AGENT
|
// Reset AZURE_HTTP_USER_AGENT
|
||||||
core.exportVariable('AZURE_HTTP_USER_AGENT', prefix);
|
core.exportVariable('AZURE_HTTP_USER_AGENT', prefix);
|
||||||
core.exportVariable('AZUREPS_HOST_ENVIRONMENT', azPSHostEnv);
|
core.exportVariable('AZUREPS_HOST_ENVIRONMENT', azPSHostEnv);
|
||||||
|
|||||||
Reference in New Issue
Block a user