Skip to content

Commit b00e638

Browse files
committed
merge from dev
2 parents ff1acac + 0d4af69 commit b00e638

19 files changed

+105
-57
lines changed

src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletBase.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public abstract class AzureBackupCmdletBase : AzurePSCmdlet
4141
/// </summary>
4242
private string resourceName { get; set; }
4343

44+
/// <summary>
45+
/// Resource context for the operation
46+
/// </summary>
47+
private string location { get; set; }
48+
4449
/// <summary>
4550
/// Client request id.
4651
/// </summary>
@@ -82,10 +87,11 @@ protected void RefreshClientRequestId()
8287
clientRequestId = Guid.NewGuid().ToString() + "-" + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ssZ") + "-PS";
8388
}
8489

85-
public void InitializeAzureBackupCmdlet(string rgName, string rName)
90+
public void InitializeAzureBackupCmdlet(string rgName, string rName, string locationName)
8691
{
8792
resourceGroupName = rgName;
8893
resourceName = rName;
94+
location = locationName;
8995

9096
RefreshClientRequestId();
9197
WriteDebug(string.Format("Initialized AzureBackup Cmdlet, ClientRequestId: {0}, ResourceGroupName: {1}, ResourceName : {2}", this.clientRequestId, resourceGroupName, resourceName));

src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ internal static class AzureBackupCmdletHelpMessage
2020
public const string PolicyName = "The protection policy name.";
2121
public const string ResourceGroupName = "The ResourceGroup name.";
2222
public const string ResourceName = "The Resource name.";
23+
public const string Location = "Location.";
2324
public const string TargetLocation = "The directory where the credentials file will be saved.";
2425
public const string ContainerResourceName = "The container resource name aka friendly name.";
2526
public const string ContainerId = "The container ID.";
2627
public const string ContainerRegistrationStatus = "The container registration status.";
2728
public const string ContainerType = "The container type.";
2829
public const string ContainerResourceGroupName = "The container resource group name.";
2930
public const string ProtectionStatus = "Protection Status of the azure backup item.";
31+
public const string AzureBackUpItem = "Azure BackUp Item.";
32+
public const string RecoveryPointId = "Recovery Point Id.";
3033
public const string Type = "Type of Azure Backup Item.";
3134
public const string Status = "Status of Azure Backup Item";
3235
public const string AzureBackupContainer = "Azure Backup Container for Azure Backup Item.";

src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupContainerCmdletBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public override void ExecuteCmdlet()
3636
{
3737
base.ExecuteCmdlet();
3838

39-
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", AzureBackupContainer.ResourceGroupName, AzureBackupContainer.ResourceName));
39+
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}, Location: {2}", AzureBackupContainer.ResourceGroupName, AzureBackupContainer.ResourceName, AzureBackupContainer.Location));
4040

41-
InitializeAzureBackupCmdlet(AzureBackupContainer.ResourceGroupName, AzureBackupContainer.ResourceName);
41+
InitializeAzureBackupCmdlet(AzureBackupContainer.ResourceGroupName, AzureBackupContainer.ResourceName, AzureBackupContainer.Location);
4242
}
4343
}
4444
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupDSCmdletBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ public abstract class AzureBackupDSCmdletBase : AzureBackupCmdletBase
3030
{
3131
// ToDO:
3232
// Correct Help message and other attributes related to paameters
33-
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ResourceGroupName, ValueFromPipelineByPropertyName = true)]
33+
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.AzureBackUpItem, ValueFromPipelineByPropertyName = true)]
3434
[ValidateNotNullOrEmpty]
35-
public AzureBackupItem AzureBackupItem { get; set; }
35+
public AzureBackupItem item { get; set; }
3636

