Skip to content

Commit ccb42bd

Browse files
committed
shifted recovery point functions to helper
1 parent 9798cb4 commit ccb42bd

File tree

4 files changed

+71
-128
lines changed

4 files changed

+71
-128
lines changed

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Helpers/Conversions/RecoveryPointConversions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public static List<RecoveryPointBase> GetPSAzureRecoveryPoints(
5252
result.Add(GetPSAzureVMRecoveryPoint(rp, item));
5353
}
5454

55-
if (rp.Properties.GetType() == typeof(ServiceClientModel.AzureFileShareRecoveryPoint))
55+
else if (rp.Properties.GetType() == typeof(ServiceClientModel.AzureFileShareRecoveryPoint))
5656
{
5757
result.Add(GetPSAzureFileRecoveryPoint(rp, item));
5858
}
5959

60-
if (rp.Properties.GetType() == typeof(ServiceClientModel.GenericRecoveryPoint))
60+
else if (rp.Properties.GetType() == typeof(ServiceClientModel.GenericRecoveryPoint))
6161
{
6262
result.Add(GetPSAzureGenericRecoveryPoint(rp, item));
6363
}
@@ -86,15 +86,15 @@ public static RecoveryPointBase GetPSAzureRecoveryPoints(
8686
result = GetPSAzureVMRecoveryPoint(rpResponse, item);
8787
}
8888

