From 06c725b0d7e137816d8393cede726e89a22bf169 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Sat, 8 Dec 2018 00:13:05 -0800 Subject: [PATCH] Remove Service Principal support --- src/PowerShell/PowerShellManager.cs | 38 ++--------------------------- 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/src/PowerShell/PowerShellManager.cs b/src/PowerShell/PowerShellManager.cs index 44224115..0cc8d4a1 100644 --- a/src/PowerShell/PowerShellManager.cs +++ b/src/PowerShell/PowerShellManager.cs @@ -51,12 +51,12 @@ internal PowerShellManager(ILogger logger) internal void AuthenticateToAzure() { // Check if Az.Profile is available - Collection azprofile = _pwsh.AddCommand("Get-Module") + Collection azProfile = _pwsh.AddCommand("Get-Module") .AddParameter("ListAvailable") .AddParameter("Name", "Az.Profile") .InvokeAndClearCommands(); - if (azprofile.Count == 0) + if (azProfile.Count == 0) { _logger.Log(LogLevel.Trace, "Required module to automatically authenticate with Azure `Az.Profile` was not found in the PSModulePath."); return; @@ -111,40 +111,6 @@ internal void AuthenticateToAzure() { _logger.Log(LogLevel.Trace, "Skip authentication to Azure via MSI. Environment variables for authenticating to Azure are not present."); } - - // Try to authenticate to Azure using Service Principal - string applicationId = Environment.GetEnvironmentVariable("SERVICE_PRINCIPAL_APP_ID"); - string applicationSecret = Environment.GetEnvironmentVariable("SERVICE_PRINCIPAL_APP_PASSWORD"); - string tenantId = Environment.GetEnvironmentVariable("SERVICE_PRINCIPAL_TENANT_ID"); - - if (string.IsNullOrEmpty(applicationId) || - string.IsNullOrEmpty(applicationSecret) || - string.IsNullOrEmpty(tenantId)) - { - _logger.Log(LogLevel.Trace, "Skip authentication to Azure via Service Principal. Environment variables for authenticating to Azure are not present."); - return; - } - - // Build SecureString - var secureString = new SecureString(); - foreach (char item in applicationSecret) - { - secureString.AppendChar(item); - } - - using (ExecutionTimer.Start(_logger, "Authentication to Azure")) - { - _pwsh.AddCommand("Az.Profile\\Connect-AzAccount") - .AddParameter("Credential", new PSCredential(applicationId, secureString)) - .AddParameter("ServicePrincipal") - .AddParameter("TenantId", tenantId) - .InvokeAndClearCommands(); - - if(_pwsh.HadErrors) - { - _logger.Log(LogLevel.Warning, "Failed to Authenticate to Azure via Service Principal. Check the logs for the errors generated."); - } - } } internal void InitializeRunspace()