File tree Expand file tree Collapse file tree 4 files changed +39
-6
lines changed
api_generator/src/generator/code_gen/url Expand file tree Collapse file tree 4 files changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -357,7 +357,7 @@ mod tests {
357
357
methods: vec![ HttpMethod :: Get , HttpMethod :: Post ] ,
358
358
parts: {
359
359
let mut map = BTreeMap :: new( ) ;
360
- map. insert( "index" . to_string( ) , Type { i
360
+ map. insert( "index" . to_string( ) , Type {
361
361
ty: TypeKind :: List ,
362
362
description: Some ( "A comma-separated list of index names to search" . to_string( ) ) ,
363
363
options: vec![ ] ,
Original file line number Diff line number Diff line change @@ -31,8 +31,10 @@ pub enum Credentials {
31
31
/// This requires the `native-tls` or `rustls-tls` feature to be enabled.
32
32
#[ cfg( any( feature = "native-tls" , feature = "rustls-tls" ) ) ]
33
33
Certificate ( ClientCertificate ) ,
34
- /// An id and api_key to use for API key authentication
34
+ /// An API key id and secret to use for API key authentication
35
35
ApiKey ( String , String ) ,
36
+ /// An API key as a base64-encoded id and secret
37
+ EncodedApiKey ( String ) ,
36
38
}
37
39
38
40
#[ cfg( any( feature = "native-tls" , feature = "rustls-tls" ) ) ]
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ use lazy_static::lazy_static;
41
41
use serde:: Serialize ;
42
42
use serde_json:: Value ;
43
43
use std:: {
44
+ convert:: TryFrom ,
44
45
error, fmt,
45
46
fmt:: Debug ,
46
47
io:: { self , Write } ,
@@ -492,10 +493,14 @@ impl Transport {
492
493
write ! ( encoder, "{}:" , i) . unwrap ( ) ;
493
494
write ! ( encoder, "{}" , k) . unwrap ( ) ;
494
495
}
495
- request_builder. header (
496
- AUTHORIZATION ,
497
- HeaderValue :: from_bytes ( & header_value) . unwrap ( ) ,
498
- )
496
+ let mut header_value = HeaderValue :: from_bytes ( & header_value) . unwrap ( ) ;
497
+ header_value. set_sensitive ( true ) ;
498
+ request_builder. header ( AUTHORIZATION , header_value)
499
+ }
500
+ Credentials :: EncodedApiKey ( k) => {
501
+ let mut header_value = HeaderValue :: try_from ( format ! ( "ApiKey {}" , k) ) . unwrap ( ) ;
502
+ header_value. set_sensitive ( true ) ;
503
+ request_builder. header ( AUTHORIZATION , header_value)
499
504
}
500
505
}
501
506
}
Original file line number Diff line number Diff line change @@ -74,6 +74,32 @@ async fn api_key_header() -> Result<(), failure::Error> {
74
74
Ok ( ( ) )
75
75
}
76
76
77
+ #[ tokio:: test]
78
+ async fn encoded_api_key_header ( ) -> Result < ( ) , failure:: Error > {
79
+ let server = server:: http ( move |req| async move {
80
+ let mut header_value = b"ApiKey " . to_vec ( ) ;
81
+ {
82
+ let mut encoder = EncoderWriter :: new ( & mut header_value, & BASE64_STANDARD ) ;
83
+ write ! ( encoder, "id:api_key" ) . unwrap ( ) ;
84
+ }
85
+
86
+ assert_eq ! (
87
+ req. headers( ) [ "authorization" ] ,
88
+ String :: from_utf8( header_value) . unwrap( )
89
+ ) ;
90
+ http:: Response :: default ( )
91
+ } ) ;
92
+
93
+ let builder = client:: create_builder ( format ! ( "http://{}" , server. addr( ) ) . as_ref ( ) )
94
+ // result of `echo -n "id:api_key" | base64`
95
+ . auth ( Credentials :: EncodedApiKey ( "aWQ6YXBpX2tleQ==" . into ( ) ) ) ;
96
+
97
+ let client = client:: create ( builder) ;
98
+ let _response = client. ping ( ) . send ( ) . await ?;
99
+
100
+ Ok ( ( ) )
101
+ }
102
+
77
103
#[ tokio:: test]
78
104
async fn bearer_header ( ) -> Result < ( ) , failure:: Error > {
79
105
let server = server:: http ( move |req| async move {
You can’t perform that action at this time.
0 commit comments