89-
if (rpResponse.Properties.GetType() ==
89+
else if (rpResponse.Properties.GetType() ==
9090
typeof(ServiceClientModel.AzureFileShareRecoveryPoint))
9191
{
9292
result = GetPSAzureFileRecoveryPoint(rpResponse, item);
9393
}
9494

95-
if (rpResponse.Properties.GetType() ==
95+
else if (rpResponse.Properties.GetType() ==
9696
typeof(ServiceClientModel.GenericRecoveryPoint))
97-
{
97+
{
9898
result = GetPSAzureGenericRecoveryPoint(rpResponse, item);
9999
}
100100
return result;

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/AzureWorkloadProviderHelper.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,5 +234,67 @@ public List<ProtectedItemResource> ListProtectedItemsByContainer(
234234

235235
return ConversionHelpers.GetContainerModelList(listResponse);
236236
}
237+
238+
public List<CmdletModel.RecoveryPointBase> ListRecoveryPoints(Dictionary<Enum, object> ProviderData)
239+
{
240+
string vaultName = (string)ProviderData[CmdletModel.VaultParams.VaultName];
241+
string resourceGroupName = (string)ProviderData[CmdletModel.VaultParams.ResourceGroupName];
242+
DateTime startDate = (DateTime)(ProviderData[CmdletModel.RecoveryPointParams.StartDate]);
243+
DateTime endDate = (DateTime)(ProviderData[CmdletModel.RecoveryPointParams.EndDate]);
244+
245+
CmdletModel.ItemBase item = ProviderData[CmdletModel.RecoveryPointParams.Item]
246+
as CmdletModel.ItemBase;
247+
248+
Dictionary<CmdletModel.UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
249+
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
250+
string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
251+
252+
TimeSpan duration = endDate - startDate;
253+
if (duration.TotalDays > 30)
254+
{
255+
throw new Exception(Resources.RestoreDiskTimeRangeError);
256+
}
257+
258+
//we need to fetch the list of RPs
259+
var queryFilterString = QueryBuilder.Instance.GetQueryString(new BMSRPQueryObject()
260+
{
261+
StartDate = startDate,
262+
EndDate = endDate
263+
});
264+
265+
ODataQuery<BMSRPQueryObject> queryFilter = new ODataQuery<BMSRPQueryObject>();
266+
queryFilter.Filter = queryFilterString;
267+
268+
List<RecoveryPointResource> rpListResponse = ServiceClientAdapter.GetRecoveryPoints(
269+
containerUri,
270+
protectedItemName,
271+
queryFilter,
272+
vaultName: vaultName,
273+
resourceGroupName: resourceGroupName);
274+
return RecoveryPointConversions.GetPSAzureRecoveryPoints(rpListResponse, item);
275+
}
276+
277+
public CmdletModel.RecoveryPointBase GetRecoveryPointDetails(Dictionary<Enum, object> ProviderData)
278+
{
279+
string vaultName = (string)ProviderData[CmdletModel.VaultParams.VaultName];
280+
string resourceGroupName = (string)ProviderData[CmdletModel.VaultParams.ResourceGroupName];
281+
CmdletModel.ItemBase item = ProviderData[CmdletModel.RecoveryPointParams.Item]
282+
as CmdletModel.ItemBase;
283+
284+
string recoveryPointId = ProviderData[CmdletModel.RecoveryPointParams.RecoveryPointId].ToString();
285+
286+
Dictionary<CmdletModel.UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
287+
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
288+
string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
289+
290+
var rpResponse = ServiceClientAdapter.GetRecoveryPointDetails(
291+
containerUri,
292+
protectedItemName,
293+
recoveryPointId,
294+
vaultName: vaultName,
295+
resourceGroupName: resourceGroupName);
296+
297+
return RecoveryPointConversions.GetPSAzureRecoveryPoints(rpResponse, item);
298+
}
237299
}
238300
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/AzureFilesPsBackupProvider.cs

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -419,66 +419,12 @@ public ProtectedItemResource GetProtectedItem()
419419

420420
public RecoveryPointBase GetRecoveryPointDetails()
421421
{
422-
string vaultName = (string)ProviderData[VaultParams.VaultName];
423-
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
424-
AzureFileShareItem item = ProviderData[RecoveryPointParams.Item]
425-
as AzureFileShareItem;
426-
427-
string recoveryPointId = ProviderData[RecoveryPointParams.RecoveryPointId].ToString();
428-
429-
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
430-
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
431-
string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
432-
433-
var rpResponse = ServiceClientAdapter.GetRecoveryPointDetails(
434-
containerUri,
435-
protectedItemName,
436-
recoveryPointId,
437-
vaultName: vaultName,
438-
resourceGroupName: resourceGroupName);
439-
440-
var rp = RecoveryPointConversions.GetPSAzureRecoveryPoints(rpResponse, item);
441-
442-
return rp;
422+
return AzureWorkloadProviderHelper.GetRecoveryPointDetails(ProviderData);
443423
}
444424

445425
public List<RecoveryPointBase> ListRecoveryPoints()
446426
{
447-
string vaultName = (string)ProviderData[VaultParams.VaultName];
448-
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
449-
DateTime startDate = (DateTime)(ProviderData[RecoveryPointParams.StartDate]);
450-
DateTime endDate = (DateTime)(ProviderData[RecoveryPointParams.EndDate]);
451-
452-
AzureFileShareItem item = ProviderData[RecoveryPointParams.Item]
453-
as AzureFileShareItem;
454-
455-
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
456-
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
457-
string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
458-
459-
TimeSpan duration = endDate - startDate;
460-
if (duration.TotalDays > 30)
461-
{
462-
throw new Exception(Resources.RestoreDiskTimeRangeError);
463-
}
464-
465-
//we need to fetch the list of RPs
466-
var queryFilterString = QueryBuilder.Instance.GetQueryString(new BMSRPQueryObject()
467-
{
468-
StartDate = startDate,
469-
EndDate = endDate
470-
});
471-
472-
ODataQuery<BMSRPQueryObject> queryFilter = new ODataQuery<BMSRPQueryObject>();
473-
queryFilter.Filter = queryFilterString;
474-
475-
List<RecoveryPointResource> rpListResponse = ServiceClientAdapter.GetRecoveryPoints(
476-
containerUri,
477-
protectedItemName,
478-
queryFilter,
479-
vaultName: vaultName,
480-
resourceGroupName: resourceGroupName);
481-
return RecoveryPointConversions.GetPSAzureRecoveryPoints(rpListResponse, item);
427+
return AzureWorkloadProviderHelper.ListRecoveryPoints(ProviderData);
482428
}
483429

484430
public ProtectionPolicyResource CreatePolicy()

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.Backup.Providers/Providers/IaasVmPsBackupProvider.cs

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -297,38 +297,7 @@ public ProtectedItemResource GetProtectedItem()
297297
/// <returns>Recovery point detail as returned by the service</returns>
298298
public RecoveryPointBase GetRecoveryPointDetails()
299299
{
300-
string vaultName = (string)ProviderData[VaultParams.VaultName];
301-
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
302-
AzureVmItem item = ProviderData[RecoveryPointParams.Item]
303-
as AzureVmItem;
304-
305-
string recoveryPointId = ProviderData[RecoveryPointParams.RecoveryPointId].ToString();
306-
307-
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
308-
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
309-
string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
310-
311-
var rpResponse = ServiceClientAdapter.GetRecoveryPointDetails(
312-
containerUri,
313-
protectedItemName,
314-
recoveryPointId,
315-
vaultName: vaultName,
316-
resourceGroupName: resourceGroupName);
317-
318-
var rp = RecoveryPointConversions.GetPSAzureRecoveryPoints(rpResponse, item) as AzureVmRecoveryPoint;
319-
320-
if (rp.EncryptionEnabled && rp.KeyAndSecretDetails != null)
321-
{
322-
string keyFileDownloadLocation =
323-
(string)ProviderData[RecoveryPointParams.KeyFileDownloadLocation];
324-
string keyFileContent = rp.KeyAndSecretDetails.KeyBackupData;
325-
if (!string.IsNullOrEmpty(keyFileDownloadLocation))
326-
{
327-
string absoluteFilePath = Path.Combine(keyFileDownloadLocation, "key.blob");
328-
File.WriteAllBytes(absoluteFilePath, Convert.FromBase64String(keyFileContent));
329-
}
330-
}
331-
return rp;
300+
return AzureWorkloadProviderHelper.GetRecoveryPointDetails(ProviderData);
332301
}
333302

334303
/// <summary>
@@ -471,41 +440,7 @@ public void RevokeItemLevelRecoveryAccess()
471440
/// <returns>List of recovery point PowerShell model objects</returns>
472441
public List<RecoveryPointBase> ListRecoveryPoints()
473442
{
474-
string vaultName = (string)ProviderData[VaultParams.VaultName];
475-
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
476-
DateTime startDate = (DateTime)(ProviderData[RecoveryPointParams.StartDate]);
477-
DateTime endDate = (DateTime)(ProviderData[RecoveryPointParams.EndDate]);
478-
479-
AzureVmItem item = ProviderData[RecoveryPointParams.Item]
480-
as AzureVmItem;
481-
482-
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
483-
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
484-
string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
485-
486-
TimeSpan duration = endDate - startDate;
487-
if (duration.TotalDays > 30)
488-
{
489-
throw new Exception(Resources.RestoreDiskTimeRangeError);
490-
}
491-
492-
//we need to fetch the list of RPs
493-
var queryFilterString = QueryBuilder.Instance.GetQueryString(new BMSRPQueryObject()
494-
{
495-
StartDate = startDate,
496-
EndDate = endDate
497-
});
498-
499-
ODataQuery<BMSRPQueryObject> queryFilter = new ODataQuery<BMSRPQueryObject>();
500-
queryFilter.Filter = queryFilterString;
501-
502-
List<RecoveryPointResource> rpListResponse = ServiceClientAdapter.GetRecoveryPoints(
503-
containerUri,
504-
protectedItemName,
505-
queryFilter,
506-
vaultName: vaultName,
507-
resourceGroupName: resourceGroupName);
508-
return RecoveryPointConversions.GetPSAzureRecoveryPoints(rpListResponse, item);
443+
return AzureWorkloadProviderHelper.ListRecoveryPoints(ProviderData);
509444
}
510445

511446
/// <summary>

0 commit comments

Comments
 (0)