1
1
use super :: DatabaseClient ;
2
- use crate :: authorization_policy:: { generate_authorization, generate_resource_link} ;
3
- use crate :: headers:: * ;
4
2
use crate :: operations:: * ;
5
3
use crate :: resources:: permission:: AuthorizationToken ;
6
- use crate :: resources:: ResourceType ;
7
- use crate :: { ReadonlyString , TimeNonce } ;
4
+ use crate :: ReadonlyString ;
8
5
9
- use azure_core:: { ClientOptions , HttpClient , Pipeline , Request } ;
10
- use http:: request:: Builder as RequestBuilder ;
11
- use http:: { header, HeaderValue } ;
6
+ use azure_core:: { ClientOptions , Pipeline , Request } ;
12
7
13
8
use std:: fmt:: Debug ;
14
9
use std:: sync:: Arc ;
@@ -18,13 +13,10 @@ use std::sync::Arc;
18
13
pub const EMULATOR_ACCOUNT_KEY : & str =
19
14
"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" ;
20
15
21
- const AZURE_VERSION : & str = "2018-12-31" ;
22
-
23
16
/// A plain Cosmos client.
24
17
#[ derive( Debug , Clone ) ]
25
18
pub struct CosmosClient {
26
19
pipeline : Pipeline ,
27
- auth_token : AuthorizationToken ,
28
20
cloud_location : CloudLocation ,
29
21
}
30
22
@@ -75,14 +67,9 @@ impl CosmosClient {
75
67
/// Create a new `CosmosClient` which connects to the account's instance in the public Azure cloud.
76
68
pub fn new ( account : String , auth_token : AuthorizationToken , options : CosmosOptions ) -> Self {
77
69
let cloud_location = CloudLocation :: Public ( account) ;
78
- // TODO: The AuthorizationToken will only be stored in the pipeline via its policy.
79
- // Right now the AuthorizationToken is a field of the Client.
80
- // This will be corrected once every Cosmos function has been be migrated to the pipeline.
81
- // Once that happens, we will remove the clone below.
82
- let pipeline = new_pipeline_from_options ( options, auth_token. clone ( ) ) ;
70
+ let pipeline = new_pipeline_from_options ( options, auth_token) ;
83
71
Self {
84
72
pipeline,
85
- auth_token,
86
73
cloud_location,
87
74
}
88
75
}
@@ -108,10 +95,9 @@ impl CosmosClient {
108
95
options : CosmosOptions ,
109
96
) -> Self {
110
97
let cloud_location = CloudLocation :: China ( account) ;
111
- let pipeline = new_pipeline_from_options ( options, auth_token. clone ( ) ) ;
98
+ let pipeline = new_pipeline_from_options ( options, auth_token) ;
112
99
Self {
113
100
pipeline,
114
- auth_token,
115
101
cloud_location,
116
102
}
117
103
}
@@ -124,10 +110,9 @@ impl CosmosClient {
124
110
options : CosmosOptions ,
125
111
) -> Self {
126
112
let cloud_location = CloudLocation :: Custom { account, uri } ;
127
- let pipeline = new_pipeline_from_options ( options, auth_token. clone ( ) ) ;
113
+ let pipeline = new_pipeline_from_options ( options, auth_token) ;
128
114
Self {
129
115
pipeline,
130
- auth_token,
131
116
cloud_location,
132
117
}
133
118
}
@@ -140,19 +125,15 @@ impl CosmosClient {
140
125
account : String :: from ( "Custom" ) ,
141
126
uri,
142
127
} ;
143
- let pipeline = new_pipeline_from_options ( options, auth_token. clone ( ) ) ;
128
+ let pipeline = new_pipeline_from_options ( options, auth_token) ;
144
129
Self {
145
130
pipeline,
146
- auth_token,
147
131
cloud_location,
148
132
}
149
133
}
150
134
151
135
/// Set the auth token used
152
136
pub fn auth_token ( & mut self , auth_token : AuthorizationToken ) {
153
- // TODO: To remove once everything uses the AutorizationPolicy
154
- self . auth_token = auth_token. clone ( ) ;
155
-
156
137
// we replace the AuthorizationPolicy. This is
157
138
// the last-1 policy by construction.
158
139
let auth_policy: Arc < dyn azure_core:: Policy > =
@@ -177,74 +158,23 @@ impl CosmosClient {
177
158
DatabaseClient :: new ( self , database_name)
178
159
}
179
160
180
- /// Prepares an `http::RequestBuilder`.
181
- ///
182
- /// TODO: Remove once all operations have been moved to pipeline architecture. This is used by
183
- /// legacy operations that have not moved to the use of the pipeline architecture. Once
184
- /// that is complete, this will be superceded by `prepare_request_pipeline`.
185
- pub ( crate ) fn prepare_request (
186
- & self ,
187
- uri_path : & str ,
188
- http_method : http:: Method ,
189
- resource_type : ResourceType ,
190
- ) -> RequestBuilder {
191
- let time = TimeNonce :: default ( ) ;
192
-
193
- let auth = {
194
- let resource_link = generate_resource_link ( uri_path) ;
195
- trace ! (
196
- "resource_link generated by prepare_request == {}" ,
197
- resource_link
198
- ) ;
199
- generate_authorization (
200
- & self . auth_token ,
201
- & http_method,
202
- & resource_type,
203
- resource_link,
204
- time,
205
- )
206
- } ;
207
- trace ! ( "prepare_request::auth == {:?}" , auth) ;
208
- let uri = format ! ( "{}/{}" , self . cloud_location. url( ) , uri_path) ;
209
- debug ! ( "building request. uri: {}" , uri) ;
210
-
211
- RequestBuilder :: new ( )
212
- . method ( http_method)
213
- . uri ( uri)
214
- . header ( HEADER_DATE , time. to_string ( ) )
215
- . header ( HEADER_VERSION , HeaderValue :: from_static ( AZURE_VERSION ) )
216
- . header ( header:: AUTHORIZATION , auth)
217
- }
218
-
219
- /// Prepares' an `azure_core::Request`. This function will
220
- /// add the cloud location to the URI suffix and generate
221
- /// a Request with the specified HTTP Method.
222
- /// It will also set the body to an empty Bytes instance.
223
- /// *Note*: This call does not handle authorization as
224
- /// it will be done by the `AuthorizationPolicy`.
161
+ /// Prepares' an `azure_core::Request`.
225
162
///
226
- /// Note: Eventually this method will replace `prepare_request` fully.
163
+ /// This function will add the cloud location to the URI suffix and generate
164
+ /// a Request with the specified HTTP Method. It will also set the body
165
+ /// to an empty `Bytes` instance.
227
166
pub ( crate ) fn prepare_request_pipeline (
228
167
& self ,
229
168
uri_path : & str ,
230
169
http_method : http:: Method ,
231
170
) -> Request {
232
171
let uri = format ! ( "{}/{}" , self . cloud_location. url( ) , uri_path) ;
233
- RequestBuilder :: new ( )
234
- . method ( http_method)
235
- . uri ( uri)
236
- . body ( bytes:: Bytes :: new ( ) )
237
- . unwrap ( )
238
- . into ( )
172
+ Request :: new ( uri. parse ( ) . unwrap ( ) , http_method)
239
173
}
240
174
241
175
pub ( crate ) fn pipeline ( & self ) -> & Pipeline {
242
176
& self . pipeline
243
177
}
244
-
245
- pub ( crate ) fn http_client ( & self ) -> & dyn HttpClient {
246
- self . pipeline . http_client ( )
247
- }
248
178
}
249
179
250
180
/// The cloud with which you want to interact.
0 commit comments