3737
public override void ExecuteCmdlet()
3838
{
3939
base.ExecuteCmdlet();
4040

41-
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", AzureBackupItem.ResourceGroupName, AzureBackupItem.ResourceName));
41+
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", item.ResourceGroupName, item.ResourceName));
4242

43-
InitializeAzureBackupCmdlet(AzureBackupItem.ResourceGroupName, AzureBackupItem.ResourceName);
43+
InitializeAzureBackupCmdlet(item.ResourceGroupName, item.ResourceName, item.Location);
4444
}
4545
}
4646
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupItemCmdletBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public abstract class AzureBackupItemCmdletBase : AzureBackupCmdletBase
3232
// Correct Help message and other attributes related to paameters
3333
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ResourceGroupName, ValueFromPipelineByPropertyName = true)]
3434
[ValidateNotNullOrEmpty]
35-
public AzureBackupContainerContextObject AzureBackupItem { get; set; }
35+
public AzureBackupContainerContextObject Item { get; set; }
3636

3737
public override void ExecuteCmdlet()
3838
{
3939
base.ExecuteCmdlet();
40-
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", AzureBackupItem.ResourceGroupName, AzureBackupItem.ResourceName));
41-
InitializeAzureBackupCmdlet(AzureBackupItem.ResourceGroupName, AzureBackupItem.ResourceName);
40+
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", Item.ResourceGroupName, Item.ResourceName));
41+
InitializeAzureBackupCmdlet(Item.ResourceGroupName, Item.ResourceName, Item.Location);
4242
}
4343
}
4444
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupVaultCmdletBase.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ public abstract class AzureBackupVaultCmdletBase : AzureBackupCmdletBase
3636
[ValidateNotNullOrEmpty]
3737
public string ResourceName { get; set; }
3838

39+
[Parameter(Position = 2, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.Location, ValueFromPipelineByPropertyName = true)]
40+
[ValidateNotNullOrEmpty]
41+
public string Location { get; set; }
3942

4043
public override void ExecuteCmdlet()
4144
{
4245
base.ExecuteCmdlet();
4346

4447
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", ResourceGroupName, ResourceName));
4548

46-
InitializeAzureBackupCmdlet(ResourceGroupName, ResourceName);
49+
InitializeAzureBackupCmdlet(ResourceGroupName, ResourceName, Location);
4750
}
4851
}
4952
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/BackUp/TriggerBackUp.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
3131
/// <summary>
3232
/// Get list of containers
3333
/// </summary>
34-
[Cmdlet(VerbsCommon.New, "AzureBackupItem"), OutputType(typeof(MBS.OperationResponse))]
34+
[Cmdlet(VerbsData.Backup, "AzureBackupItem"), OutputType(typeof(MBS.OperationResponse))]
3535
public class TriggerAzureBackup : AzureBackupDSCmdletBase
3636
{
3737
public override void ExecuteCmdlet()
@@ -44,26 +44,26 @@ public override void ExecuteCmdlet()
4444

4545
MBS.OperationResponse triggerBackUpInfo =
4646
AzureBackupClient.BackUp.TriggerBackUpAsync(GetCustomRequestHeaders(),
47-
AzureBackupItem.ContainerUniqueName,
48-
AzureBackupItem.Type,
49-
AzureBackupItem.DataSourceId,
47+
item.ContainerUniqueName,
48+
item.Type,
49+
item.DataSourceId,
5050
CmdletCancellationToken).Result;
5151

5252
WriteVerbose("Received policy response");
5353
WriteVerbose("Received policy response2");
5454

5555
WriteVerbose("Converting response");
56-
WriteAzureBackupProtectionPolicy(triggerBackUpInfo);
56+
WriteAzureBackupOperationId(triggerBackUpInfo);
5757
});
5858
}
5959

60-
public void WriteAzureBackupProtectionPolicy(MBS.OperationResponse sourceOperationResponse)
60+
public void WriteAzureBackupOperationId(MBS.OperationResponse sourceOperationResponse)
6161
{
6262
// this needs to be uncommented once we have proper constructor
63-
//this.WriteObject(new AzureBackupRecoveryPoint(ResourceGroupName, ResourceName, sourceOperationResponse));
63+
// this.WriteObject(new AzureBackupRecoveryPoint(ResourceGroupName, ResourceName, sourceOperationResponse));
6464
}
6565

