5
5
//! We implement that policy here, because we can't use any standard Azure SDK authentication policy.
6
6
7
7
use azure_core:: auth:: TokenCredential ;
8
+ use azure_core:: date:: OffsetDateTime ;
8
9
use azure_core:: {
9
10
date,
10
11
headers:: { HeaderValue , AUTHORIZATION , MS_DATE , VERSION } ,
11
12
Context , Policy , PolicyResult , Request , Url ,
12
13
} ;
13
14
use std:: sync:: Arc ;
14
- use time:: OffsetDateTime ;
15
15
use tracing:: trace;
16
16
use url:: form_urlencoded;
17
17
18
- #[ cfg( feature = "key-auth " ) ]
18
+ #[ cfg( feature = "key_auth " ) ]
19
19
use azure_core:: { auth:: Secret , hmac:: hmac_sha256} ;
20
20
21
21
const AZURE_VERSION : & str = "2018-12-31" ;
@@ -42,11 +42,11 @@ enum Credential {
42
42
Token ( Arc < dyn TokenCredential > ) ,
43
43
44
44
/// The credential is a key to be used to sign the HTTP request (a shared key)
45
- #[ cfg( feature = "key-auth " ) ]
45
+ #[ cfg( feature = "key_auth " ) ]
46
46
PrimaryKey ( Secret ) ,
47
47
}
48
48
49
- #[ cfg( feature = "key-auth " ) ]
49
+ #[ cfg( feature = "key_auth " ) ]
50
50
struct SignatureTarget < ' a > {
51
51
http_method : & ' a azure_core:: Method ,
52
52
resource_type : & ' a ResourceType ,
@@ -66,7 +66,7 @@ impl AuthorizationPolicy {
66
66
}
67
67
}
68
68
69
- #[ cfg( feature = "key-auth " ) ]
69
+ #[ cfg( feature = "key_auth " ) ]
70
70
pub ( crate ) fn from_shared_key ( key : Secret ) -> Self {
71
71
Self {
72
72
credential : Credential :: PrimaryKey ( key) ,
@@ -99,7 +99,7 @@ impl Policy for AuthorizationPolicy {
99
99
let auth = generate_authorization (
100
100
& self . credential ,
101
101
request. url ( ) ,
102
- #[ cfg( feature = "key-auth " ) ]
102
+ #[ cfg( feature = "key_auth " ) ]
103
103
SignatureTarget {
104
104
http_method : request. method ( ) ,
105
105
resource_type,
@@ -186,7 +186,7 @@ fn extract_resource_link(request: &Request) -> String {
186
186
async fn generate_authorization < ' a > (
187
187
auth_token : & Credential ,
188
188
url : & Url ,
189
- #[ cfg( feature = "key-auth " ) ] signature_target : SignatureTarget < ' a > ,
189
+ #[ cfg( feature = "key_auth " ) ] signature_target : SignatureTarget < ' a > ,
190
190
) -> azure_core:: Result < String > {
191
191
let ( authorization_type, signature) = match auth_token {
192
192
Credential :: Token ( token_credential) => (
@@ -199,7 +199,7 @@ async fn generate_authorization<'a>(
199
199
. to_string ( ) ,
200
200
) ,
201
201
202
- #[ cfg( feature = "key-auth " ) ]
202
+ #[ cfg( feature = "key_auth " ) ]
203
203
Credential :: PrimaryKey ( key) => {
204
204
let string_to_sign = string_to_sign ( signature_target) ;
205
205
( "master" , hmac_sha256 ( & string_to_sign, key) ?)
@@ -222,7 +222,7 @@ fn scope_from_url(url: &Url) -> String {
222
222
/// This function generates a valid authorization string, according to the documentation.
223
223
/// In case of authorization problems we can compare the `string_to_sign` generated by Azure against
224
224
/// our own.
225
- #[ cfg( feature = "key-auth " ) ]
225
+ #[ cfg( feature = "key_auth " ) ]
226
226
fn string_to_sign ( signature_target : SignatureTarget ) -> String {
227
227
// From official docs:
228
228
// StringToSign =
@@ -266,16 +266,16 @@ fn string_to_sign(signature_target: SignatureTarget) -> String {
266
266
267
267
#[ cfg( test) ]
268
268
mod tests {
269
- #[ cfg( feature = "key-auth " ) ]
269
+ #[ cfg( feature = "key_auth " ) ]
270
270
use azure_core:: auth:: AccessToken ;
271
271
272
272
use super :: * ;
273
273
274
274
#[ derive( Debug ) ]
275
- #[ cfg( feature = "key-auth " ) ]
275
+ #[ cfg( feature = "key_auth " ) ]
276
276
struct TestTokenCredential ( String ) ;
277
277
278
- #[ cfg( feature = "key-auth " ) ]
278
+ #[ cfg( feature = "key_auth " ) ]
279
279
#[ cfg_attr( target_arch = "wasm32" , async_trait:: async_trait( ?Send ) ) ]
280
280
#[ cfg_attr( not( target_arch = "wasm32" ) , async_trait:: async_trait) ]
281
281
impl TokenCredential for TestTokenCredential {
@@ -293,7 +293,7 @@ mod tests {
293
293
}
294
294
295
295
#[ test]
296
- #[ cfg( feature = "key-auth " ) ]
296
+ #[ cfg( feature = "key_auth " ) ]
297
297
fn string_to_sign_generates_expected_string_for_signing ( ) {
298
298
let time_nonce = date:: parse_rfc3339 ( "1900-01-01T01:00:00.000000000+00:00" ) . unwrap ( ) ;
299
299
@@ -315,7 +315,7 @@ mon, 01 jan 1900 01:00:00 gmt
315
315
}
316
316
317
317
#[ tokio:: test]
318
- #[ cfg( feature = "key-auth " ) ]
318
+ #[ cfg( feature = "key_auth " ) ]
319
319
async fn generate_authorization_for_token_credential ( ) {
320
320
let time_nonce = date:: parse_rfc3339 ( "1900-01-01T01:00:00.000000000+00:00" ) . unwrap ( ) ;
321
321
let cred = Arc :: new ( TestTokenCredential ( "test_token" . to_string ( ) ) ) ;
@@ -346,7 +346,7 @@ mon, 01 jan 1900 01:00:00 gmt
346
346
}
347
347
348
348
#[ tokio:: test]
349
- #[ cfg( feature = "key-auth " ) ]
349
+ #[ cfg( feature = "key_auth " ) ]
350
350
async fn generate_authorization_for_primary_key_0 ( ) {
351
351
let time_nonce = date:: parse_rfc3339 ( "1900-01-01T01:00:00.000000000+00:00" ) . unwrap ( ) ;
352
352
@@ -379,7 +379,7 @@ mon, 01 jan 1900 01:00:00 gmt
379
379
}
380
380
381
381
#[ tokio:: test]
382
- #[ cfg( feature = "key-auth " ) ]
382
+ #[ cfg( feature = "key_auth " ) ]
383
383
async fn generate_authorization_for_primary_key_1 ( ) {
384
384
let time_nonce = date:: parse_rfc3339 ( "2017-04-27T00:51:12.000000000+00:00" ) . unwrap ( ) ;
385
385
0 commit comments