-
Notifications
You must be signed in to change notification settings - Fork 4k
Add-AzureAnalysisServicesAccount to support login with Service Principal #4389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0b28baf
3c7cb8f
c71d4c4
1670ff4
47535ea
b1345f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,19 +28,54 @@ namespace Microsoft.Azure.Commands.AnalysisServices.Dataplane | |
/// <summary> | ||
/// Cmdlet to log into an Analysis Services environment | ||
/// </summary> | ||
[Cmdlet("Add", "AzureAnalysisServicesAccount", SupportsShouldProcess=true)] | ||
[Cmdlet("Add", "AzureAnalysisServicesAccount", DefaultParameterSetName = "UserParameterSetName", SupportsShouldProcess =true)] | ||
[Alias("Login-AzureAsAccount")] | ||
[OutputType(typeof(AsAzureProfile))] | ||
public class AddAzureASAccountCommand : AzurePSCmdlet, IModuleAssemblyInitializer | ||
{ | ||
[Parameter(Position = 0, Mandatory = false, HelpMessage = "Name of the Azure Analysis Services environment to which to logon to")] | ||
private const string UserParameterSet = "UserParameterSetName"; | ||
private const string ServicePrincipalWithPasswordParameterSet = "ServicePrincipalWithPasswordParameterSetName"; | ||
private const string ServicePrincipalWithCertificateParameterSet = "ServicePrincipalWithCertificateParameterSetName"; | ||
|
||
[Parameter(ParameterSetName = UserParameterSet, | ||
Mandatory = false, HelpMessage = "Name of the Azure Analysis Services environment to which to logon to", Position = 0)] | ||
[Parameter(ParameterSetName = ServicePrincipalWithPasswordParameterSet, | ||
Mandatory = true, HelpMessage = "Name of the Azure Analysis Services environment to which to logon to")] | ||
[Parameter(ParameterSetName = ServicePrincipalWithCertificateParameterSet, | ||
Mandatory = true, HelpMessage = "Name of the Azure Analysis Services environment to which to logon to")] | ||
public string RolloutEnvironment { get; set; } | ||
|
||
[Parameter(Position = 1, Mandatory = false, HelpMessage = "Login credentials to the Azure Analysis Services environment")] | ||
|
||
[Parameter(ParameterSetName = UserParameterSet, | ||
Mandatory = false, HelpMessage = "Login credentials to the Azure Analysis Services environment", Position = 1)] | ||
[Parameter(ParameterSetName = ServicePrincipalWithPasswordParameterSet, | ||
Mandatory = true, HelpMessage = "Login credentials to the Azure Analysis Services environment")] | ||
public PSCredential Credential { get; set; } | ||
|
||
[Parameter(ParameterSetName = ServicePrincipalWithPasswordParameterSet, | ||
Mandatory = true)] | ||
[Parameter(ParameterSetName = ServicePrincipalWithCertificateParameterSet, | ||
Mandatory = true)] | ||
public SwitchParameter ServicePrincipal { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @liangyong79 this parameter doesn't seem to provide any value since the presence of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will make it clear that ServicePrincipal will be used, and also the other Add-AzureRmAccount used the same parameter for SPN: https://docs.microsoft.com/en-us/powershell/module/azurerm.profile/add-azurermaccount?view=azurermps-4.2.0 |
||
|
||
[Parameter(ParameterSetName = ServicePrincipalWithPasswordParameterSet, | ||
Mandatory = true, HelpMessage = "Tenant name or ID")] | ||
[Parameter(ParameterSetName = ServicePrincipalWithCertificateParameterSet, | ||
Mandatory = true, HelpMessage = "Tenant name or ID")] | ||
[ValidateNotNullOrEmpty] | ||
public string TenantId { get; set; } | ||
|
||
[Parameter(ParameterSetName = ServicePrincipalWithCertificateParameterSet, | ||
Mandatory = true, HelpMessage = "The application ID.")] | ||
[ValidateNotNullOrEmpty] | ||
public string ApplicationId { get; set; } | ||
|
||
[Parameter(ParameterSetName = ServicePrincipalWithCertificateParameterSet, | ||
Mandatory = true, HelpMessage = "Certificate Hash (Thumbprint)")] | ||
[ValidateNotNullOrEmpty] | ||
public string CertificateThumbprint { get; set; } | ||
|
||
protected AsAzureEnvironment AsEnvironment; | ||
|
||
protected override IAzureContext DefaultContext | ||
{ | ||
get | ||
|
@@ -83,9 +118,30 @@ protected override void InitializeQosEvent() | |
// nothing to do here. | ||
} | ||
|
||
protected override void SetupDebuggingTraces() | ||
{ | ||
// nothing to do here. | ||
} | ||
|
||
protected override void TearDownDebuggingTraces() | ||
{ | ||
// nothing to do here. | ||
} | ||
|
||
protected override void SetupHttpClientPipeline() | ||
{ | ||
// nothing to do here. | ||
} | ||
|
||
protected override void TearDownHttpClientPipeline() | ||
{ | ||
// nothing to do here. | ||
} | ||
|
||
public override void ExecuteCmdlet() | ||
{ | ||
AsAzureAccount azureAccount = new AsAzureAccount(); | ||
azureAccount.Type = ServicePrincipal ? AsAzureAccount.AccountType.ServicePrincipal : AsAzureAccount.AccountType.User; | ||
|
||
SecureString password = null; | ||
if (Credential != null) | ||
|
@@ -94,6 +150,20 @@ public override void ExecuteCmdlet() | |
password = Credential.Password; | ||
} | ||
|
||
if (ServicePrincipal) | ||
{ | ||
azureAccount.Tenant = TenantId; | ||
|
||
if (!string.IsNullOrEmpty(ApplicationId)) | ||
{ | ||
azureAccount.Id = ApplicationId; | ||
} | ||
if (!string.IsNullOrEmpty(CertificateThumbprint)) | ||
{ | ||
azureAccount.CertificateThumbprint = CertificateThumbprint; | ||
} | ||
} | ||
|
||
if (ShouldProcess(string.Format(Resources.LoginTarget, AsEnvironment.Name), "log in")) | ||
{ | ||
var currentProfile = AsAzureClientSession.Instance.Profile; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liangyong79 now that there are multiple parameter sets used in this cmdlet, there will need to be a
DefaultParameterSetName
defined at the top (inside of theCmdlet
attribute). I would recommend usingUserParameterSet
as the default.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed