13
13
// ----------------------------------------------------------------------------------
14
14
15
15
using System ;
16
+ using System . Collections . Generic ;
17
+ using System . Configuration ;
16
18
using System . Diagnostics . CodeAnalysis ;
19
+ using System . Net . Security ;
17
20
using Microsoft . Azure . Commands . Common . Authentication ;
18
21
using Microsoft . Azure . Commands . Common . Authentication . Models ;
22
+ using Microsoft . Azure . Management . Internal . Resources ;
19
23
using Microsoft . Azure . Management . RecoveryServices ;
20
- using Microsoft . Azure . Management . RecoveryServices . Models ;
21
24
using Microsoft . Azure . Portal . RecoveryServices . Models . Common ;
22
- using System . Configuration ;
23
- using System . Net . Security ;
24
- using Microsoft . Azure . Management . Resources ;
25
25
26
26
namespace Microsoft . Azure . Commands . RecoveryServices
27
27
{
@@ -56,14 +56,6 @@ public ResourceManagementClient RmClient
56
56
}
57
57
}
58
58
59
- public string RpNamespace
60
- {
61
- get
62
- {
63
- return rpNamespace ;
64
- }
65
- }
66
-
67
59
/// Azure profile
68
60
/// </summary>
69
61
public IAzureProfile Profile { get ; set ; }
@@ -92,8 +84,6 @@ public string RpNamespace
92
84
93
85
private ResourceManagementClient resourceManagementClient ;
94
86
95
- private string rpNamespace ;
96
-
97
87
/// <summary>
98
88
/// Initializes a new instance of the <see cref="PSRecoveryServicesClient" /> class with
99
89
/// required current subscription.
@@ -104,39 +94,24 @@ public PSRecoveryServicesClient(IAzureProfile azureProfile, AzureContext default
104
94
System . Configuration . Configuration recoveryServicesConfig = ConfigurationManager . OpenExeConfiguration ( System . Reflection . Assembly . GetExecutingAssembly ( ) . Location ) ;
105
95
106
96
System . Configuration . AppSettingsSection appSettings = ( System . Configuration . AppSettingsSection ) recoveryServicesConfig . GetSection ( "appSettings" ) ;
107
-
108
- var resourceProviderNamespace = string . Empty ;
109
- string resourceType = string . Empty ;
110
97
98
+ string resourceType = string . Empty ;
99
+
111
100
// Get Resource provider namespace from config if needed to communicate with internal deployments
112
101
if ( string . IsNullOrEmpty ( arsVaultCreds . ResourceNamespace ) )
113
102
{
114
- if ( appSettings . Settings . Count == 0 )
115
- {
116
- resourceProviderNamespace = ProductionRpNamespace ;
117
- }
118
- else
119
- {
120
- resourceProviderNamespace =
121
- null == appSettings . Settings [ "ProviderNamespace" ]
122
- ? ProductionRpNamespace
123
- : appSettings . Settings [ "ProviderNamespace" ] . Value ;
124
- }
125
-
126
103
Utilities . UpdateCurrentVaultContext ( new ASRVaultCreds ( )
127
104
{
128
- ResourceNamespace = resourceProviderNamespace ,
105
+ ResourceNamespace = ProductionRpNamespace ,
129
106
ARMResourceType = resourceType
130
107
} ) ;
131
108
}
132
109
133
- rpNamespace = string . Copy ( resourceProviderNamespace ) ;
134
-
135
- this . recoveryServicesClient =
110
+ this . recoveryServicesClient =
136
111
AzureSession . ClientFactory . CreateArmClient < RecoveryServicesClient > (
137
112
defaultContext , AzureEnvironment . Endpoint . ResourceManager ) ;
138
113
139
- resourceManagementClient = AzureSession . ClientFactory . CreateClient < ResourceManagementClient > ( defaultContext , AzureEnvironment . Endpoint . ResourceManager ) ;
114
+ resourceManagementClient = AzureSession . ClientFactory . CreateArmClient < ResourceManagementClient > ( defaultContext , AzureEnvironment . Endpoint . ResourceManager ) ;
140
115
}
141
116
142
117
private static bool IgnoreCertificateErrorHandler
@@ -168,22 +143,19 @@ public static string GetSubscriptionId(string resourceId)
168
143
return resourceId . Substring ( startIndex , endIndex - startIndex ) ;
169
144
}
170
145
171
- ///// <summary>
172
- ///// Gets request headers.
173
- ///// </summary>
174
- ///// <param name="shouldSignRequest">specifies whether to sign the request or not</param>
175
- ///// <returns>Custom request headers</returns>
176
- //public CustomRequestHeaders GetRequestHeaders()
177
- //{
178
- // this.ClientRequestId = Guid.NewGuid().ToString() + "-" + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ssZ") + "-P";
179
-
180
- // return new CustomRequestHeaders()
181
- // {
182
- // // ClientRequestId is a unique ID for every request.
183
- // // It is useful when diagnosing failures in API calls.
184
- // ClientRequestId = this.ClientRequestId,
185
- // AgentAuthenticationHeader = ""
186
- // };
187
- //}
146
+ /// <summary>
147
+ /// Gets request headers.
148
+ /// </summary>
149
+ /// <param name="shouldSignRequest">specifies whether to sign the request or not</param>
150
+ /// <returns>Custom request headers</returns>
151
+ public Dictionary < string , List < string > > GetRequestHeaders ( )
152
+ {
153
+ this . ClientRequestId = Guid . NewGuid ( ) . ToString ( ) + "-" + DateTime . Now . ToUniversalTime ( ) . ToString ( "yyyy-MM-dd HH:mm:ssZ" ) + "-P" ;
154
+
155
+ var dict = new Dictionary < string , List < string > > ( ) ;
156
+ dict [ "x-ms-client-request-id" ] = new List < string > ( ) { ClientRequestId } ;
157
+
158
+ return dict ;
159
+ }
188
160
}
189
161
}
0 commit comments