Skip to content

Commit 07750ad

Browse files
committed
Adding warning for location being invalid.
1 parent d403d80 commit 07750ad

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,14 @@ public void ValidateSubscriptionAccountAssociation(string azureSubscriptionId)
111111
/// <param name="azureSubscription">Subscription ID</param>
112112
/// <param name="azureStorageAccount">Storage Account details</param>
113113
/// <param name="vaultLocation">Current Vault Location</param>
114-
/// <returns>Validation successful</returns>
115-
public bool ValidateStorageAccountAssociation(
114+
/// <param name="validationSuccessful">Out variable to indicate if validation was successful</param>
115+
/// <param name="locationValid">Out variable to indicate if location of storage account is valid</param>
116+
public void ValidateStorageAccountAssociation(
116117
string azureSubscription,
117118
string azureStorageAccount,
118-
string vaultLocation)
119+
string vaultLocation,
120+
out bool validationSuccessful,
121+
out bool locationValid)
119122
{
120123
if (string.IsNullOrEmpty(azureSubscription))
121124
{
@@ -142,7 +145,7 @@ public bool ValidateStorageAccountAssociation(
142145
}
143146
catch (Exception)
144147
{
145-
return false;
148+
validationSuccessful = false;
146149
}
147150

148151
foreach (var storage in azureStorageListResponse.StorageAccounts)
@@ -160,28 +163,25 @@ public bool ValidateStorageAccountAssociation(
160163

161164
if (!associatedAccount)
162165
{
163-
return false;
166+
validationSuccessful = false;
164167
}
165168

166169
// Validate that the Geo Location of the storage account is the same as that of the vault.
167170
if (string.IsNullOrEmpty(currentStorageAccount.Properties.Location))
168171
{
169-
return false;
172+
validationSuccessful = false;
170173
}
171174

172175
if (0 != string.Compare(
173176
currentStorageAccount.Properties.Location,
174177
vaultLocation,
175178
StringComparison.OrdinalIgnoreCase))
176179
{
177-
throw new InvalidOperationException(
178-
string.Format(
179-
Properties.Resources.StorageIsNotInTheSameLocationAsVault,
180-
currentStorageAccount.Properties.Location,
181-
vaultLocation));
180+
locationValid = true;
182181
}
183182

184-
return true;
183+
validationSuccessful = true;
184+
locationValid = true;
185185
}
186186
}
187187
}

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
@@ -253,4 +253,7 @@ Please provide a storage account with the same location as that of the vault.</v
253253
<data name="StorageAccountValidationUnsuccessful" xml:space="preserve">
254254
<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>
255255
</data>
256+
<data name="LocationInvalidWarning" xml:space="preserve">
257+
<value>The Location couldn’t be validated. For failovers to be successful, Storage account location must be the same as location of your Vault.</value>
258+
</data>
256259
</root>

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Service/CreateAzureSiteRecoveryProtectionProfileObject.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,26 @@ private void EnterpriseToAzureProtectionProfileObject()
207207
}
208208

209209
// Verify whether the storage account is associated with the subscription or not.
210-
bool validationSuccessful = RecoveryServicesClient.ValidateStorageAccountAssociation(
210+
bool validationSuccessful;
211+
bool locationValid;
212+
RecoveryServicesClient.ValidateStorageAccountAssociation(
211213
this.RecoveryAzureSubscription,
212214
this.RecoveryAzureStorageAccount,
213-
this.GetCurrentValutLocation());
215+
this.GetCurrentValutLocation(),
216+
out validationSuccessful,
217+
out locationValid);
214218

215-
if (!validationSuccessful)
219+
if (!locationValid)
220+
{
221+
this.WriteWarning(string.Format(Properties.Resources.StorageIsNotInTheSameLocationAsVault));
222+
this.ConfirmAction(
223+
this.Force.IsPresent,
224+
string.Format(Properties.Resources.LocationInvalidWarning, this.targetName),
225+
string.Format(Properties.Resources.NewProtectionProfileObjectWhatIfMessage),
226+
this.targetName,
227+
new Action(this.ProceedToCreateProtectionProfileObject));
228+
}
229+
else if (!validationSuccessful)
216230
{
217231
this.WriteWarning(string.Format(Properties.Resources.StorageAccountValidationUnsuccessful));
218232

0 commit comments

Comments
 (0)