Skip to content

Commit 707af15

Browse files
committed
PR comments
1 parent 1f40abb commit 707af15

File tree

5 files changed

+162
-109
lines changed

5 files changed

+162
-109
lines changed

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/Commands.RecoveryServices.SiteRecovery.Test.Netcore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1111
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
1212
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
13-
<OutputPath>$(ProjectDir)..\..\..\Package\$(Configuration)\ResourceManager\AzureResourceManager\Az.Profile\</OutputPath>
13+
<OutputPath>$(ProjectDir)..\..\..\Package\$(Configuration)\ResourceManager\AzureResourceManager\Az.RecoveryServices\</OutputPath>
1414
<WarningsAsErrors />
1515
</PropertyGroup>
1616

src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/Common/AsrTests.cs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
using Xunit.Abstractions;
1818
using Microsoft.Azure.ServiceManagemenet.Common.Models;
1919
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
21+
using Microsoft.Azure.Portal.RecoveryServices.Models.Common;
2022

2123
namespace RecoveryServices.SiteRecovery.Test
2224
{
@@ -88,33 +90,22 @@ public void V2AGetNotificationTest()
8890
"Test-NotificationSettings -vaultSettingsFilePath \"" + this.vaultSettingsFilePath + "\"");
8991
}
9092

91-
[Fact(Skip = "Failing, needs service team to fix")]
93+
[Fact]
9294
[Trait(
9395
Category.AcceptanceType,
9496
Category.CheckIn)]
9597
public void CIKTokenValidation()
9698
{
97-
DateTime? dateTime = new DateTime(636604856296924385);
98-
// PSRecoveryServicesClient.asrVaultCreds = new ASRVaultCreds();
99-
// PSRecoveryServicesClient.asrVaultCreds.ChannelIntegrityKey = "RandomRandom";
100-
101-
// var cikToken = PSRecoveryServicesClient.GenerateAgentAuthenticationHeader(
102-
// "e5ec3f71-75c6-4688-b557-6ef69d2e7514-2018-04-27 22:43:45Z-Ps",
103-
// dateTime);
104-
105-
// Assert.Equal(
106-
// cikToken,
107-
// "{\"NotBeforeTimestamp\":\"\\/Date(1524865429692)\\/\",\"NotAfterTimestamp\":\"\\/Date(1525470229692)\\/\",\"ClientRequestId\":\"e5ec3f71-75c6-4688-b557-6ef69d2e7514-2018-04-27 22:43:45Z-Ps\",\"HashFunction\":\"HMACSHA256\",\"Hmac\":\"cYcaVjQ7BOG/lVrrl7dhwK5WXad6mvQdqm3ce3JSRY4=\",\"Version\":{\"Major\":1,\"Minor\":2,\"Build\":-1,\"Revision\":-1,\"MajorRevision\":-1,\"MinorRevision\":-1},\"PropertyBag\":{}}");
108-
//} // PSRecoveryServicesClient.asrVaultCreds = new ASRVaultCreds();
109-
// PSRecoveryServicesClient.asrVaultCreds.ChannelIntegrityKey = "RandomRandom";
110-
111-
// var cikToken = PSRecoveryServicesClient.GenerateAgentAuthenticationHeader(
112-
// "e5ec3f71-75c6-4688-b557-6ef69d2e7514-2018-04-27 22:43:45Z-Ps",
113-
// dateTime);
11499

115-
// Assert.Equal(
116-
// cikToken,
117-
// "{\"NotBeforeTimestamp\":\"\\/Date(1524865429692)\\/\",\"NotAfterTimestamp\":\"\\/Date(1525470229692)\\/\",\"ClientRequestId\":\"e5ec3f71-75c6-4688-b557-6ef69d2e7514-2018-04-27 22:43:45Z-Ps\",\"HashFunction\":\"HMACSHA256\",\"Hmac\":\"cYcaVjQ7BOG/lVrrl7dhwK5WXad6mvQdqm3ce3JSRY4=\",\"Version\":{\"Major\":1,\"Minor\":2,\"Build\":-1,\"Revision\":-1,\"MajorRevision\":-1,\"MinorRevision\":-1},\"PropertyBag\":{}}");
100+
DateTime dateTime = new DateTime(636604658296924385, DateTimeKind.Utc);
101+
PSRecoveryServicesClient.asrVaultCreds = new ASRVaultCreds();
102+
PSRecoveryServicesClient.asrVaultCreds.ChannelIntegrityKey = "RandomRandom";
103+
var cikToken = PSRecoveryServicesClient.GenerateAgentAuthenticationHeader(
104+
"e5ec3f71-75c6-4688-b557-6ef69d2e7514-2018-04-27 22:43:45Z-Ps",
105+
dateTime);
106+
Assert.Equal(
107+
cikToken,
108+
"{\"NotBeforeTimestamp\":\"\\/Date(1524865429692)\\/\",\"NotAfterTimestamp\":\"\\/Date(1525470229692)\\/\",\"ClientRequestId\":\"e5ec3f71-75c6-4688-b557-6ef69d2e7514-2018-04-27 22:43:45Z-Ps\",\"HashFunction\":\"HMACSHA256\",\"Hmac\":\"cYcaVjQ7BOG/lVrrl7dhwK5WXad6mvQdqm3ce3JSRY4=\",\"Version\":{\"Major\":1,\"Minor\":2,\"Build\":-1,\"Revision\":-1,\"MajorRevision\":-1,\"MinorRevision\":-1},\"PropertyBag\":{}}");
118109
}
119110
}
120111
}

