Skip to content

Commit 9afabcd

Browse files
committed
bug1680974
1 parent f23a106 commit 9afabcd

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesClient.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public RecoveryServicesManagementClient GetRecoveryServicesClient
7979
/// </summary>
8080
private RecoveryServicesManagementClient recoveryServicesClient;
8181

82+
private string currentSubscriptionId;
83+
8284
/// <summary>
8385
/// Initializes a new instance of the <see cref="PSRecoveryServicesClient" /> class with
8486
/// required current subscription.
@@ -87,6 +89,7 @@ public RecoveryServicesManagementClient GetRecoveryServicesClient
8789
public PSRecoveryServicesClient(AzureProfile azureProfile, AzureSubscription azureSubscription)
8890
{
8991
this.Profile = azureProfile;
92+
this.currentSubscriptionId = azureSubscription.Id.ToString();
9093
this.recoveryServicesClient =
9194
AzureSession.ClientFactory.CreateClient<RecoveryServicesManagementClient>(azureProfile, azureSubscription, AzureEnvironment.Endpoint.ServiceManagement);
9295
}
@@ -154,6 +157,17 @@ public bool ValidateVaultSettings(
154157
return true;
155158
}
156159

160+
public bool ValidateVaultContext(
161+
string subscriptionId)
162+
{
163+
if (0 == string.CompareOrdinal(this.currentSubscriptionId, subscriptionId))
164+
{
165+
return true;
166+
}
167+
168+
return false;
169+
}
170+
157171
/// <summary>
158172
/// Site Recovery requests that go to on-premise components (like the Provider installed
159173
/// in VMM) require an authentication token that is signed with the vault key to indicate
@@ -213,10 +227,10 @@ public CustomRequestHeaders GetRequestHeaders(bool shouldSignRequest = true)
213227
private SiteRecoveryManagementClient GetSiteRecoveryClient()
214228
{
215229
CloudServiceListResponse services = this.recoveryServicesClient.CloudServices.List();
216-
this.ValidateVaultSettings(
217-
asrVaultCreds.ResourceName,
218-
asrVaultCreds.CloudServiceName,
219-
services);
230+
if (!this.ValidateVaultContext(asrVaultCreds.SubscriptionId))
231+
{
232+
throw new ArgumentException(Properties.Resources.InvalidVaultContext);
233+
}
220234

221235
CloudService selectedCloudService = null;
222236
Vault selectedResource = null;

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,7 @@ Please provide a storage account with the same location as that of the vault.</v
256256
<data name="StorageAccountValidationUnsuccessful" xml:space="preserve">
257257
<value>The Subscription or Storage account couldn’t be validated. For failovers to be successful, the Subscription should belong to your account, the Storage account to the Subscription and Storage account location must be the same as location of your Vault.</value>
258258
</data>
259+
<data name="InvalidVaultContext" xml:space="preserve">
260+
<value>Imported Vault is not associated with the Current Subscription.</value>
261+
</data>
259262
</root>

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/Utilities.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public static void UpdateVaultSettings(ASRVaultCreds asrVaultCreds)
112112
asrVaultCreds.CloudServiceName;
113113
PSRecoveryServicesClient.asrVaultCreds.ChannelIntegrityKey =
114114
asrVaultCreds.ChannelIntegrityKey;
115+
PSRecoveryServicesClient.asrVaultCreds.SubscriptionId =
116+
asrVaultCreds.SubscriptionId;
115117
}
116118
}
117119

0 commit comments

Comments
 (0)