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

[Az.DataProtection] Added support for UAMI in Backup Instance #26868

Merged
merged 2 commits into from
Dec 17, 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/DataProtection/DataProtection.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
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 - DataProtection")]
[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)]
2 changes: 1 addition & 1 deletion src/DataProtection/DataProtection.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This file contains the configuration for generating My API from the OpenAPI spec

``` yaml
# it's the same options as command line options, just drop the double-dash!
commit: 72f52bc8847a889488da885f40d6871a89e0470b
commit: 4aad50a36767f7c36673f2c7982bb4055dbf5ed4
require:
- $(this-folder)/../../readme.azure.noprofile.md
input-file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@

[Parameter(Mandatory=$false, HelpMessage='Backup configuration for backup. Use this parameter to configure protection for AzureKubernetesService,AzureBlob.')]
[Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20240401.IBackupDatasourceParameters]
${BackupConfiguration}
${BackupConfiguration},

[Parameter(Mandatory=$false, HelpMessage='Use system assigned identity')]
[System.Nullable[System.Boolean]]
${UseSystemAssignedIdentity},

[Parameter(Mandatory=$false, HelpMessage='User assigned identity ARM Id')]
[Alias('AssignUserIdentity')]
[System.String]
${UserAssignedIdentityArmId}
)

process {
Expand Down Expand Up @@ -96,6 +105,22 @@
$backupInstance.PolicyInfo.PolicyId = $PolicyId
}

$hasUseSystemAssignedIdentity = $PSBoundParameters.Remove("UseSystemAssignedIdentity")
$hasUserAssignedIdentityArmId = $PSBoundParameters.Remove("UserAssignedIdentityArmId")
if ($hasUseSystemAssignedIdentity -or $hasUserAssignedIdentityArmId) {

if ($hasUserAssignedIdentityArmId -and (!$hasUseSystemAssignedIdentity -or $UseSystemAssignedIdentity)) {
throw "UserAssignedIdentityArmId cannot be provided without UseSystemAssignedIdentity and UseSystemAssignedIdentity must be false when UserAssignedIdentityArmId is provided."
}

$backupInstance.IdentityDetail = [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20240401.IdentityDetails]::new()
$backupInstance.IdentityDetail.UseSystemAssignedIdentity = $UseSystemAssignedIdentity

if ($hasUserAssignedIdentityArmId) {
$instance.Property.IdentityDetail.UserAssignedIdentityArmUrl = $UserAssignedIdentityArmId
}
}

# secret store authentication
if($PSBoundParameters.ContainsKey("SecretStoreURI"))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ function Update-AzDataProtectionBackupInstance
[System.String]
${PolicyId},

[Parameter(Mandatory=$false, HelpMessage='Use system assigned identity')]
[System.Nullable[System.Boolean]]
${UseSystemAssignedIdentity},

[Parameter(Mandatory=$false, HelpMessage='User assigned identity ARM Id')]
[Alias('AssignUserIdentity')]
[System.String]
${UserAssignedIdentityArmId},

[Parameter(Mandatory=$false, HelpMessage='List of containers to be backed up inside the VaultStore. Use this parameter for DatasourceType AzureBlob.')]
[System.String[]]
${VaultedBackupContainer},
Expand Down Expand Up @@ -98,6 +107,8 @@ function Update-AzDataProtectionBackupInstance
{
$hasPolicyId = $PSBoundParameters.Remove("PolicyId")
$hasVaultedBackupContainer = $PSBoundParameters.Remove("VaultedBackupContainer")
$hasUseSystemAssignedIdentity = $PSBoundParameters.Remove("UseSystemAssignedIdentity")
$hasUserAssignedIdentityArmId = $PSBoundParameters.Remove("UserAssignedIdentityArmId")

$instance = Az.DataProtection\Get-AzDataProtectionBackupInstance @PSBoundParameters

Expand All @@ -107,6 +118,20 @@ function Update-AzDataProtectionBackupInstance

$DatasourceType = GetClientDatasourceType -ServiceDatasourceType $instance.Property.DataSourceInfo.Type
# $manifest = LoadManifest -DatasourceType $DatasourceType.ToString()

if ($hasUseSystemAssignedIdentity -or $hasUserAssignedIdentityArmId) {

if ($hasUserAssignedIdentityArmId -and (!$hasUseSystemAssignedIdentity -or $UseSystemAssignedIdentity)) {
throw "UserAssignedIdentityArmId cannot be provided without UseSystemAssignedIdentity and UseSystemAssignedIdentity must be false when UserAssignedIdentityArmId is provided."
}

$instance.Property.IdentityDetail = [Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20240401.IdentityDetails]::new()
$instance.Property.IdentityDetail.UseSystemAssignedIdentity = $UseSystemAssignedIdentity

if ($hasUserAssignedIdentityArmId) {
$instance.Property.IdentityDetail.UserAssignedIdentityArmUrl = $UserAssignedIdentityArmId
}
}

if($hasVaultedBackupContainer){

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
${Tag},

[Parameter(Mandatory=$false, HelpMessage='Gets or sets the user assigned identities.')]
[Alias('UserAssignedIdentity')]
[Alias('UserAssignedIdentity', 'AssignUserIdentity')]
[System.Collections.Hashtable]
${IdentityUserAssignedIdentity},

Expand Down
Loading