src/ResourceManager/RecoveryServices/Commands.RecoveryServices/Az.RecoveryServices.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ FormatsToProcess = '.\Microsoft.Azure.Commands.RecoveryServices.Backup.format.ps
7575
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
7676
NestedModules = @('.\Microsoft.Azure.Commands.RecoveryServices.ARM.dll',
7777
'.\Microsoft.Azure.Commands.RecoveryServices.Backup.dll',
78-
'.\Microsoft.Azure.Commands.RecoveryServices.siteRecovery.dll')
78+
'.\Microsoft.Azure.Commands.RecoveryServices.SiteRecovery.dll')
7979

8080
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
8181
FunctionsToExport = @()

src/ResourceManager/RecoveryServices/Commands.RecoveryServices/Vault/GetAzureRMRecoveryServicesVaultSettingsFile.cs

Lines changed: 123 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,19 @@ public class GetAzureRmRecoveryServicesVaultSettingsFile : RecoveryServicesCmdle
6565
[ValidateNotNullOrEmpty]
6666
public ARSVault Vault { get; set; }
6767

68+
/// <summary>
69+
/// Gets or sets the path where the credential file is to be generated
70+
/// </summary>
71+
/// <summary>
72+
/// Gets or sets vault Object.
73+
/// </summary>
74+
[Parameter(Position = 2)]
75+
public string Path { get; set; }
76+
77+
#if NETSTANDARD
6878
/// <summary>
6979
/// Gets or sets Site Identifier.
7080
/// </summary>
71-
[Parameter(ParameterSetName = ARSParameterSets.ForSite, Mandatory = true)]
7281
[Parameter(ParameterSetName = ARSParameterSets.ForSiteWithCertificate, Mandatory = true)]
7382
[ValidateNotNullOrEmpty]
7483
public string SiteIdentifier { get; set; }
@@ -85,7 +94,6 @@ public class GetAzureRmRecoveryServicesVaultSettingsFile : RecoveryServicesCmdle
8594
/// <summary>
8695
/// Gets or sets SiteFriendlyName.
8796
/// </summary>
88-
[Parameter(ParameterSetName = ARSParameterSets.ForSite, Mandatory = true)]
8997
[Parameter(ParameterSetName = ARSParameterSets.ForSiteWithCertificate, Mandatory = true)]
9098
[ValidateNotNullOrEmpty]
9199
public string SiteFriendlyName { get; set; }
@@ -96,8 +104,48 @@ public class GetAzureRmRecoveryServicesVaultSettingsFile : RecoveryServicesCmdle
96104
/// <summary>
97105
/// Gets or sets vault Object.
98106
/// </summary>
99-
[Parameter(Position = 2)]
100-
public string Path { get; set; }
107+
[Parameter(ParameterSetName = ARSParameterSets.ByDefaultWithCertificate, Mandatory = false)]
108+
[Parameter(ParameterSetName = ARSParameterSets.ForSiteWithCertificate, Mandatory = false)]
109+
public SwitchParameter SiteRecovery
110+
{
111+
get { return siteRecovery; }
112+
set { siteRecovery = value; }
113+
}
114+
115+
/// <summary>
116+
/// Gets or sets the path where the credential file is to be generated
117+
/// </summary>
118+
/// <summary>
119+
/// Gets or sets vault Object.
120+
/// </summary>
121+
[Parameter(ParameterSetName = ARSParameterSets.ForBackupVaultTypeWithCertificate, Mandatory = true)]
122+
public SwitchParameter Backup
123+
{
124+
get { return backup; }
125+
set { backup = value; }
126+
}
127+
#else
128+
/// <summary>
129+
/// Gets or sets Site Identifier.
130+
/// </summary>
131+
[Parameter(ParameterSetName = ARSParameterSets.ForSite, Mandatory = true)]
132+
[ValidateNotNullOrEmpty]
133+
public string SiteIdentifier { get; set; }
134+
135+
/// <summary>
136+
/// Gets or sets certificate.
137+
/// </summary>
138+
[Parameter(ParameterSetName = ARSParameterSets.ForSite, Mandatory = true)]
139+
[Parameter(ParameterSetName = ARSParameterSets.ByDefault, Mandatory = true)]
140+
[ValidateNotNullOrEmpty]
141+
public string certificate { get; set; }
142+
143+
/// <summary>
144+
/// Gets or sets SiteFriendlyName.
145+
/// </summary>
146+
[Parameter(ParameterSetName = ARSParameterSets.ForSite, Mandatory = true)]
147+
[ValidateNotNullOrEmpty]
148+
public string SiteFriendlyName { get; set; }
101149

