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

Update Set-AzStorageSyncServer to reset identity #26724

Closed
12 changes: 12 additions & 0 deletions documentation/azure-powershell-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
| Cognitive Services | `Az.CognitiveServices` | [![CognitiveServices]][CognitiveServicesGallery] | [Changelog][CognitiveServicesChangeLog] |
| Communication | `Az.Communication` | [![Communication]][CommunicationGallery] | [Changelog][CommunicationChangeLog] |
| Compute | `Az.Compute` | [![Compute]][ComputeGallery] | [Changelog][ComputeChangeLog] |
| Compute Fleet | `Az.ComputeFleet` | [![ComputeFleet]][ComputeFleetGallery] | [Changelog][ComputeFleetChangeLog] |
| Compute Schedule | `Az.ComputeSchedule` | [![ComputeSchedule]][ComputeScheduleGallery] | [Changelog][ComputeScheduleChangeLog] |
| ConfidentialLedger | `Az.ConfidentialLedger` | [![ConfidentialLedger]][ConfidentialLedgerGallery] | [Changelog][ConfidentialLedgerChangeLog] |
| Confluent | `Az.Confluent` | [![Confluent]][ConfluentGallery] | [Changelog][ConfluentChangeLog] |
| Connected Kubernetes | `Az.ConnectedKubernetes` | [![ConnectedKubernetes]][ConnectedKubernetesGallery] | [Changelog][ConnectedKubernetesChangeLog] |
Expand Down Expand Up @@ -69,6 +71,7 @@
| Windows Virtual Desktop | `Az.DesktopVirtualization` | [![DesktopVirtualization]][DesktopVirtualizationGallery] | [Changelog][DesktopVirtualizationChangeLog] |
| DevCenter | `Az.DevCenter` | [![DevCenter]][DevCenterGallery] | [Changelog][DevCenterChangeLog] |
| Device Provisioning Services | `Az.DeviceProvisioningServices` | [![DeviceProvisioningServices]][DeviceProvisioningServicesGallery] | [Changelog][DeviceProvisioningServicesChangeLog] |
| Device Registry | `Az.DeviceRegistry` | [![DeviceRegistry]][DeviceUpdateGallery] | [Changelog][DeviceRegistryChangeLog] |
| Device Update | `Az.DeviceUpdate` | [![DeviceUpdate]][DeviceUpdateGallery] | [Changelog][DeviceUpdateChangeLog] |
| DevTest Labs | `Az.DevTestLabs` | [![DevTestLabs]][DevTestLabsGallery] | [Changelog][DevTestLabsChangeLog] |
| Digital Twins | `Az.DigitalTwins` | [![DigitalTwins]][DigitalTwinsGallery] | [Changelog][DigitalTwinsChangeLog] |
Expand Down Expand Up @@ -227,6 +230,8 @@
[CognitiveServices]: https://img.shields.io/powershellgallery/v/Az.CognitiveServices.svg?style=flat-square&label=Az.CognitiveServices
[Communication]: https://img.shields.io/powershellgallery/v/Az.Communication.svg?style=flat-square&label=Az.Communication
[Compute]: https://img.shields.io/powershellgallery/v/Az.Compute.svg?style=flat-square&label=Az.Compute
[ComputeFleet]: https://img.shields.io/powershellgallery/v/Az.ComputeFleet.svg?style=flat-square&label=Az.ComputeFleet
[ComputeSchedule]: https://img.shields.io/powershellgallery/v/Az.ComputeSchedule.svg?style=flat-square&label=Az.ComputeSchedule
[ConfidentialLedger]: https://img.shields.io/powershellgallery/v/Az.ConfidentialLedger.svg?style=flat-square&label=Az.ConfidentialLedger
[Confluent]: https://img.shields.io/powershellgallery/v/Az.Confluent.svg?style=flat-square&label=Az.Confluent
[ConnectedKubernetes]: https://img.shields.io/powershellgallery/v/Az.ConnectedKubernetes.svg?style=flat-square&label=Az.ConnectedKubernetes
Expand Down Expand Up @@ -254,6 +259,7 @@
[DesktopVirtualization]: https://img.shields.io/powershellgallery/v/Az.DesktopVirtualization.svg?style=flat-square&label=Az.DesktopVirtualization
[DevCenter]: https://img.shields.io/powershellgallery/v/Az.DevCenter.svg?style=flat-square&label=Az.DevCenter
[DeviceProvisioningServices]: https://img.shields.io/powershellgallery/v/Az.DeviceProvisioningServices.svg?style=flat-square&label=Az.DeviceProvisioningServices
[DeviceRegistry]: https://img.shields.io/powershellgallery/v/Az.DeviceRegistry.svg?style=flat-square&label=Az.DeviceRegistry
[DeviceUpdate]: https://img.shields.io/powershellgallery/v/Az.DeviceUpdate.svg?style=flat-square&label=Az.DeviceUpdate
[DevTestLabs]: https://img.shields.io/powershellgallery/v/Az.DevTestLabs.svg?style=flat-square&label=Az.DevTestLabs
[DigitalTwins]: https://img.shields.io/powershellgallery/v/Az.DigitalTwins.svg?style=flat-square&label=Az.DigitalTwins
Expand Down Expand Up @@ -408,6 +414,8 @@
[CognitiveServicesGallery]: https://www.powershellgallery.com/packages/Az.CognitiveServices/
[CommunicationGallery]: https://www.powershellgallery.com/packages/Az.Communication/
[ComputeGallery]: https://www.powershellgallery.com/packages/Az.Compute/
[ComputeFleetGallery]: https://www.powershellgallery.com/packages/Az.ComputeFleet/
[ComputeScheduleGallery]: https://www.powershellgallery.com/packages/Az.ComputeSchedule/
[ConfidentialLedgerGallery]: https://www.powershellgallery.com/packages/Az.ConfidentialLedger/
[ConfluentGallery]: https://www.powershellgallery.com/packages/Az.Confluent/
[ConnectedKubernetesGallery]: https://www.powershellgallery.com/packages/Az.ConnectedKubernetes/
Expand Down Expand Up @@ -435,6 +443,7 @@
[DesktopVirtualizationGallery]: https://www.powershellgallery.com/packages/Az.DesktopVirtualization/
[DevCenterGallery]: https://www.powershellgallery.com/packages/Az.DevCenter/
[DeviceProvisioningServicesGallery]: https://www.powershellgallery.com/packages/Az.DeviceProvisioningServices/
[DeviceRegistryGallery]: https://www.powershellgallery.com/packages/Az.DeviceRegistry/
[DeviceUpdateGallery]: https://www.powershellgallery.com/packages/Az.DeviceUpdate/
[DevTestLabsGallery]: https://www.powershellgallery.com/packages/Az.DevTestLabs/
[DigitalTwinsGallery]: https://www.powershellgallery.com/packages/Az.DigitalTwins/
Expand Down Expand Up @@ -587,6 +596,8 @@
[CognitiveServicesChangeLog]: ../src/CognitiveServices/CognitiveServices/ChangeLog.md
[CommunicationChangeLog]: ../src/Communication/Communication/ChangeLog.md
[ComputeChangeLog]: ../src/Compute/Compute/ChangeLog.md
[ComputeFleetChangeLog]: ../src/ComputeFleet/ComputeFleet/ChangeLog.md
[ComputeScheduleChangeLog]: ../src/ComputeSchedule/ComputeSchedule/ChangeLog.md
[ConfidentialLedgerChangeLog]: ../src/ConfidentialLedger/ConfidentialLedger/ChangeLog.md
[ConfluentChangeLog]: ../src/Confluent/Confluent/ChangeLog.md
[ConnectedKubernetesChangeLog]: ../src/ConnectedKubernetes/ConnectedKubernetes/ChangeLog.md
Expand Down Expand Up @@ -614,6 +625,7 @@
[DesktopVirtualizationChangeLog]: ../src/DesktopVirtualization/DesktopVirtualization/ChangeLog.md
[DevCenterChangeLog]: ../src/DevCenter/DevCenter/ChangeLog.md
[DeviceProvisioningServicesChangeLog]: ../src/DeviceProvisioningServices/DeviceProvisioningServices/ChangeLog.md
[DeviceRegistryChangeLog]: ../src/DeviceRegistry/DeviceRegistry/ChangeLog.md
[DeviceUpdateChangeLog]: ../src/DeviceUpdate/DeviceUpdate/ChangeLog.md
[DevTestLabsChangeLog]: ../src/DevTestLabs/DevTestLabs/ChangeLog.md
[DigitalTwinsChangeLog]: ../src/DigitalTwins/DigitalTwins/ChangeLog.md
Expand Down
5 changes: 1 addition & 4 deletions src/Automation/Automation/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
- Additional information about change #1
-->
## Upcoming Release
<<<<<<< HEAD
* Fixed Bug: Start-AzAutomationRunbook throws object reference error when the automation account is not available in the subscription