66-
public void WriteAzureBackupProtectionPolicy(IEnumerable<MBS.OperationResponse> sourceOperationResponseList)
66+
public void WriteAzureBackupOperationId(IEnumerable<MBS.OperationResponse> sourceOperationResponseList)
6767
{
6868
List<MBS.OperationResponse> targetList = new List<MBS.OperationResponse>();
6969

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Container/GetAzureBackupContainer.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public override void ExecuteCmdlet()
5757
ListContainerResponse listContainerResponse = AzureBackupClient.Container.ListAsync(queryFilterString,
5858
GetCustomRequestHeaders(), CmdletCancellationToken).Result;
5959

60+
WriteVerbose(string.Format("# of fetched containers = {0}", listContainerResponse.Objects.Count));
61+
6062
List<ContainerInfo> containerInfos = listContainerResponse.Objects.ToList();
6163

6264
// When resource group name is specified, remove all containers whose resource group name
@@ -69,10 +71,24 @@ public override void ExecuteCmdlet()
6971
});
7072
}
7173

72-
WriteObject(containerInfos.ConvertAll(containerInfo =>
74+
WriteVerbose(string.Format("# of containers after resource group filter = {0}", listContainerResponse.Objects.Count));
75+
76+
List<AzureBackupContainer> containers = containerInfos.ConvertAll(containerInfo =>
77+
{
78+
return new AzureBackupContainer(containerInfo, ResourceGroupName, ResourceName, Location);
79+
});
80+
81+
if (!string.IsNullOrEmpty(ResourceName) & !string.IsNullOrEmpty(ResourceGroupName))
7382
{
74-
return new AzureBackupContainer(containerInfo);
75-
}));
83+
if (containers.Any())
84+
{
85+
WriteObject(containers.First());
86+
}
87+
}
88+
else
89+
{
90+
WriteObject(containers);
91+
}
7692
});
7793
}
7894

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/DataSource/Disable-AzureBackupProtection .cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override void ExecuteCmdlet()
3535
RemoveProtectionRequestInput input = new RemoveProtectionRequestInput();
3636
input.RemoveProtectionOption = this.RemoveProtectionOption == null ? "RetainBackupData" : this.RemoveProtectionOption;
3737
WriteVerbose("RemoveProtectionOption = " + input.RemoveProtectionOption);
38-
var disbaleAzureBackupProtection = AzureBackupClient.DataSource.DisableProtectionAsync(GetCustomRequestHeaders(), AzureBackupItem.ContainerUniqueName, AzureBackupItem.Type, AzureBackupItem.DataSourceId, input, CmdletCancellationToken).Result;
38+
var disbaleAzureBackupProtection = AzureBackupClient.DataSource.DisableProtectionAsync(GetCustomRequestHeaders(), item.ContainerUniqueName, item.Type, item.DataSourceId, input, CmdletCancellationToken).Result;
3939

4040
WriteVerbose("Received policy response");
4141
WriteVerbose("Converting response");

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/DataSource/Enable-AzureBackupProtection .cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ public override void ExecuteCmdlet()
4848
WriteVerbose("Making client call");
4949
SetProtectionRequestInput input = new SetProtectionRequestInput();
5050
input.PolicyId = Policy.InstanceId;
51-
if (AzureBackupItem.GetType() == ((AzureBackupItem)AzureBackupItem).GetType())
51+
if (Item.GetType() == ((AzureBackupItem)Item).GetType())
5252
{
53-
input.ProtectableObjectType = (AzureBackupItem as AzureBackupItem).Type;
54-
input.ProtectableObjects.Add((AzureBackupItem as AzureBackupItem).Name);
53+
input.ProtectableObjectType = (Item as AzureBackupItem).Type;
54+
input.ProtectableObjects.Add((Item as AzureBackupItem).Name);
5555
}
56-
else if (AzureBackupItem.GetType() == ((AzureBackupContainer)AzureBackupItem).GetType())
56+
else if (Item.GetType() == ((AzureBackupContainer)Item).GetType())
5757
{
58-
if((AzureBackupItem as AzureBackupContainer).ContainerType == ContainerType.IaasVMContainer.ToString())
58+
if((Item as AzureBackupContainer).ContainerType == ContainerType.IaasVMContainer.ToString())
5959
{
6060
input.ProtectableObjectType = DataSourceType.VM.ToString();
61-
input.ProtectableObjects.Add((AzureBackupItem as AzureBackupContainer).ContainerUniqueName);
61+
input.ProtectableObjects.Add((Item as AzureBackupContainer).ContainerUniqueName);
6262
}
6363
}
6464
else

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
2727
[Cmdlet(VerbsCommon.Get, "AzureBackupProtectionPolicy"), OutputType(typeof(AzureBackupProtectionPolicy), typeof(List<AzureBackupProtectionPolicy>))]
2828
public class GetAzureBackupProtectionPolicy : AzureBackupVaultCmdletBase
2929
{
30-
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)]
30+
[Parameter(Position = 3, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)]
3131
[ValidateNotNullOrEmpty]
3232
public string Name { get; set; }
3333

