Skip to content

Commit

Permalink
Customer Managed Key Encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
hiaga committed Dec 21, 2020
1 parent ca615cb commit 1f3b2d8
Show file tree
Hide file tree
Showing 43 changed files with 20,930 additions and 81,001 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ public static CmdletModel.JobBase GetPSJob(JobResource serviceClientJob)
else if (serviceClientJob.Properties.GetType() == typeof(MabJob))
{
response = GetPSMabJob(serviceClientJob);
}
}
else if (serviceClientJob.Properties.GetType() == typeof(VaultJob))
{
response = GetPSAzureVaultJob(serviceClientJob);
}

return response;
}
Expand Down Expand Up @@ -86,80 +90,95 @@ public static void AddServiceClientJobsToPSList(
}
}

#region AzureVm job private helpers
#endregion

#region Vault job private helpers


/// <summary>
/// Helper function to convert ps azure vm backup policy job from service response.
/// </summary>
private static CmdletModel.AzureVmJob GetPSAzureVmJob(JobResource serviceClientJob)
private static CmdletModel.VaultJob GetPSAzureVaultJob(JobResource serviceClientJob)
{
CmdletModel.AzureVmJob response;
CmdletModel.VaultJob response;

AzureIaaSVMJob vmJob = serviceClientJob.Properties as AzureIaaSVMJob;
VaultJob vaultJob = serviceClientJob.Properties as VaultJob;

if (vmJob.ExtendedInfo != null)
if (vaultJob.ExtendedInfo != null)
{
response = new CmdletModel.AzureVmJobDetails();
response = new CmdletModel.VaultJobDetails();
}
else
{
response = new CmdletModel.AzureVmJob();
response = new CmdletModel.VaultJob();
}

response.JobId = GetLastIdFromFullId(serviceClientJob.Id);
response.StartTime = GetJobStartTime(vmJob.StartTime);
response.EndTime = vmJob.EndTime;
response.Duration = GetJobDuration(vmJob.Duration);
response.Status = vmJob.Status;
response.VmVersion = vmJob.VirtualMachineVersion;
response.WorkloadName = vmJob.EntityFriendlyName;
response.ActivityId = vmJob.ActivityId;
response.BackupManagementType =
CmdletModel.ConversionUtils.GetPsBackupManagementType(vmJob.BackupManagementType);
response.Operation = vmJob.Operation;
response.StartTime = GetJobStartTime(vaultJob.StartTime);
response.EndTime = vaultJob.EndTime;
response.Duration = GetJobDuration(vaultJob.Duration);
response.Status = vaultJob.Status;
response.WorkloadName = vaultJob.EntityFriendlyName;
response.ActivityId = vaultJob.ActivityId;

if (vaultJob.BackupManagementType == "")
{
response.BackupManagementType = null;
}
else
{
response.BackupManagementType = CmdletModel.ConversionUtils.GetPsBackupManagementType(vaultJob.BackupManagementType);
}

if (vmJob.ErrorDetails != null)
response.Operation = vaultJob.Operation;

if (vaultJob.ErrorDetails != null)
{
response.ErrorDetails = new List<CmdletModel.AzureJobErrorInfo>();
foreach (var vmError in vmJob.ErrorDetails)
foreach (var vaultError in vaultJob.ErrorDetails)
{
response.ErrorDetails.Add(GetPSAzureVmErrorInfo(vmError));
response.ErrorDetails.Add(GetPSVaultErrorInfo(vaultError));
}
}

// fill extended info if present
if (vmJob.ExtendedInfo != null)
if (vaultJob.ExtendedInfo != null)
{
CmdletModel.AzureVmJobDetails detailedResponse =
response as CmdletModel.AzureVmJobDetails;
CmdletModel.VaultJobDetails detailedResponse =
response as CmdletModel.VaultJobDetails;

detailedResponse.DynamicErrorMessage = vmJob.ExtendedInfo.DynamicErrorMessage;
if (vmJob.ExtendedInfo.PropertyBag != null)
if (vaultJob.ExtendedInfo.PropertyBag != null)
{
detailedResponse.Properties = new Dictionary<string, string>();
foreach (var key in vmJob.ExtendedInfo.PropertyBag.Keys)
{
detailedResponse.Properties.Add(key, vmJob.ExtendedInfo.PropertyBag[key]);
}
}

if (vmJob.ExtendedInfo.TasksList != null)
{
detailedResponse.SubTasks = new List<CmdletModel.AzureVmJobSubTask>();
foreach (var vmJobTask in vmJob.ExtendedInfo.TasksList)
foreach (var key in vaultJob.ExtendedInfo.PropertyBag.Keys)
{
detailedResponse.SubTasks.Add(new CmdletModel.AzureVmJobSubTask()
{
Name = vmJobTask.TaskId,
Status = vmJobTask.Status
});
detailedResponse.Properties.Add(key, vaultJob.ExtendedInfo.PropertyBag[key]);
}
}
}
}

