-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Validate ServerId against local machine in Set-AzStorageSyncServer #29448
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
base: main
Are you sure you want to change the base?
Changes from all commits
4563645
2ba21d7
f699752
a5520e7
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 | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |||||||||||||||||||||||||||
| // ---------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| using Commands.StorageSync.Interop.DataObjects; | ||||||||||||||||||||||||||||
| using Commands.StorageSync.Interop.Interfaces; | ||||||||||||||||||||||||||||
| using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; | ||||||||||||||||||||||||||||
| using Microsoft.Azure.Commands.StorageSync.Common; | ||||||||||||||||||||||||||||
| using Microsoft.Azure.Commands.StorageSync.Interop.Enums; | ||||||||||||||||||||||||||||
|
|
@@ -141,6 +142,13 @@ public override void ExecuteCmdlet() | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| bool? identity = default; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| IEcsManagement ecsManagement = StorageSyncClientWrapper.StorageSyncResourceManager.CreateEcsManagement(); | ||||||||||||||||||||||||||||
| int hr = ecsManagement.GetSyncServerId(out string localServerId); | ||||||||||||||||||||||||||||
| if (hr != 0 || !Guid.TryParse(localServerId, out Guid localServerGuid)) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| throw new PSArgumentException("Unable to retrieve the local server ID. Ensure the Azure File Sync agent is installed and running."); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
Comment on lines
+145
to
+151
|
||||||||||||||||||||||||||||
| if (this.IsParameterBound(c => c.InputObject)) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| resourceName = InputObject.ServerId; | ||||||||||||||||||||||||||||
|
|
@@ -149,20 +157,25 @@ public override void ExecuteCmdlet() | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| resourceName = ServerId; | ||||||||||||||||||||||||||||
| resourceGroupName = ResourceGroupName; | ||||||||||||||||||||||||||||
| storageSyncServiceName = StorageSyncServiceName; | ||||||||||||||||||||||||||||
| resourceName = this.IsParameterBound(c => c.ServerId) ? ServerId : localServerId; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (!Guid.TryParse(resourceName, out Guid resourceServerGuid) || resourceServerGuid != localServerGuid) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| throw new PSArgumentException($"The provided ServerId '{resourceName}' does not match the local machine's server ID '{localServerGuid}'. Run this command on the correct server."); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+165
to
168
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
Comment on lines
+165
to
169
|
||||||||||||||||||||||||||||
| if (!Guid.TryParse(resourceName, out Guid resourceServerGuid) || resourceServerGuid != localServerGuid) | |
| { | |
| throw new PSArgumentException($"The provided ServerId '{resourceName}' does not match the local machine's server ID '{localServerGuid}'. Run this command on the correct server."); | |
| } | |
| if (!Guid.TryParse(resourceName, out Guid resourceServerGuid)) | |
| { | |
| throw new PSArgumentException($"The server ID '{resourceName}' is not a valid GUID."); | |
| } | |
| if (resourceServerGuid != localServerGuid) | |
| { | |
| throw new PSArgumentException($"The server ID '{resourceName}' does not match the local machine's server ID '{localServerGuid}'. Run this command on the correct server."); | |
| } |
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.
IEcsManagementimplementsIDisposable(and the real implementation wraps a COM object). Wrap the instance returned fromCreateEcsManagement()in ausing/try/finallyto ensure COM handles are released promptly.