Skip to content

Commit 66ee7dd

Browse files
authored
fix spacegate-lib packname (#594)
1 parent 16bb20f commit 66ee7dd

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

gateway/spacegate-lib/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::plugin::{anti_replay, anti_xss, audit_log, auth, ip_time, rewrite_ns_
44

55
mod plugin;
66

7-
pub const PACKAGE_NAME: &str = "bios_spacegate";
7+
pub const PACKAGE_NAME: &str = "spacegate_lib";
88

99
pub fn register_lib_filter() {
1010
spacegate_kernel::register_filter_def(audit_log::SgFilterAuditLogDef);

gateway/spacegate-lib/src/plugin/auth.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ impl SgFilterAuth {
107107
header_map
108108
.get(&self.header_is_mix_req)
109109
.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}"), ""))
112112
})
113113
.transpose()
114114
.ok()
@@ -139,13 +139,13 @@ impl SgPluginFilter for SgFilterAuth {
139139
let mut cs = HashMap::<String, Value>::new();
140140
cs.insert(
141141
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:?}"), ""))?,
143143
);
144144
TardisFuns::init_conf(TardisConfig {
145145
cs,
146146
fw: FrameworkConfig {
147147
app: AppConfig {
148-
name: "spacegate.plugin.auth".to_string(),
148+
name: "spacegate.SG.Filter.Auth".to_string(),
149149
desc: "This is a spacegate plugin-auth".to_string(),
150150
..Default::default()
151151
},
@@ -158,7 +158,7 @@ impl SgPluginFilter for SgFilterAuth {
158158
self.cache_url.as_str()
159159
}
160160
.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"))?,
162162
)
163163
.build()
164164
.into(),
@@ -198,9 +198,9 @@ impl SgPluginFilter for SgFilterAuth {
198198
return Ok((true, ctx));
199199
}
200200

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());
202202
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);
204204
ctx.set_action(SgRouteFilterRequestAction::Response);
205205
let mut headers = HeaderMap::new();
206206
headers.insert(http::header::CONTENT_TYPE, HeaderValue::from_static("application/json"));
@@ -211,15 +211,15 @@ impl SgPluginFilter for SgFilterAuth {
211211
msg: "".to_string(),
212212
data: Some(auth_res_serv::get_apis_json()?),
213213
})
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}"), ""))?,
215215
);
216216
return Ok((true, ctx));
217217
}
218218

219219
let is_true_mix_req = self.get_is_true_mix_req_from_header(ctx.request.get_headers());
220220

221221
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");
223223
let mut ctx = mix_req_to_ctx(&self.auth_config, &self.mix_replace_url, ctx).await?;
224224
ctx.request.set_header_str(&self.header_is_mix_req, "true")?;
225225
return Ok((false, ctx));
@@ -230,19 +230,19 @@ impl SgPluginFilter for SgFilterAuth {
230230
match auth_kernel_serv::auth(&mut auth_req, is_true_mix_req).await {
231231
Ok(auth_result) => {
232232
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);
234234
} else if log::level_enabled!(log::Level::DEBUG) {
235235
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}",);
237237
} else {
238-
log::debug!("[Plugin.Auth] auth return ok ctx:None",);
238+
log::debug!("[SG.Filter.Auth] auth return ok ctx:None",);
239239
};
240240
}
241241

242242
if auth_result.e.is_none() {
243243
ctx = success_auth_result_to_ctx(auth_result, req_body.into(), ctx)?;
244244
} 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}");
246246
ctx.set_action(SgRouteFilterRequestAction::Response);
247247
ctx.response.set_status_code(StatusCode::from_str(&e.code).unwrap_or(StatusCode::BAD_GATEWAY));
248248
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 {
251251
Ok((true, ctx))
252252
}
253253
Err(e) => {
254-
log::info!("[Plugin.Auth] auth return error {:?}", e);
254+
log::info!("[SG.Filter.Auth] auth return error {:?}", e);
255255
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}"));
257257
Ok((false, ctx))
258258
}
259259
}
@@ -272,7 +272,7 @@ impl SgPluginFilter for SgFilterAuth {
272272
let crypto_value = ctx.request.get_headers().get(&head_key_crypto).expect("").clone();
273273
let ctx_resp_headers = ctx.response.get_headers_mut();
274274
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:?}"), ""))?,
276276
crypto_value,
277277
);
278278