## Version 1.11.0
=======
* Fixed Bug: Start-AzAutomationRunbook throws object reference error when the automation account is not available in the subscription
>>>>>>> origin/main
* Upgraded nuget package to signed package.

## Version 1.10.0
Expand Down
4 changes: 2 additions & 2 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

-->
## Upcoming Release
* Added new parameter `EncryptionIdentity` to cmdlet `Set-AzVMDiskEncryptionExtension`
* Added new parameter `EncryptionIdentity` to cmdlet `New-AzVMConfig`

## Version 9.0.1
* Upgraded nuget package to signed package.
* Upgraded Azure.Core to 1.44.1.
* Compute gallery related cmdlets will now use 2024-03-03 GalleryRP API calls.
* Added new parameter `EncryptionIdentity` to cmdlet `Set-AzVMDiskEncryptionExtension`
* Added new parameter `EncryptionIdentity` to cmdlet `New-AzVMConfig`

## Version 9.0.0
* Made `-PublicIpSku` parameter Standard by default in `New-AzVM`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.Azure.Commands.Common.MSGraph.Version1_0.Applications.Models;
using Microsoft.Azure.Commands.StorageSync.Common;
using Microsoft.Azure.Commands.StorageSync.Interfaces;
using Microsoft.Azure.Commands.StorageSync.Interop.Enums;
using Microsoft.Azure.Commands.StorageSync.Interop.ManagedIdentity;
using Microsoft.Azure.Commands.StorageSync.Test.Common;
using Microsoft.Azure.Test.HttpRecorder;
Expand Down Expand Up @@ -172,5 +173,10 @@ public string GetTenantId()
/// </summary>
/// <returns>MicrosoftGraphServicePrincipal</returns>
public MicrosoftGraphServicePrincipal GetServicePrincipalOrNull() => new() { Id = "384dab06-7a70-4ecf-a04e-284602199124" }; // Change Object ID if we are using some other tenant