return response;
}


private static CmdletModel.AzureJobErrorInfo GetPSVaultErrorInfo(VaultJobErrorInfo vaultError)
{
CmdletModel.VaultJobErrorInfo psErrorInfo = new CmdletModel.VaultJobErrorInfo();
psErrorInfo.ErrorCode = GetJobErrorCode(vaultError.ErrorCode);
psErrorInfo.ErrorMessage = vaultError.ErrorString;
if (vaultError.Recommendations != null)
{
psErrorInfo.Recommendations = new List<string>();
psErrorInfo.Recommendations.AddRange(vaultError.Recommendations);
}

return psErrorInfo;
}


#endregion

#region MAB job private helpers

/// <summary>
/// Creates the powershell MabJob object from service response.
/// </summary>
Expand All @@ -177,7 +196,7 @@ private static CmdletModel.JobBase GetPSMabJob(JobResource serviceClientJob)
{
response = new CmdletModel.MabJob();
}

// Transfer values from service job object to powershell job object.
response.JobId = GetLastIdFromFullId(serviceClientJob.Id);
response.StartTime = GetJobStartTime(mabJob.StartTime);
Expand Down Expand Up @@ -231,6 +250,7 @@ private static CmdletModel.JobBase GetPSMabJob(JobResource serviceClientJob)
return response;
}