@@ -60,7 +60,7 @@ public override void ExecuteCmdlet()
6060

6161
public void WriteAzureBackupProtectionPolicy(ProtectionPolicyInfo sourcePolicy)
6262
{
63-
this.WriteObject(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, sourcePolicy));
63+
this.WriteObject(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, sourcePolicy));
6464
}
6565

6666
public void WriteAzureBackupProtectionPolicy(IEnumerable<ProtectionPolicyInfo> sourcePolicyList)
@@ -69,7 +69,7 @@ public void WriteAzureBackupProtectionPolicy(IEnumerable<ProtectionPolicyInfo> s
6969

7070
foreach (var sourcePolicy in sourcePolicyList)
7171
{
72-
targetList.Add(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, sourcePolicy));
72+
targetList.Add(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, sourcePolicy));
7373
}
7474

7575
this.WriteObject(targetList, true);

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/RecoveryPoint/GetAzureBackupRecoveryPoint.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
2727
[Cmdlet(VerbsCommon.Get, "AzureBackupRecoveryPoint"), OutputType(typeof(AzureBackupRecoveryPoint), typeof(List<AzureBackupRecoveryPoint>))]
2828
public class GetAzureBackupRecoveryPoint : AzureBackupDSCmdletBase
2929
{
30-
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)]
30+
[Parameter(Position = 1, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.RecoveryPointId)]
3131
[ValidateNotNullOrEmpty]
3232
public string Id { get; set; }
3333

@@ -41,9 +41,9 @@ public override void ExecuteCmdlet()
4141

4242
RecoveryPointListResponse recoveryPointListResponse =
4343
AzureBackupClient.RecoveryPoint.ListAsync(GetCustomRequestHeaders(),
44-
AzureBackupItem.ContainerUniqueName,
45-
AzureBackupItem.Type,
46-
AzureBackupItem.DataSourceId,
44+
item.ContainerUniqueName,
45+
item.Type,
46+
item.DataSourceId,
4747
CmdletCancellationToken).Result;
4848

4949
WriteVerbose("Received policy response");
@@ -59,16 +59,16 @@ public override void ExecuteCmdlet()
5959
}
6060

6161
WriteVerbose("Converting response");
62-
WriteAzureBackupProtectionPolicy(recoveryPointObjects, AzureBackupItem);
62+
WriteAzureBackupRecoveryPoint(recoveryPointObjects, item);
6363
});
6464
}
6565

66-
public void WriteAzureBackupProtectionPolicy(RecoveryPointInfo sourceRecoverPoint, AzureBackupItem azureBackupItem)
66+
public void WriteAzureBackupRecoveryPoint(RecoveryPointInfo sourceRecoverPoint, AzureBackupItem azureBackupItem)
6767
{
6868
this.WriteObject(new AzureBackupRecoveryPoint(sourceRecoverPoint, azureBackupItem));
6969
}
7070

