Skip to content

Commit 0815cbb

Browse files
committed
Merge pull request #54 from AsrOneSdk/neha-dev
Storage account related validation changes.
2 parents b603326 + 955f28c commit 0815cbb

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

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

Lines changed: 32 additions & 6 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,9 @@ public bool ValidateStorageAccountAssociation(
142145
}
143146
catch (Exception)
144147
{
145-
return false;
148+
validationSuccessful = false;
149+
locationValid = false;
150+
return;
146151
}
147152

148153
foreach (var storage in azureStorageListResponse.StorageAccounts)
@@ -160,10 +165,31 @@ public bool ValidateStorageAccountAssociation(
160165

161166
if (!associatedAccount)
162167
{
163-
return false;
168+
validationSuccessful = false;
169+
locationValid = false;
170+
return;
171+
}
172+
173+
// Validate that the Geo Location of the storage account is the same as that of the vault.
174+
if (string.IsNullOrEmpty(currentStorageAccount.Properties.Location))
175+
{
176+
validationSuccessful = false;
177+
locationValid = false;
178+
return;
179+
}
180+
181+
if (0 != string.Compare(
182+
currentStorageAccount.Properties.Location,
183+
vaultLocation,
184+
StringComparison.OrdinalIgnoreCase))
185+
{
186+
validationSuccessful = true;
187+
locationValid = true;
188+
return;
164189
}
165190

166-
return true;
191+
validationSuccessful = true;
192+
locationValid = true;
167193
}
168194
}
169195
}

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

Lines changed: 1 addition & 1 deletion
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ ClientRequestId: {3}</value>
250250
Are you sure you want to continue {0}?</value>
251251
</data>
252252
<data name="StorageIsNotInTheSameLocationAsVault" xml:space="preserve">
253-
<value>Storage account given is in {0} whereas the vault is in {1}.
253+
<value>Storage account given is in a different location as compared to the current vault.
254254
Please provide a storage account with the same location as that of the vault.</value>
255255
</data>
256256
<data name="StorageAccountValidationUnsuccessful" xml:space="preserve">

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,27 @@ 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

215219
if (!validationSuccessful)
216220
{
217221
this.WriteWarning(string.Format(Properties.Resources.StorageAccountValidationUnsuccessful));
222+
}
218223

224+
if (validationSuccessful && !locationValid)
225+
{
226+
this.WriteWarning(string.Format(Properties.Resources.StorageIsNotInTheSameLocationAsVault));
227+
}
228+
229+
if (!validationSuccessful || !locationValid)
230+
{
219231
this.ConfirmAction(
220232
this.Force.IsPresent,
221233
string.Format(Properties.Resources.ValidationUnsuccessfulWarning, this.targetName),

0 commit comments

Comments
 (0)