LocalServerType IStorageSyncResourceManager.GetServerTypeFromRegistry()
{
return LocalServerType.HybridServer;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,15 @@ public void TestRemoveRegisteredServerInputObject()
{
TestRunner.RunTestScript("Test-RemoveRegisteredServerInputObject");
}

/// <summary>
/// Defines the test method TestRemoveRegisteredServer.
/// </summary>
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestPatchRegisteredServer()
{
TestRunner.RunTestScript("Test-PatchRegisteredServer");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -733,3 +733,49 @@ function Test-RemoveRegisteredServerResourceId
Clean-ResourceGroup $resourceGroupName
}
}

<#
.SYNOPSIS
Test PatchRegisteredServer
.DESCRIPTION
SmokeTest
#>
function Test-PatchRegisteredServer
{
# Setup
$resourceGroupName = Get-ResourceGroupName
Write-Verbose "RecordMode : $(Get-StorageTestMode)"
try
{
# Test
$storageSyncServiceName = Get-ResourceName("sss")
$resourceGroupLocation = Get-ResourceGroupLocation
$resourceLocation = Get-StorageSyncLocation("Microsoft.StorageSync/storageSyncServices")

Write-Verbose "RGName: $resourceGroupName | Loc: $resourceGroupLocation | Type : ResourceGroup"
New-AzResourceGroup -Name $resourceGroupName -Location $resourceGroupLocation

Write-Verbose "Resource: $storageSyncServiceName | Loc: $resourceLocation | Type : StorageSyncService"
$storageSyncService = New-AzStorageSyncService -ResourceGroupName $resourceGroupName -Location $resourceLocation -StorageSyncServiceName $storageSyncServiceName

Write-Verbose "Resource: <auto-generated> | Loc: $resourceLocation | Type : RegisteredServer"
$job = Register-AzStorageSyncServer -ResourceGroupName $resourceGroupName -StorageSyncServiceName $storageSyncServiceName -AssignIdentity -AsJob
$job | Wait-Job
$expectedRegisteredServer = get-job -Id $job.Id | receive-job -Keep

Write-Verbose "Patch Server: $($expectedRegisteredServer.ServerId)"
Set-AzStorageSyncServer -Force -ResourceGroupName $resourceGroupName -StorageSyncServiceName $storageSyncServiceName -ServerId $expectedRegisteredServer.ServerId -Identity -AsJob | Wait-Job

Write-Verbose "Unregister Server: $($expectedRegisteredServer.ServerId)"
Unregister-AzStorageSyncServer -Force -ResourceGroupName $resourceGroupName -StorageSyncServiceName $storageSyncServiceName -ServerId $expectedRegisteredServer.ServerId -AsJob | Wait-Job

Write-Verbose "Removing StorageSyncService: $storageSyncServiceName"
Remove-AzStorageSyncService -Force -ResourceGroupName $resourceGroupName -Name $storageSyncServiceName -AsJob | Wait-Job
}
finally
{
# Cleanup
Write-Verbose "Removing ResourceGroup : $resourceGroupName"
Clean-ResourceGroup $resourceGroupName
}
}
24 changes: 24 additions & 0 deletions src/StorageSync/StorageSync/Common/StorageSyncResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Commands.StorageSync.Interop.Interfaces;
using Microsoft.Azure.Commands.Common.MSGraph.Version1_0.Applications.Models;
using Microsoft.Azure.Commands.StorageSync.Interfaces;
using Microsoft.Azure.Commands.StorageSync.Interop.Enums;
using Microsoft.Azure.Commands.StorageSync.Interop.ManagedIdentity;
using Microsoft.Win32;
using System;
Expand Down Expand Up @@ -93,6 +94,29 @@ public bool TryGetAfsAgentVersion(out string afsAgentVersion)
return true;
}

