Azure PowerShell Login changes (#25)

* Initial commit

* updating package version

* adding secret info link in logs

* adding user-agent

* Update README.md

* Added changes for azure powershell login

Changes in loginAzurePowerShell.ts

using latest version

Added getlatestazmodule version

changes in runner info

code refactor

changes in loginAzurePowerShell

code refactor

Code refactor

Code refactor

added review comments

changes in scriptbuilder

changes in setmodulepath

added paths in tsconfig.json

Revert "added paths in tsconfig.json"

This reverts commit cb2f4176bf.

changes in action.yml

changes in main

added review comments

Added changes for review comments

Modified description in action.yml

Added telemetry info

Code refactor

added review comments

added review comments

removed tslint from package.json

added log in ServicePrincipalLogin

added boolean for error log

Added Unit tests (#15)

* Added unit tests for Azure PowerShell

* Added unit tests

* changes in utils

* removed babel

* changed variable name of enable-PSSession

* refactor

* added ci.yml

* changes in utils test

making login calls silent (#19)

Co-authored-by: Deepak Sattiraju <desattir@microsoft.com>

update utils test (#16)

* update utils test

* update utils test

* update serviceprincipallogin test

Co-authored-by: Microsoft GitHub User <msftgits@microsoft.com>
Co-authored-by: Sumiran Aggarwal <suaggar@microsoft.com>
Co-authored-by: UshaN <ushan@microsoft.com>
This commit is contained in:
aksm-ms
2020-05-06 16:34:34 +05:30
committed by GitHub
parent d1bf5b744b
commit ab6d759ee8
22 changed files with 766 additions and 15 deletions

View File

@@ -0,0 +1,80 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const os = __importStar(require("os"));
const Constants_1 = __importDefault(require("../Constants"));
const ScriptBuilder_1 = __importDefault(require("./ScriptBuilder"));
const PowerShellToolRunner_1 = __importDefault(require("./PowerShellToolRunner"));
class Utils {
/**
* Add the folder path where Az modules are present to PSModulePath based on runner
* @param azPSVersion
* If azPSVersion is empty, folder path in which all Az modules are present are set
* If azPSVersion is not empty, folder path of exact Az module version is set
*/
static setPSModulePath(azPSVersion = "") {
let modulePath = "";
const runner = process.env.RUNNER_OS || os.type();
switch (runner.toLowerCase()) {
case "linux":
modulePath = `/usr/share/${azPSVersion}:`;
break;
case "windows":
case "windows_nt":
modulePath = `C:\\Modules\\${azPSVersion};`;
break;
case "macos":
case "darwin":
throw new Error(`OS not supported`);
default:
throw new Error(`Unknown os: ${runner.toLowerCase()}`);
}
process.env.PSModulePath = `${modulePath}${process.env.PSModulePath}`;
}
static getLatestModule(moduleName) {
return __awaiter(this, void 0, void 0, function* () {
let output = "";
const options = {
listeners: {
stdout: (data) => {
output += data.toString();
}
}
};
yield PowerShellToolRunner_1.default.init();
yield PowerShellToolRunner_1.default.executePowerShellScriptBlock(new ScriptBuilder_1.default()
.getLatestModuleScript(moduleName), options);
const result = JSON.parse(output.trim());
if (!(Constants_1.default.Success in result)) {
throw new Error(result[Constants_1.default.Error]);
}
const azLatestVersion = result[Constants_1.default.AzVersion];
if (!Utils.isValidVersion(azLatestVersion)) {
throw new Error(`Invalid AzPSVersion: ${azLatestVersion}`);
}
return azLatestVersion;
});
}
static isValidVersion(version) {
return !!version.match(Constants_1.default.versionPattern);
}
}
exports.default = Utils;