Skip to content

Commit cc266e3

Browse files
JoyerJinPan-Qi
authored andcommitted
update managed identity logic
1 parent ad252cc commit cc266e3

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

src/Workloads/SapVirtualInstance.Autorest/custom/New-AzWorkloadsSapVirtualInstance/New-AzWorkloadsSapVirtualInstance_CreateWithJsonString.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ protected override void ProcessRecord()
403403
try
404404
{
405405
await ((Microsoft.Azure.PowerShell.Cmdlets.Workloads.SapVirtualInstance.Runtime.IEventListener)this).Signal(Microsoft.Azure.PowerShell.Cmdlets.Workloads.SapVirtualInstance.Runtime.Events.CmdletBeforeAPICall); if( ((Microsoft.Azure.PowerShell.Cmdlets.Workloads.SapVirtualInstance.Runtime.IEventListener)this).Token.IsCancellationRequested ) { return; }
406-
this.PreProcessManagedIdentityParameters();
407406
await this.Client.SapVirtualInstancesCreateViaJsonString(SubscriptionId, ResourceGroupName, Name, JsonString, onOk, onDefault, this, Pipeline);
408407
await ((Microsoft.Azure.PowerShell.Cmdlets.Workloads.SapVirtualInstance.Runtime.IEventListener)this).Signal(Microsoft.Azure.PowerShell.Cmdlets.Workloads.SapVirtualInstance.Runtime.Events.CmdletAfterAPICall); if( ((Microsoft.Azure.PowerShell.Cmdlets.Workloads.SapVirtualInstance.Runtime.IEventListener)this).Token.IsCancellationRequested ) { return; }
409408
}
@@ -493,30 +492,5 @@ protected override void StopProcessing()
493492
WriteObject((await response));
494493
}
495494
}
496-
497-
private void PreProcessManagedIdentityParameters()
498-
{
499-
if (this.UserAssignedIdentity?.Length > 0)
500-
{
501-
// calculate UserAssignedIdentity
502-
_resourceBody.IdentityUserAssignedIdentity.Clear();
503-
foreach( var id in this.UserAssignedIdentity )
504-
{
505-
_resourceBody.IdentityUserAssignedIdentity.Add(id, new Microsoft.Azure.PowerShell.Cmdlets.Workloads.SapVirtualInstance.Models.UserAssignedIdentity());
506-
}
507-
}
508-
// calculate IdentityType
509-
if (this.UserAssignedIdentity?.Length > 0)
510-
{
511-
if ("SystemAssigned".Equals(_resourceBody.IdentityType, StringComparison.InvariantCultureIgnoreCase))
512-
{
513-
_resourceBody.IdentityType = "SystemAssigned,UserAssigned";
514-
}
515-
else
516-
{
517-
_resourceBody.IdentityType = "UserAssigned";
518-
}
519-
}
520-
}
521495
}
522496
}

src/Workloads/SapVirtualInstance.Autorest/custom/New-AzWorkloadsSapVirtualInstance/New-AzWorkloadsSapVirtualInstance_CreateWithJsonTemplatePath.ps1

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,39 @@ function New-AzWorkloadsSapVirtualInstance_CreateWithJsonTemplatePath {
198198
}
199199

200200
$bodyHashTable.identity = @{}
201-
if($PSBoundParameters.ContainsKey('IdentityType')) {
202-
$bodyHashTable.identity.type = $IdentityType.ToString()
203-
$null = $PSBoundParameters.Remove('IdentityType');
204-
}
205-
206-
if($PSBoundParameters.ContainsKey('UserAssignedIdentity')) {
207-
$bodyHashTable.identity.userAssignedIdentities = $UserAssignedIdentity
208-
$null = $PSBoundParameters.Remove('UserAssignedIdentity');
201+
if ($PSBoundParameters.ContainsKey('EnableSystemAssignedIdentity') -or $PSBoundParameters.ContainsKey('UserAssignedIdentity')){
202+
$supportsSystemAssignedIdentity = $PSBoundParameters.ContainsKey('EnableSystemAssignedIdentity')
203+
$supportsUserAssignedIdentity = $PSBoundParameters.ContainsKey("UserAssignedIdentity") -and $UserAssignedIdentity.Length -gt 0
204+
205+
# calculate IdentityType
206+
if (($supportsSystemAssignedIdentity -and $supportsUserAssignedIdentity)) {
207+
$bodyHashTable.identity.type = "SystemAssigned,UserAssigned"
208+
}
209+
elseif ($supportsUserAssignedIdentity -and (-not $supportsSystemAssignedIdentity)) {
210+
$bodyHashTable.identity.type = "UserAssigned"
211+
}
212+
elseif ((-not $supportsUserAssignedIdentity) -and $supportsSystemAssignedIdentity) {
213+
$bodyHashTable.identity.type = "SystemAssigned"
214+
}
215+
else {
216+
$bodyHashTable.identity.type = "None"
217+
}
218+
219+
# If user input UserAssignedIdentity
220+
if ($PSBoundParameters.ContainsKey('UserAssignedIdentity')) {
221+
$userIdentityObject = [Microsoft.Azure.PowerShell.Cmdlets.Workloads.SapVirtualInstance.Models.UserAssignedIdentity]::New()
222+
$IdentityUserAssignedIdentity = @{}
223+
foreach ($item in $PSBoundParameters.UserAssignedIdentity) {
224+
$IdentityUserAssignedIdentity.Add($item, $userIdentityObject )
225+
}
226+
$bodyHashTable.identity.userAssignedIdentities = $IdentityUserAssignedIdentity
227+
$null = $PSBoundParameters.Remove('UserAssignedIdentity')
228+
}
229+
230+
# remove EnableSystemAssignedIdentity
231+
if ($PSBoundParameters.ContainsKey('EnableSystemAssignedIdentity')) {
232+
$null = $PSBoundParameters.Remove("EnableSystemAssignedIdentity")
233+
}
209234
}
210235

211236
if ($bodyHashTable.identity.Count -eq 0) {

0 commit comments

Comments
 (0)