71-
public void WriteAzureBackupProtectionPolicy(IEnumerable<RecoveryPointInfo> sourceRecoverPointList, AzureBackupItem azureBackupItem)
71+
public void WriteAzureBackupRecoveryPoint(IEnumerable<RecoveryPointInfo> sourceRecoverPointList, AzureBackupItem azureBackupItem)
7272
{
7373
List<AzureBackupRecoveryPoint> targetList = new List<AzureBackupRecoveryPoint>();
7474

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/VaultCredentials/GetAzureBackupVaultCredentials.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ public override void ExecuteCmdlet()
4545

4646
ExecutionBlock(() =>
4747
{
48-
WriteVerbose(string.Format("Profile == null : {0}", (Profile == null).ToString()));
49-
WriteVerbose(string.Format("Profile.DefaultSubscription == null : {0}", (Profile.DefaultSubscription == null).ToString()));
48+
if (!Directory.Exists(TargetLocation))
49+
{
50+
throw new ArgumentException("The target location provided is not a directory. Please provide a directory.");
51+
}
52+
5053
string subscriptionId = Profile.DefaultSubscription.Id.ToString();
5154
string resourceType = "resourceType";
5255
string displayName = subscriptionId + "_" + ResourceGroupName + "_" + ResourceName;
@@ -62,7 +65,6 @@ public override void ExecuteCmdlet()
6265
DateTime.UtcNow.AddHours(this.GetCertificateExpiryInHours()));
6366

6467
AcsNamespace acsNamespace = new AcsNamespace();
65-
6668
string channelIntegrityKey = string.Empty;
6769
try
6870
{
@@ -80,8 +82,16 @@ public override void ExecuteCmdlet()
8082
string vaultCredsFileContent = GenerateVaultCreds(cert, subscriptionId, resourceType, acsNamespace);
8183

8284
// prepare for download
83-
string fileName = string.Format("{0}_{1}.VaultCredentials", displayName, DateTime.UtcNow.ToLongDateString());
84-
string filePath = Path.Combine(Path.GetDirectoryName(TargetLocation), fileName);
85+
string fileName = string.Format("{0}_{1}.VaultCredentials", displayName, DateTime.UtcNow.ToString("yyyy-dd-M--HH-mm-ss"));
86+
string directoryPath = Path.GetDirectoryName(TargetLocation);
87+
if (directoryPath == null)
88+
{
89+
// TargetLocation is a root path
90+
directoryPath = TargetLocation;
91+
}
92+
string filePath = Path.Combine(directoryPath, fileName);
93+
WriteVerbose(string.Format("Saving Vault Credentials to file : {0}", filePath));
94+
8595
File.WriteAllBytes(filePath, Encoding.UTF8.GetBytes(vaultCredsFileContent));
8696

8797
// Output filename back to user

src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@
118118
<Reference Include="System.Runtime.Caching" />
119119
<Reference Include="System.Runtime.Serialization" />
120120
<Reference Include="System.Security" />
121-
<Reference Include="System.Web" />
122121
<Reference Include="System.Xml.Linq" />
123122
<Reference Include="System.Data.DataSetExtensions" />
124123
<Reference Include="Microsoft.CSharp" />
@@ -136,9 +135,10 @@
136135
<Compile Include="Cmdlets\DataSource\Disable-AzureBackupProtection .cs" />
137136
<Compile Include="Cmdlets\DataSource\Enable-AzureBackupProtection .cs" />
138137
<Compile Include="Cmdlets\DataSource\GetAzureBackupItem.cs" />
138+
<Compile Include="Cmdlets\RecoveryPoint\GetAzureBackupRecoveryPoint.cs" />
139+
<Compile Include="Cmdlets\Container\GetAzureBackupContainer.cs" />
139140
<Compile Include="Cmdlets\Jobs\GetAzureBackupJob.cs" />
140141
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureBackupProtectionPolicy.cs" />
141-
<Compile Include="Cmdlets\RecoveryPoint\GetAzureBackupRecoveryPoint.cs" />
142142
<Compile Include="Cmdlets\VaultCredentials\AcsNamespace.cs" />
143143
<Compile Include="Cmdlets\VaultCredentials\CertUtils.cs" />
144144
<Compile Include="Cmdlets\VaultCredentials\Constants.cs" />

0 commit comments

Comments
 (0)