@@ -295,29 +295,29 @@ async fn mix_req_to_ctx(auth_config: &AuthConfig, mix_replace_url: &str, mut ctx
295295
let body = ctx.request.take_body_into_bytes().await?;
296296
let string_body = String::from_utf8_lossy(&body).trim_matches('"').to_string();
297297
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");
299299
}
300300
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();
301301
let (body, crypto_headers) = auth_crypto_serv::decrypt_req(&req_headers, &Some(string_body), true, true, auth_config).await?;
302302
req_headers.remove(&auth_config.head_key_crypto);
303303
req_headers.remove(&auth_config.head_key_crypto.to_ascii_lowercase());
304304

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"))?;
306306

307307
let mix_body = TardisFuns::json.str_to_obj::<MixRequestBody>(&body)?;
308308
ctx.set_action(SgRouteFilterRequestAction::Redirect);
309309
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"))?;
311311
true_uri.set_path(&true_uri.path().replace("//", "/"));
312312
true_uri.set_query(Some(&if let Some(old_query) = true_uri.query() {
313313
format!("{}&_t={}", old_query, mix_body.ts)
314314
} else {
315315
format!("_t={}", mix_body.ts)
316316
}));
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), ""))?);
318318
ctx.request.set_method(
319319
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"))?,
321321
);
322322

323323
let mut headers = req_headers;
@@ -329,8 +329,8 @@ async fn mix_req_to_ctx(auth_config: &AuthConfig, mix_replace_url: &str, mut ctx
329329
.into_iter()
330330
.map(|(k, v)| {
331331
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}"), ""))?,
334334
))
335335
})
336336
.collect::<TardisResult<HeaderMap<HeaderValue>>>()?,
@@ -343,7 +343,7 @@ async fn mix_req_to_ctx(auth_config: &AuthConfig, mix_replace_url: &str, mut ctx
343343
"{},{}",
344344
forwarded.to_str().map_err(|e| TardisError::custom(
345345
"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}"),
347347
"502-parse_mix_req-url-error"
348348
))?,
349349
real_ip
@@ -421,7 +421,7 @@ async fn ctx_to_auth_encrypt_req(ctx: &mut SgRoutePluginContext) -> TardisResult
421421
if !body.is_empty() {
422422
ctx.set_ext(plugin_constants::BEFORE_ENCRYPT_BODY, body.to_string());
423423
}
424-
log::trace!("[Plugin.Auth] Before Encrypt Body {}", body.to_string());
424+
log::trace!("[SG.Filter.Auth] Before Encrypt Body {}", body.to_string());
425425
Ok(AuthEncryptReq {
426426
headers,
427427
body: String::from(body),
@@ -432,8 +432,8 @@ fn hashmap_header_to_headermap(old_headers: HashMap<String, String>) -> TardisRe
432432
let mut new_headers = HeaderMap::new();
433433
for header in old_headers {
434434
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}"), ""))?,
437437
);
438438
}
439439
Ok(new_headers)
@@ -444,7 +444,7 @@ fn headermap_header_to_hashmap(old_headers: &HeaderMap) -> TardisResult<HashMap<
444444
for header_name in old_headers.keys() {
445445
new_headers.insert(
446446
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(),
448448
);
449449
}
450450
Ok(new_headers)

gateway/spacegate-lib/src/plugin/rewrite_ns_b_ip.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ impl SgPluginFilter for SgFilterRewriteNs {
5959
format!(":{}", backend.port)
6060
};
6161
let url = format!("{}://{}{}{}", scheme, host, port, ctx.request.get_uri().path_and_query().map(|p| p.as_str()).unwrap_or(""));
62-
ctx.request.set_uri(url.parse().map_err(|e| TardisError::wrap(&format!("[Plugin.Auth.Rewrite_Ns({id})] parse url:{e}"), ""))?);
63-
log::debug!("[Plugin.Auth.Rewrite_Ns({id})] change namespace to {}", self.target_ns);
62+
ctx.request.set_uri(url.parse().map_err(|e| TardisError::wrap(&format!("[SG.Filter.Auth.Rewrite_Ns({id})] parse url:{e}"), ""))?);
63+
log::debug!("[SG.Filter.Auth.Rewrite_Ns({id})] change namespace to {}", self.target_ns);
6464
}
6565
}
6666
}

0 commit comments

Comments
 (0)