Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ideal-world/bios
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed May 14, 2024
2 parents d4d1323 + cd310e1 commit fffc0ec
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions backend/spi/spi-plugin/src/api/ci/plugin_ci_exec_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl PluginExecApi {
}
TardisResp::ok(PluginExecReq {
body: Some(tardis::serde_json::Value::String(msg.0)),
query: None,
header: None,
})
}
Expand Down
1 change: 1 addition & 0 deletions backend/spi/spi-plugin/src/dto/plugin_exec_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use tardis::{serde_json::Value, web::poem_openapi};
#[derive(poem_openapi::Object, Serialize, Deserialize, Debug)]
pub struct PluginExecReq {
pub header: Option<HashMap<String, String>>,
pub query: Option<HashMap<String, String>>,
pub body: Option<Value>,
}

Expand Down
17 changes: 16 additions & 1 deletion backend/spi/spi-plugin/src/serv/plugin_exec_serv.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::collections::HashMap;
use std::path::Path;

use bios_basic::rbum::serv::rbum_item_serv::RbumItemCrudOperation;
use bios_basic::rbum::serv::rbum_kind_serv::RbumKindServ;
use tardis::basic::dto::TardisContext;
Expand Down Expand Up @@ -27,6 +30,7 @@ impl PluginExecServ {
&spi_bs.conn_uri,
Self::build_url(
&format!("{}{}", if spi_api.path_and_query.starts_with('/') { "" } else { "/" }, &spi_api.path_and_query),
exec_req.query,
exec_req.body.clone(),
funs,
)?
Expand Down Expand Up @@ -71,7 +75,18 @@ impl PluginExecServ {
return Err(funs.err().not_found(&PluginApiServ::get_obj_name(), "exec", "exec api is not fond", ""));
}

fn build_url(path: &str, body: Option<Value>, funs: &TardisFunsInst) -> TardisResult<String> {
fn build_url(path: &str, query: Option<HashMap<String, String>>, body: Option<Value>, funs: &TardisFunsInst) -> TardisResult<String> {
let mut path = path.to_string();
if let Some(query) = query {
let query_str = query.iter().map(|(k, v)| format!("{}={}", k, v)).collect::<Vec<String>>().join("&");
if path.ends_with('?') {
path.push_str(&query_str);
} else if path.contains('?') {
path.push_str(&format!("&{}", query_str));
} else {
path.push_str(&format!("?{}", query_str));
}
}
if !path.contains(':') {
return Ok(path.to_string());
}
Expand Down
1 change: 1 addition & 0 deletions backend/spi/spi-plugin/tests/test_plugin_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub async fn test(client: &mut TestHttpClient) -> TardisResult<()> {
TardisFuns::crypto.base64.encode(&TardisFuns::json.obj_to_string(&client.context()).unwrap()),
)])),
body: Some(json!({ "msg": "object" })),
query: None,
},
)
.await;
Expand Down

0 comments on commit fffc0ec

Please sign in to comment.