@@ -58,18 +58,31 @@ public class GetVaultCredentialsFile : RecoveryServicesCmdletBase
58
58
public string Location { get ; set ; }
59
59
60
60
/// <summary>
61
- /// Gets or sets Job Object.
61
+ /// Gets or sets vault Object.
62
62
/// </summary>
63
63
[ Parameter ( ParameterSetName = ASRParameterSets . ByObject , Mandatory = true , ValueFromPipeline = true ) ]
64
64
[ ValidateNotNullOrEmpty ]
65
65
public ASRVault Vault { get ; set ; }
66
66
67
67
/// <summary>
68
- /// Gets or sets the path where the credential file is to be generated
68
+ /// Gets or sets the site name
69
69
/// </summary>
70
70
[ Parameter ( ParameterSetName = ASRParameterSets . ByParam , Mandatory = false , HelpMessage = "The site name if the vault credentials to be downloaded for a Hyper-V sites." ) ]
71
71
public string SiteName { get ; set ; }
72
72
73
+ /// <summary>
74
+ /// Gets or sets the site id
75
+ /// </summary>
76
+ [ Parameter ( ParameterSetName = ASRParameterSets . ByParam , Mandatory = false , HelpMessage = "The site name if the vault credentials to be downloaded for a Hyper-V sites." ) ]
77
+ public string SiteId { get ; set ; }
78
+
79
+ /// <summary>
80
+ /// Gets or sets site object
81
+ /// </summary>
82
+ [ Parameter ( ParameterSetName = ASRParameterSets . ByObject , Mandatory = false , ValueFromPipeline = true ) ]
83
+ [ ValidateNotNullOrEmpty ]
84
+ public Site Site { get ; set ; }
85
+
73
86
/// <summary>
74
87
/// Gets or sets the path where the credential file is to be generated
75
88
/// </summary>
@@ -90,6 +103,12 @@ public override void ExecuteCmdlet()
90
103
case ASRParameterSets . ByObject :
91
104
this . Name = this . Vault . Name ;
92
105
this . Location = this . Vault . Location ;
106
+ if ( this . Site != null )
107
+ {
108
+ this . SiteName = this . Site . Name ;
109
+ this . SiteId = this . Site . ID ;
110
+ }
111
+
93
112
this . GetByParams ( ) ;
94
113
break ;
95
114
case ASRParameterSets . ByParam :
@@ -107,7 +126,7 @@ public override void ExecuteCmdlet()
107
126
/// <summary>
108
127
/// Method to execute the command
109
128
/// </summary>
110
- private async void GetByParams ( )
129
+ private void GetByParams ( )
111
130
{
112
131
AzureSubscription subscription = AzureSession . CurrentContext . Subscription ;
113
132
@@ -124,15 +143,22 @@ private async void GetByParams()
124
143
} ) ;
125
144
126
145
// Upload certificate
127
- UploadCertificateResponse acsDetails = await this . UpdateVaultCertificate ( cert ) ;
146
+ UploadCertificateResponse acsDetails ;
147
+ Task < UploadCertificateResponse > uploadCertificate = this . UpdateVaultCertificate ( cert ) ;
128
148
129
149
// Get Channel Integrity key
130
- string channelIntegrityKey = await this . GetChannelIntegrityKey ( ) ;
150
+ string channelIntegrityKey ;
151
+ Task < string > getChannelIntegrityKey = this . GetChannelIntegrityKey ( ) ;
152
+
153
+ uploadCertificate . Wait ( ) ;
154
+ getChannelIntegrityKey . Wait ( ) ;
155
+
156
+ acsDetails = uploadCertificate . Result ;
157
+ channelIntegrityKey = getChannelIntegrityKey . Result ;
131
158
132
159
// Generate file.
133
160
ASRVaultCreds vaultCreds = this . GenerateCredential (
134
161
subscription . Id . ToString ( ) ,
135
- this . Name ,
136
162
cert ,
137
163
acsDetails ,
138
164
channelIntegrityKey ,
@@ -142,7 +168,10 @@ private async void GetByParams()
142
168
string fileName = this . GenerateFileName ( ) ;
143
169
144
170
// write the content to a file.
145
- Utilities . WriteToFile < ASRVaultCreds > ( vaultCreds , filePath , fileName ) ;
171
+ string outputPath = Utilities . WriteToFile < ASRVaultCreds > ( vaultCreds , filePath , fileName ) ;
172
+
173
+ // print the path to the user.
174
+ this . WriteObject ( outputPath , true ) ;
146
175
}
147
176
148
177
/// <summary>
@@ -231,25 +260,26 @@ private ResourceExtendedInfo CreateVaultExtendedInformatino()
231
260
/// Method to generate the credential file content
232
261
/// </summary>
233
262
/// <param name="subscriptionId">subscription id</param>
234
- /// <param name="resourceName">resource name</param>
235
263
/// <param name="managementCert">management cert</param>
236
264
/// <param name="acsDetails">ACS details</param>
237
265
/// <param name="channelIntegrityKey">Integrity key</param>
238
266
/// <param name="cloudServiceName">cloud service name</param>
239
267
/// <returns>vault credential object</returns>
240
- private ASRVaultCreds GenerateCredential ( string subscriptionId , string resourceName , X509Certificate2 managementCert , UploadCertificateResponse acsDetails , string channelIntegrityKey , string cloudServiceName )
268
+ private ASRVaultCreds GenerateCredential ( string subscriptionId , X509Certificate2 managementCert , UploadCertificateResponse acsDetails , string channelIntegrityKey , string cloudServiceName )
241
269
{
242
270
string serializedCertifivate = Convert . ToBase64String ( managementCert . Export ( X509ContentType . Pfx ) ) ;
243
271
244
272
AcsNamespace acsNamespace = new AcsNamespace ( acsDetails ) ;
245
273
246
274
ASRVaultCreds vaultCreds = new ASRVaultCreds (
247
275
subscriptionId ,
248
- resourceName ,
276
+ this . Name ,
249
277
serializedCertifivate ,
250
278
acsNamespace ,
251
279
channelIntegrityKey ,
252
- cloudServiceName ) ;
280
+ cloudServiceName ,
281
+ this . SiteId ,
282
+ this . SiteName ) ;
253
283
254
284
return vaultCreds ;
255
285
}
0 commit comments