Skip to content

Commit cf7435b

Browse files
author
dragonfly91
committed
Download Vault Creds cmdlet fixes post component testing.
1 parent fb4ba52 commit cf7435b

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

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

0 commit comments

Comments
 (0)