private static CmdletModel.AzureJobErrorInfo GetPSMabErrorInfo(MabErrorInfo mabError)
{
CmdletModel.MabJobErrorInfo psErrorInfo = new CmdletModel.MabJobErrorInfo();
Expand All @@ -244,6 +264,10 @@ private static CmdletModel.AzureJobErrorInfo GetPSMabErrorInfo(MabErrorInfo mabE
return psErrorInfo;
}

#endregion

#region AFS job private helpers

private static CmdletModel.JobBase GetPSAzureFileShareJob(JobResource serviceClientJob)
{
CmdletModel.AzureFileShareJob response;
Expand Down Expand Up @@ -326,6 +350,10 @@ private static CmdletModel.AzureJobErrorInfo GetPSAzureFileShareErrorInfo(AzureS
return psErrorInfo;
}

#endregion

#region Workload job private helpers

private static CmdletModel.JobBase GetPSAzureWorkloadJob(JobResource serviceClientJob)
{
CmdletModel.AzureVmWorkloadJob response;
Expand Down Expand Up @@ -408,26 +436,80 @@ private static CmdletModel.AzureJobErrorInfo GetPSAzureWorkloadErrorInfo(AzureWo
return psErrorInfo;
}

private static int GetJobErrorCode(int? errorCode)
{
return errorCode ?? default(int);
}
#endregion

private static TimeSpan GetJobDuration(TimeSpan? duration)
{
return duration.HasValue ? (TimeSpan)duration : default(TimeSpan);
}
#region AzureVm job private helpers

private static DateTime GetJobStartTime(DateTime? startTime)
/// <summary>
/// Helper function to convert ps azure vm backup policy job from service response.
/// </summary>
private static CmdletModel.AzureVmJob GetPSAzureVmJob(JobResource serviceClientJob)
{
if (startTime.HasValue)
CmdletModel.AzureVmJob response;

AzureIaaSVMJob vmJob = serviceClientJob.Properties as AzureIaaSVMJob;

if (vmJob.ExtendedInfo != null)
{
return (DateTime)startTime;
response = new CmdletModel.AzureVmJobDetails();
}
else
{
throw new ArgumentNullException("Job Start Time is null");
response = new CmdletModel.AzureVmJob();
}

response.JobId = GetLastIdFromFullId(serviceClientJob.Id);
response.StartTime = GetJobStartTime(vmJob.StartTime);
response.EndTime = vmJob.EndTime;
response.Duration = GetJobDuration(vmJob.Duration);
response.Status = vmJob.Status;
response.VmVersion = vmJob.VirtualMachineVersion;
response.WorkloadName = vmJob.EntityFriendlyName;
response.ActivityId = vmJob.ActivityId;
response.BackupManagementType =
CmdletModel.ConversionUtils.GetPsBackupManagementType(vmJob.BackupManagementType);
response.Operation = vmJob.Operation;

if (vmJob.ErrorDetails != null)
{
response.ErrorDetails = new List<CmdletModel.AzureJobErrorInfo>();
foreach (var vmError in vmJob.ErrorDetails)
{
response.ErrorDetails.Add(GetPSAzureVmErrorInfo(vmError));
}
}

// fill extended info if present
if (vmJob.ExtendedInfo != null)
{
CmdletModel.AzureVmJobDetails detailedResponse =
response as CmdletModel.AzureVmJobDetails;

detailedResponse.DynamicErrorMessage = vmJob.ExtendedInfo.DynamicErrorMessage;
if (vmJob.ExtendedInfo.PropertyBag != null)
{
detailedResponse.Properties = new Dictionary<string, string>();
foreach (var key in vmJob.ExtendedInfo.PropertyBag.Keys)
{
detailedResponse.Properties.Add(key, vmJob.ExtendedInfo.PropertyBag[key]);
}
}

if (vmJob.ExtendedInfo.TasksList != null)
{
detailedResponse.SubTasks = new List<CmdletModel.AzureVmJobSubTask>();
foreach (var vmJobTask in vmJob.ExtendedInfo.TasksList)
{
detailedResponse.SubTasks.Add(new CmdletModel.AzureVmJobSubTask()
{
Name = vmJobTask.TaskId,
Status = vmJobTask.Status
});
}
}
}

return response;
}

/// <summary>
Expand All @@ -443,6 +525,32 @@ private static CmdletModel.AzureVmJobErrorInfo GetPSAzureVmErrorInfo(AzureIaaSVM
return psErrorInfo;
}

#endregion

#region generic helpers

private static int GetJobErrorCode(int? errorCode)
{
return errorCode ?? default(int);
}

private static TimeSpan GetJobDuration(TimeSpan? duration)
{
return duration.HasValue ? (TimeSpan)duration : default(TimeSpan);
}

private static DateTime GetJobStartTime(DateTime? startTime)
{
if (startTime.HasValue)
{
return (DateTime)startTime;
}
else
{
throw new ArgumentNullException("Job Start Time is null");
}
}

private static List<string> GetJobErrorRecommendations(IList<string> recommendations)
{
if (recommendations != null)
Expand All @@ -465,7 +573,6 @@ public static string GetLastIdFromFullId(string fullId)
}

#endregion

#endregion

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.2-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.3-preview" />
<PackageReference Include="TimeZoneConverter" Version="3.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// ----------------------------------------------------------------------------------

using System;
using System.Threading;
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using RestAzureNS = Microsoft.Rest.Azure;
Expand Down Expand Up @@ -46,8 +47,7 @@ public static T GetOperationStatus<T>(RestAzureNS.AzureOperationResponse respons
while (opStatusResponse.Body.Status ==
ServiceClientModel.OperationStatusValues.InProgress)
{
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);

Thread.Sleep(5000);
opStatusResponse = getOpStatus(operationId);
}

Expand All @@ -74,8 +74,7 @@ public static T GetOperationStatus<T, S>(RestAzureNS.AzureOperationResponse<S> r
while (opStatusResponse.Body.Status ==
ServiceClientModel.OperationStatusValues.InProgress)
{
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);

Thread.Sleep(5000);
opStatusResponse = getOpStatus(operationId);
}

Expand All @@ -101,8 +100,7 @@ public static RestAzureNS.AzureOperationResponse GetOperationResult(

while (opStatusResponse.Response.StatusCode == SystemNet.HttpStatusCode.Accepted)
{
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);

Thread.Sleep(5000);
opStatusResponse = getOpStatus(operationId);
}

Expand All @@ -128,7 +126,7 @@ public static RestAzureNS.AzureOperationResponse<T> GetOperationStatusDataMove<T

while (opStatusResponse.Body.Status == "InProgress")
{
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
Thread.Sleep(5000);
opStatusResponse = getOpStatus(operationId);
}
opStatusResponse = getOpStatus(operationId);
Expand All @@ -153,7 +151,7 @@ public static RestAzureNS.AzureOperationResponse<T> GetOperationResult<T>(

while (opStatusResponse.Response.StatusCode == SystemNet.HttpStatusCode.Accepted)
{
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);
Thread.Sleep(5000);
opStatusResponse = getOpStatus(operationId);
}
opStatusResponse = getOpStatus(operationId);
Expand Down Expand Up @@ -193,8 +191,7 @@ public static RestAzureNS.AzureOperationResponse<T> GetOperationResult<T>(

while (opStatusResponse.Response.StatusCode == SystemNet.HttpStatusCode.Accepted)
{
TestMockSupport.Delay(_defaultSleepForOperationTracking * 1000);

Thread.Sleep(5000);
opStatusResponse = getOpStatus(operationId);
}

Expand Down
Loading

0 comments on commit 1f3b2d8

Please sign in to comment.