Skip to content

Commit 6e53357

Browse files
authored
Remove Service Principal support (#112)
1 parent 982251e commit 6e53357

File tree

1 file changed

+2
-36
lines changed

1 file changed

+2
-36
lines changed

src/PowerShell/PowerShellManager.cs

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ internal PowerShellManager(ILogger logger)
5151
internal void AuthenticateToAzure()
5252
{
5353
// Check if Az.Profile is available
54-
Collection<PSModuleInfo> azprofile = _pwsh.AddCommand("Get-Module")
54+
Collection<PSModuleInfo> azProfile = _pwsh.AddCommand("Get-Module")
5555
.AddParameter("ListAvailable")
5656
.AddParameter("Name", "Az.Profile")
5757
.InvokeAndClearCommands<PSModuleInfo>();
5858

59-
if (azprofile.Count == 0)
59+
if (azProfile.Count == 0)
6060
{
6161
_logger.Log(LogLevel.Trace, "Required module to automatically authenticate with Azure `Az.Profile` was not found in the PSModulePath.");
6262
return;
@@ -111,40 +111,6 @@ internal void AuthenticateToAzure()
111111
{
112112
_logger.Log(LogLevel.Trace, "Skip authentication to Azure via MSI. Environment variables for authenticating to Azure are not present.");
113113
}
114-
115-
// Try to authenticate to Azure using Service Principal
116-
string applicationId = Environment.GetEnvironmentVariable("SERVICE_PRINCIPAL_APP_ID");
117-
string applicationSecret = Environment.GetEnvironmentVariable("SERVICE_PRINCIPAL_APP_PASSWORD");
118-
string tenantId = Environment.GetEnvironmentVariable("SERVICE_PRINCIPAL_TENANT_ID");
119-
120-
if (string.IsNullOrEmpty(applicationId) ||
121-
string.IsNullOrEmpty(applicationSecret) ||
122-
string.IsNullOrEmpty(tenantId))
123-
{
124-
_logger.Log(LogLevel.Trace, "Skip authentication to Azure via Service Principal. Environment variables for authenticating to Azure are not present.");
125-
return;
126-
}
127-
128-
// Build SecureString
129-
var secureString = new SecureString();
130-
foreach (char item in applicationSecret)
131-
{
132-
secureString.AppendChar(item);
133-
}
134-
135-
using (ExecutionTimer.Start(_logger, "Authentication to Azure"))
136-
{
137-
_pwsh.AddCommand("Az.Profile\\Connect-AzAccount")
138-
.AddParameter("Credential", new PSCredential(applicationId, secureString))
139-
.AddParameter("ServicePrincipal")
140-
.AddParameter("TenantId", tenantId)
141-
.InvokeAndClearCommands();
142-
143-
if(_pwsh.HadErrors)
144-
{
145-
_logger.Log(LogLevel.Warning, "Failed to Authenticate to Azure via Service Principal. Check the logs for the errors generated.");
146-
}
147-
}
148114
}
149115

150116
internal void InitializeRunspace()

0 commit comments

Comments
 (0)