Skip to content
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

[Astro] Update astro custom logic for New-AzAstroOrganization and Update-AzAstroOrganization #26641

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Astro/Astro.Autorest/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ tools
custom/*.psm1
custom/autogen-model-cmdlets
test/*-TestResults.xml
license.txt
/*.ps1
/*.psd1
/*.ps1xml
/*.psm1
/*.snk
Expand Down
26 changes: 26 additions & 0 deletions src/Astro/Astro.Autorest/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the ""License"");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an ""AS IS"" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
// is regenerated.

using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: System.Reflection.AssemblyCompanyAttribute("Microsoft")]
[assembly: System.Reflection.AssemblyCopyrightAttribute("Copyright © Microsoft")]
[assembly: System.Reflection.AssemblyProductAttribute("Microsoft Azure PowerShell")]
[assembly: System.Reflection.AssemblyTitleAttribute("Microsoft Azure PowerShell - Astro")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("0.1.0.0")]
[assembly: System.Reflection.AssemblyVersionAttribute("0.1.0.0")]
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]
[assembly: System.CLSCompliantAttribute(false)]
4 changes: 4 additions & 0 deletions src/Astro/Astro.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ subject-prefix: $(service-name)
# Disable transform IdentityType as GET+PUT can not replace patch
# 1. Organizations_CreateOrUpdate can not update resources
# 2. the input schemas of PUT and PATCH are different
flatten-userassignedidentity: false
disable-transform-identity-type: true

directive:
Expand All @@ -74,4 +75,7 @@ directive:
- where:
verb: Update
hide: true
- from: UserAssignedIdentities.dictionary.cs
where: $
transform: $ = $.replace('null != property.Key && null != property.Value', 'null != property.Key');
```
19 changes: 15 additions & 4 deletions src/Astro/Astro.Autorest/custom/New-AzAstroOrganization.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function New-AzAstroOrganization {
# Last name of the user
${UserLastName},

[Parameter(ParameterSetName='CreateExpanded')]
[Parameter(ParameterSetName = 'CreateExpanded')]
[Microsoft.Azure.PowerShell.Cmdlets.Astro.Category('Body')]
[System.Management.Automation.SwitchParameter]
# Decides if enable a system assigned identity for the resource.
Expand Down Expand Up @@ -282,7 +282,7 @@ function New-AzAstroOrganization {
)

process {
if($PSBoundParameters.ContainsKey('EnableSystemAssignedIdentity') -or $PSBoundParameters.ContainsKey('UserAssignedIdentity') ){
if ($PSBoundParameters.ContainsKey('EnableSystemAssignedIdentity') -or $PSBoundParameters.ContainsKey('UserAssignedIdentity')) {
$supportsSystemAssignedIdentity = $PSBoundParameters.ContainsKey('EnableSystemAssignedIdentity')
$supportsUserAssignedIdentity = $PSBoundParameters.ContainsKey("UserAssignedIdentity") -and $UserAssignedIdentity.Length -gt 0

Expand All @@ -299,9 +299,20 @@ function New-AzAstroOrganization {
else {
$PSBoundParameters.Add("IdentityType", "None")
}


# If user input UserAssignedIdentity
if ($PSBoundParameters.ContainsKey('UserAssignedIdentity')) {
$userIdentityObject = [Microsoft.Azure.PowerShell.Cmdlets.Astro.Models.UserAssignedIdentity]::New()
$PSBoundParameters.IdentityUserAssignedIdentity = @{}
foreach ($item in $PSBoundParameters.UserAssignedIdentity) {
$PSBoundParameters.IdentityUserAssignedIdentity.Add($item, $userIdentityObject )
}

$null = $PSBoundParameters.Remove('UserAssignedIdentity')
}

# remove EnableSystemAssignedIdentity
if($PSBoundParameters.ContainsKey('EnableSystemAssignedIdentity')) {
if ($PSBoundParameters.ContainsKey('EnableSystemAssignedIdentity')) {
$null = $PSBoundParameters.Remove("EnableSystemAssignedIdentity")
}
}
Expand Down
Loading