@@ -107,8 +107,8 @@ impl SgFilterAuth {
107
107
header_map
108
108
. get ( & self . header_is_mix_req )
109
109
. map ( |v : & HeaderValue | {
110
- bool:: from_str ( v. to_str ( ) . map_err ( |e| TardisError :: custom ( "502" , & format ! ( "[Plugin .Auth] parse header IS_MIX_REQ error:{e}" ) , "" ) ) ?)
111
- . map_err ( |e| TardisError :: custom ( "502" , & format ! ( "[Plugin .Auth] parse header IS_MIX_REQ error:{e}" ) , "" ) )
110
+ bool:: from_str ( v. to_str ( ) . map_err ( |e| TardisError :: custom ( "502" , & format ! ( "[SG.Filter .Auth] parse header IS_MIX_REQ error:{e}" ) , "" ) ) ?)
111
+ . map_err ( |e| TardisError :: custom ( "502" , & format ! ( "[SG.Filter .Auth] parse header IS_MIX_REQ error:{e}" ) , "" ) )
112
112
} )
113
113
. transpose ( )
114
114
. ok ( )
@@ -139,13 +139,13 @@ impl SgPluginFilter for SgFilterAuth {
139
139
let mut cs = HashMap :: < String , Value > :: new ( ) ;
140
140
cs. insert (
141
141
bios_auth:: auth_constants:: DOMAIN_CODE . to_string ( ) ,
142
- serde_json:: to_value ( self . auth_config . clone ( ) ) . map_err ( |e| TardisError :: internal_error ( & format ! ( "[Plugin .Auth]init auth config error: {e:?}" ) , "" ) ) ?,
142
+ serde_json:: to_value ( self . auth_config . clone ( ) ) . map_err ( |e| TardisError :: internal_error ( & format ! ( "[SG.Filter .Auth]init auth config error: {e:?}" ) , "" ) ) ?,
143
143
) ;
144
144
TardisFuns :: init_conf ( TardisConfig {
145
145
cs,
146
146
fw : FrameworkConfig {
147
147
app : AppConfig {
148
- name : "spacegate.plugin.auth " . to_string ( ) ,
148
+ name : "spacegate.SG.Filter.Auth " . to_string ( ) ,
149
149
desc : "This is a spacegate plugin-auth" . to_string ( ) ,
150
150
..Default :: default ( )
151
151
} ,
@@ -158,7 +158,7 @@ impl SgPluginFilter for SgFilterAuth {
158
158
self . cache_url . as_str ( )
159
159
}
160
160
. parse ( )
161
- . map_err ( |e| TardisError :: internal_error ( & format ! ( "[Plugin .Auth]invalid redis url: {e:?}" ) , "-1" ) ) ?,
161
+ . map_err ( |e| TardisError :: internal_error ( & format ! ( "[SG.Filter .Auth]invalid redis url: {e:?}" ) , "-1" ) ) ?,
162
162
)
163
163
. build ( )
164
164
. into ( ) ,
@@ -198,9 +198,9 @@ impl SgPluginFilter for SgFilterAuth {
198
198
return Ok ( ( true , ctx) ) ;
199
199
}
200
200
201
- log:: trace!( "[Plugin .Auth] request filter info: request path is {}" , ctx. request. get_uri( ) . path( ) ) ;
201
+ log:: trace!( "[SG.Filter .Auth] request filter info: request path is {}" , ctx. request. get_uri( ) . path( ) ) ;
202
202
if ctx. request . get_method ( ) . eq ( & Method :: GET ) && ctx. request . get_uri ( ) . path ( ) == self . fetch_server_config_path . as_str ( ) {
203
- log:: debug!( "[Plugin .Auth] request path hit fetch server config path: {}" , self . fetch_server_config_path) ;
203
+ log:: debug!( "[SG.Filter .Auth] request path hit fetch server config path: {}" , self . fetch_server_config_path) ;
204
204
ctx. set_action ( SgRouteFilterRequestAction :: Response ) ;
205
205
let mut headers = HeaderMap :: new ( ) ;
206
206
headers. insert ( http:: header:: CONTENT_TYPE , HeaderValue :: from_static ( "application/json" ) ) ;
@@ -211,15 +211,15 @@ impl SgPluginFilter for SgFilterAuth {
211
211
msg : "" . to_string ( ) ,
212
212
data : Some ( auth_res_serv:: get_apis_json ( ) ?) ,
213
213
} )
214
- . map_err ( |e| TardisError :: bad_request ( & format ! ( "[Plugin .Auth] fetch_server_config serde error: {e}" ) , "" ) ) ?,
214
+ . map_err ( |e| TardisError :: bad_request ( & format ! ( "[SG.Filter .Auth] fetch_server_config serde error: {e}" ) , "" ) ) ?,
215
215
) ;
216
216
return Ok ( ( true , ctx) ) ;
217
217
}
218
218
219
219
let is_true_mix_req = self . get_is_true_mix_req_from_header ( ctx. request . get_headers ( ) ) ;
220
220
221
221
if self . auth_config . strict_security_mode && !is_true_mix_req {
222
- log:: debug!( "[Plugin .Auth] handle mix request" ) ;
222
+ log:: debug!( "[SG.Filter .Auth] handle mix request" ) ;
223
223
let mut ctx = mix_req_to_ctx ( & self . auth_config , & self . mix_replace_url , ctx) . await ?;
224
224
ctx. request . set_header_str ( & self . header_is_mix_req , "true" ) ?;
225
225
return Ok ( ( false , ctx) ) ;
@@ -230,19 +230,19 @@ impl SgPluginFilter for SgFilterAuth {
230
230
match auth_kernel_serv:: auth ( & mut auth_req, is_true_mix_req) . await {
231
231
Ok ( auth_result) => {
232
232
if log:: level_enabled!( log:: Level :: TRACE ) {
233
- log:: trace!( "[Plugin .Auth] auth return ok {:?}" , auth_result) ;
233
+ log:: trace!( "[SG.Filter .Auth] auth return ok {:?}" , auth_result) ;
234
234
} else if log:: level_enabled!( log:: Level :: DEBUG ) {
235
235
if let Some ( ctx) = & auth_result. ctx {
236
- log:: debug!( "[Plugin .Auth] auth return ok ctx:{ctx}" , ) ;
236
+ log:: debug!( "[SG.Filter .Auth] auth return ok ctx:{ctx}" , ) ;
237
237
} else {
238
- log:: debug!( "[Plugin .Auth] auth return ok ctx:None" , ) ;
238
+ log:: debug!( "[SG.Filter .Auth] auth return ok ctx:None" , ) ;
239
239
} ;
240
240
}
241
241
242
242
if auth_result. e . is_none ( ) {
243
243
ctx = success_auth_result_to_ctx ( auth_result, req_body. into ( ) , ctx) ?;
244
244
} else if let Some ( e) = auth_result. e {
245
- log:: info!( "[Plugin .Auth] auth failed:{e}" ) ;
245
+ log:: info!( "[SG.Filter .Auth] auth failed:{e}" ) ;
246
246
ctx. set_action ( SgRouteFilterRequestAction :: Response ) ;
247
247
ctx. response . set_status_code ( StatusCode :: from_str ( & e. code ) . unwrap_or ( StatusCode :: BAD_GATEWAY ) ) ;
248
248
ctx. response . set_body ( json ! ( { "code" : format!( "{}-gateway-cert-error" , e. code) , "message" : e. message} ) . to_string ( ) ) ;
@@ -251,9 +251,9 @@ impl SgPluginFilter for SgFilterAuth {
251
251
Ok ( ( true , ctx) )
252
252
}
253
253
Err ( e) => {
254
- log:: info!( "[Plugin .Auth] auth return error {:?}" , e) ;
254
+ log:: info!( "[SG.Filter .Auth] auth return error {:?}" , e) ;
255
255
ctx. set_action ( SgRouteFilterRequestAction :: Response ) ;
256
- ctx. response . set_body ( format ! ( "[Plugin .Auth] auth return error:{e}" ) ) ;
256
+ ctx. response . set_body ( format ! ( "[SG.Filter .Auth] auth return error:{e}" ) ) ;
257
257
Ok ( ( false , ctx) )
258
258
}
259
259
}
@@ -272,7 +272,7 @@ impl SgPluginFilter for SgFilterAuth {
272
272
let crypto_value = ctx. request . get_headers ( ) . get ( & head_key_crypto) . expect ( "" ) . clone ( ) ;
273
273
let ctx_resp_headers = ctx. response . get_headers_mut ( ) ;
274
274
ctx_resp_headers. insert (
275
- HeaderName :: try_from ( head_key_crypto. clone ( ) ) . map_err ( |e| TardisError :: internal_error ( & format ! ( "[Plugin .Auth] get header error: {e:?}" ) , "" ) ) ?,
275
+ HeaderName :: try_from ( head_key_crypto. clone ( ) ) . map_err ( |e| TardisError :: internal_error ( & format ! ( "[SG.Filter .Auth] get header error: {e:?}" ) , "" ) ) ?,
276
276
crypto_value,
277
277
) ;
278
278
@@ -295,29 +295,29 @@ async fn mix_req_to_ctx(auth_config: &AuthConfig, mix_replace_url: &str, mut ctx
295
295
let body = ctx. request . take_body_into_bytes ( ) . await ?;
296
296
let string_body = String :: from_utf8_lossy ( & body) . trim_matches ( '"' ) . to_string ( ) ;
297
297
if string_body. is_empty ( ) {
298
- TardisError :: custom ( "502" , "[Plugin .Auth.MixReq] body can't be empty" , "502-parse_mix_req-parse-error" ) ;
298
+ TardisError :: custom ( "502" , "[SG.Filter .Auth.MixReq] body can't be empty" , "502-parse_mix_req-parse-error" ) ;
299
299
}
300
300
let mut req_headers = ctx. request . get_headers ( ) . iter ( ) . map ( |( k, v) | ( k. as_str ( ) . to_string ( ) , v. to_str ( ) . expect ( "error parse header value to str" ) . to_string ( ) ) ) . collect ( ) ;
301
301
let ( body, crypto_headers) = auth_crypto_serv:: decrypt_req ( & req_headers, & Some ( string_body) , true , true , auth_config) . await ?;
302
302
req_headers. remove ( & auth_config. head_key_crypto ) ;
303
303
req_headers. remove ( & auth_config. head_key_crypto . to_ascii_lowercase ( ) ) ;
304
304
305
- let body = body. ok_or_else ( || TardisError :: custom ( "502" , "[Plugin .Auth.MixReq] decrypt body can't be empty" , "502-parse_mix_req-parse-error" ) ) ?;
305
+ let body = body. ok_or_else ( || TardisError :: custom ( "502" , "[SG.Filter .Auth.MixReq] decrypt body can't be empty" , "502-parse_mix_req-parse-error" ) ) ?;
306
306
307
307
let mix_body = TardisFuns :: json. str_to_obj :: < MixRequestBody > ( & body) ?;
308
308
ctx. set_action ( SgRouteFilterRequestAction :: Redirect ) ;
309
309
let mut true_uri = Url :: from_str ( & ctx. request . get_uri ( ) . to_string ( ) . replace ( mix_replace_url, & mix_body. uri ) )
310
- . map_err ( |e| TardisError :: custom ( "502" , & format ! ( "[Plugin .Auth.MixReq] url parse err {e}" ) , "502-parse_mix_req-url-error" ) ) ?;
310
+ . map_err ( |e| TardisError :: custom ( "502" , & format ! ( "[SG.Filter .Auth.MixReq] url parse err {e}" ) , "502-parse_mix_req-url-error" ) ) ?;
311
311
true_uri. set_path ( & true_uri. path ( ) . replace ( "//" , "/" ) ) ;
312
312
true_uri. set_query ( Some ( & if let Some ( old_query) = true_uri. query ( ) {
313
313
format ! ( "{}&_t={}" , old_query, mix_body. ts)
314
314
} else {
315
315
format ! ( "_t={}" , mix_body. ts)
316
316
} ) ) ;
317
- ctx. request . set_uri ( true_uri. as_str ( ) . parse ( ) . map_err ( |e| TardisError :: custom ( "502" , & format ! ( "[Plugin .Auth.MixReq] uri parse error: {}" , e) , "" ) ) ?) ;
317
+ ctx. request . set_uri ( true_uri. as_str ( ) . parse ( ) . map_err ( |e| TardisError :: custom ( "502" , & format ! ( "[SG.Filter .Auth.MixReq] uri parse error: {}" , e) , "" ) ) ?) ;
318
318
ctx. request . set_method (
319
319
Method :: from_str ( & mix_body. method . to_ascii_uppercase ( ) )
320
- . map_err ( |e| TardisError :: custom ( "502" , & format ! ( "[Plugin .Auth.MixReq] method parse err {e}" ) , "502-parse_mix_req-method-error" ) ) ?,
320
+ . map_err ( |e| TardisError :: custom ( "502" , & format ! ( "[SG.Filter .Auth.MixReq] method parse err {e}" ) , "502-parse_mix_req-method-error" ) ) ?,
321
321
) ;
322
322
323
323
let mut headers = req_headers;
@@ -329,8 +329,8 @@ async fn mix_req_to_ctx(auth_config: &AuthConfig, mix_replace_url: &str, mut ctx
329
329
. into_iter ( )
330
330
. map ( |( k, v) | {
331
331
Ok :: < _ , TardisError > ( (
332
- HeaderName :: from_str ( & k) . map_err ( |e| TardisError :: format_error ( & format ! ( "[Plugin .Auth] error parse str {k} to header name :{e}" ) , "" ) ) ?,
333
- HeaderValue :: from_str ( & v) . map_err ( |e| TardisError :: format_error ( & format ! ( "[Plugin .Auth] error parse str {v} to header value :{e}" ) , "" ) ) ?,
332
+ HeaderName :: from_str ( & k) . map_err ( |e| TardisError :: format_error ( & format ! ( "[SG.Filter .Auth] error parse str {k} to header name :{e}" ) , "" ) ) ?,
333
+ HeaderValue :: from_str ( & v) . map_err ( |e| TardisError :: format_error ( & format ! ( "[SG.Filter .Auth] error parse str {v} to header value :{e}" ) , "" ) ) ?,
334
334
) )
335
335
} )
336
336
. collect :: < TardisResult < HeaderMap < HeaderValue > > > ( ) ?,
@@ -343,7 +343,7 @@ async fn mix_req_to_ctx(auth_config: &AuthConfig, mix_replace_url: &str, mut ctx
343
343
"{},{}" ,
344
344
forwarded. to_str( ) . map_err( |e| TardisError :: custom(
345
345
"502" ,
346
- & format!( "[Plugin .Auth.MixReq] X-Forwarded-For header value parse err {e}" ) ,
346
+ & format!( "[SG.Filter .Auth.MixReq] X-Forwarded-For header value parse err {e}" ) ,
347
347
"502-parse_mix_req-url-error"
348
348
) ) ?,
349
349
real_ip
@@ -421,7 +421,7 @@ async fn ctx_to_auth_encrypt_req(ctx: &mut SgRoutePluginContext) -> TardisResult
421
421
if !body. is_empty ( ) {
422
422
ctx. set_ext ( plugin_constants:: BEFORE_ENCRYPT_BODY , body. to_string ( ) ) ;
423
423
}
424
- log:: trace!( "[Plugin .Auth] Before Encrypt Body {}" , body. to_string( ) ) ;
424
+ log:: trace!( "[SG.Filter .Auth] Before Encrypt Body {}" , body. to_string( ) ) ;
425
425
Ok ( AuthEncryptReq {
426
426
headers,
427
427
body : String :: from ( body) ,
@@ -432,8 +432,8 @@ fn hashmap_header_to_headermap(old_headers: HashMap<String, String>) -> TardisRe
432
432
let mut new_headers = HeaderMap :: new ( ) ;
433
433
for header in old_headers {
434
434
new_headers. insert (
435
- HeaderName :: from_str ( & header. 0 ) . map_err ( |e| TardisError :: format_error ( & format ! ( "[Plugin .Auth] request header error :{e}" ) , "" ) ) ?,
436
- HeaderValue :: from_str ( & header. 1 ) . map_err ( |e| TardisError :: format_error ( & format ! ( "[Plugin .Auth] request header error :{e}" ) , "" ) ) ?,
435
+ HeaderName :: from_str ( & header. 0 ) . map_err ( |e| TardisError :: format_error ( & format ! ( "[SG.Filter .Auth] request header error :{e}" ) , "" ) ) ?,
436
+ HeaderValue :: from_str ( & header. 1 ) . map_err ( |e| TardisError :: format_error ( & format ! ( "[SG.Filter .Auth] request header error :{e}" ) , "" ) ) ?,
437
437
) ;
438
438
}
439
439
Ok ( new_headers)
@@ -444,7 +444,7 @@ fn headermap_header_to_hashmap(old_headers: &HeaderMap) -> TardisResult<HashMap<
444
444
for header_name in old_headers. keys ( ) {
445
445
new_headers. insert (
446
446
header_name. to_string ( ) ,
447
- old_headers. get ( header_name) . expect ( "" ) . to_str ( ) . map_err ( |e| TardisError :: format_error ( & format ! ( "[Plugin .Auth] response header error :{e}" ) , "" ) ) ?. to_string ( ) ,
447
+ old_headers. get ( header_name) . expect ( "" ) . to_str ( ) . map_err ( |e| TardisError :: format_error ( & format ! ( "[SG.Filter .Auth] response header error :{e}" ) , "" ) ) ?. to_string ( ) ,
448
448
) ;
449
449
}
450
450
Ok ( new_headers)
0 commit comments