102150
/// <summary>
103151
/// Gets or sets the path where the credential file is to be generated
@@ -107,14 +155,11 @@ public class GetAzureRmRecoveryServicesVaultSettingsFile : RecoveryServicesCmdle
107155
/// </summary>
108156
[Parameter(ParameterSetName = ARSParameterSets.ByDefault, Mandatory = false)]
109157
[Parameter(ParameterSetName = ARSParameterSets.ForSite, Mandatory = false)]
110-
[Parameter(ParameterSetName = ARSParameterSets.ByDefaultWithCertificate, Mandatory = false)]
111-
[Parameter(ParameterSetName = ARSParameterSets.ForSiteWithCertificate, Mandatory = false)]
112158
public SwitchParameter SiteRecovery
113159
{
114160
get { return siteRecovery; }
115161
set { siteRecovery = value; }
116162
}
117-
private bool siteRecovery;
118163

119164
/// <summary>
120165
/// Gets or sets the path where the credential file is to be generated
@@ -123,12 +168,14 @@ public SwitchParameter SiteRecovery
123168
/// Gets or sets vault Object.
124169
/// </summary>
125170
[Parameter(ParameterSetName = ARSParameterSets.ForBackupVaultType, Mandatory = true)]
126-
[Parameter(ParameterSetName = ARSParameterSets.ForBackupVaultTypeWithCertificate, Mandatory = true)]
127171
public SwitchParameter Backup
128172
{
129173
get { return backup; }
130174
set { backup = value; }
131175
}
176+
#endif
177+
178+
private bool siteRecovery;
132179
private bool backup;
133180