/// <summary>
/// Gets the Server Type from the the StorageSync registry path. Default to <see cref="LocalServerType.HybridServer"/>
/// Not using ServerManagedIdentityProvider.GetServerType because it does not necessarily do a direct registry key read.
/// </summary>
/// <returns>The server type</returns>
public LocalServerType GetServerTypeFromRegistry()
{
if (RegistryUtility.TryGetValue(
StorageSyncConstants.ServerTypeRegistryKeyName,
StorageSyncConstants.AfsRegistryKey,
out string serverTypeFromRegistryString,
RegistryValueKind.String,
RegistryValueOptions.None))
{
if (Enum.TryParse(serverTypeFromRegistryString, out LocalServerType serverTypeFromRegistry))
{
return serverTypeFromRegistry;
}
}

return LocalServerType.HybridServer;
}

/// <summary>
/// Updates the server registration data.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Commands.StorageSync.Interop.DataObjects;
using Commands.StorageSync.Interop.Interfaces;
using Microsoft.Azure.Commands.Common.MSGraph.Version1_0.Applications.Models;
using Microsoft.Azure.Commands.StorageSync.Interop.Enums;
using System;

namespace Microsoft.Azure.Commands.StorageSync.Interfaces
Expand Down Expand Up @@ -62,6 +63,12 @@ public interface IStorageSyncResourceManager
/// <returns>System.String.</returns>
bool TryGetAfsAgentVersion(out string afsAgentVersion);

/// <summary>
/// Gets the Server Type from the the StorageSync registry path. Default to <see cref="LocalServerType.HybridServer"/>
/// </summary>
/// <returns>LocalServerType</returns>
LocalServerType GetServerTypeFromRegistry();

/// <summary>
/// Updates the server registration data.
/// </summary>
Expand Down
Loading