134181
#endregion Parameters
@@ -140,8 +187,7 @@ public override void ExecuteCmdlet()
140187
{
141188
try
142189
{
143-
if (this.MyInvocation.BoundParameters.ContainsKey("this.certificate"))
144-
{
190+
#if NETSTANDARD
145191
if (backup)
146192
{
147193
this.GetBackupCredentialsWithCertificate(certificate);
@@ -150,23 +196,19 @@ public override void ExecuteCmdlet()
150196
{
151197
this.GetSiteRecoveryCredentialsWithCertificate(certificate);
152198
}
199+
200+
#else
201+
202+
if (backup)
203+
{
204+
this.GetAzureRMRecoveryServicesVaultBackupCredentials();
153205
}
154206
else
155207
{
156-
#if !NETSTANDARD
157-
if (backup)
158-
{
159-
this.GetAzureRMRecoveryServicesVaultBackupCredentials();
160-
}
161-
else
162-
{
163-
this.GetSiteRecoveryCredentials();
164-
}
165-
#else
166-
throw new ArgumentException(Resources.MissingCertificateForNetStandard);
167-
#endif
208+
this.GetSiteRecoveryCredentials();
168209
}
169210

211+
#endif
170212
}
171213
catch (AggregateException aggregateEx)
172214
{
@@ -254,7 +296,64 @@ private void GetBackupCredentialsWithCertificate(string certificate)
254296

255297
private void GetSiteRecoveryCredentialsWithCertificate(string certificate)
256298
{
299+
string subscriptionId = DefaultContext.Subscription.Id.ToString();
300+
VaultCertificateResponse vaultCertificateResponse = null;
301+
ASRSite site = new ASRSite();
302+
303+
if (!string.IsNullOrEmpty(this.SiteIdentifier)
304+
&& !string.IsNullOrEmpty(this.SiteFriendlyName))
305+
{
306+
site.ID = this.SiteIdentifier;
307+
site.Name = this.SiteFriendlyName;
308+
}
309+
try
310+
{
311+
string fileName = this.GenerateFileName();
312+
313+
string filePath = string.IsNullOrEmpty(this.Path) ? Utilities.GetDefaultPath() : this.Path;
314+
string fullFilePath = System.IO.Path.Combine(filePath, fileName);
315+
// Upload cert into ID Mgmt
316+
WriteDebug(string.Format(CultureInfo.InvariantCulture, Resources.UploadingCertToIdmgmt));
317+
byte[] bytes = Encoding.ASCII.GetBytes(certificate);
318+
var certificateArgs = new CertificateRequest();
319+
certificateArgs.Properties = new RawCertificateData();
320+
certificateArgs.Properties.Certificate = bytes;
321+
certificateArgs.Properties.AuthType = AuthType.AAD;
322+
323+
324+
string dateString = DateTime.Now.ToString("M-d-yyyy");
325+
326+
var friendlyName = string.Format("{0}{1}-{2}-vaultcredentials", this.Vault.Name, subscriptionId, dateString);
327+
vaultCertificateResponse = RecoveryServicesClient.GetRecoveryServicesClient.VaultCertificates.CreateWithHttpMessagesAsync(
328+
this.Vault.ResourceGroupName,
329+
this.Vault.Name,
330+
friendlyName,
331+
certificateArgs,
332+
RecoveryServicesClient.GetRequestHeaders()).Result.Body;
333+
WriteDebug(string.Format(CultureInfo.InvariantCulture, Resources.UploadedCertToIdmgmt));
334+
335+
string vaultCredsFileContent = GenerateVaultCredsForSiteRecovery(
336+
certificate,
337+
subscriptionId,
338+
vaultCertificateResponse,
339+
site);
257340

341+
WriteDebug(string.Format(Resources.SavingVaultCred, fullFilePath));
342+
343+
AzureSession.Instance.DataStore.WriteFile(fullFilePath, Encoding.UTF8.GetBytes(vaultCredsFileContent));
344+
345+
VaultSettingsFilePath output = new VaultSettingsFilePath()
346+
{
347+
FilePath = fullFilePath,
348+
};
349+
350+
// Output filename back to user
351+
WriteObject(output, true);
352+
}
353+
catch (Exception exception)
354+
{
355+
throw exception;
356+
}
258357
}
259358

260359
/// <summary>
@@ -282,6 +381,7 @@ private void GetSiteRecoveryCredentials()
282381
string fileName = this.GenerateFileName();
283382

284383
string filePath = string.IsNullOrEmpty(this.Path) ? Utilities.GetDefaultPath() : this.Path;
384+
filePath = ResolveUserPath(filePath);
285385

286386
// Generate file.
287387
if (RecoveryServicesClient.getVaultAuthType(this.Vault.ResourceGroupName, this.Vault.Name) == 0)
@@ -376,6 +476,7 @@ private string GenerateFileName()
376476
public void GetAzureRMRecoveryServicesVaultBackupCredentials()
377477
{
378478
string targetLocation = string.IsNullOrEmpty(this.Path) ? Utilities.GetDefaultPath() : this.Path;
479+
targetLocation = ResolveUserPath(targetLocation);
379480
if (!Directory.Exists(targetLocation))
380481
{
381482
throw new ArgumentException(Resources.VaultCredPathException);

0 commit comments

Comments
 (0)