submissions-api: reintroduce external api
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
964fc24e26
commit
518327820d
@ -20,3 +20,4 @@ url = "2"
|
|||||||
[features]
|
[features]
|
||||||
default = ["internal"]
|
default = ["internal"]
|
||||||
internal = []
|
internal = []
|
||||||
|
external = []
|
||||||
|
144
validation/api/src/external.rs
Normal file
144
validation/api/src/external.rs
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
use crate::Error;
|
||||||
|
|
||||||
|
#[derive(Clone,Copy,serde::Serialize,serde::Deserialize)]
|
||||||
|
pub struct ScriptID(i64);
|
||||||
|
#[derive(Clone,Copy,serde::Serialize,serde::Deserialize)]
|
||||||
|
pub struct ScriptPolicyID(i64);
|
||||||
|
|
||||||
|
#[allow(nonstandard_style)]
|
||||||
|
pub struct GetScriptRequest{
|
||||||
|
pub ScriptID:ScriptID,
|
||||||
|
}
|
||||||
|
#[allow(nonstandard_style)]
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
pub struct ScriptResponse{
|
||||||
|
pub ID:i64,
|
||||||
|
pub Name:String,
|
||||||
|
pub Hash:String,
|
||||||
|
pub Source:String,
|
||||||
|
pub SubmissionID:i64,
|
||||||
|
}
|
||||||
|
#[allow(nonstandard_style)]
|
||||||
|
#[derive(serde::Serialize)]
|
||||||
|
pub struct CreateScriptRequest<'a>{
|
||||||
|
pub Name:&'a str,
|
||||||
|
pub Source:&'a str,
|
||||||
|
pub SubmissionID:Option<i64>,
|
||||||
|
}
|
||||||
|
#[allow(nonstandard_style)]
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
pub struct ScriptIDResponse{
|
||||||
|
pub ID:ScriptID,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde_repr::Serialize_repr,serde_repr::Deserialize_repr)]
|
||||||
|
#[repr(i32)]
|
||||||
|
pub enum Policy{
|
||||||
|
None=0, // not yet reviewed
|
||||||
|
Allowed=1,
|
||||||
|
Blocked=2,
|
||||||
|
Delete=3,
|
||||||
|
Replace=4,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ScriptPolicyHashRequest<'a>{
|
||||||
|
pub hash:&'a str,
|
||||||
|
}
|
||||||
|
#[allow(nonstandard_style)]
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
pub struct ScriptPolicyResponse{
|
||||||
|
pub ID:i64,
|
||||||
|
pub FromScriptHash:String,
|
||||||
|
pub ToScriptID:ScriptID,
|
||||||
|
pub Policy:Policy
|
||||||
|
}
|
||||||
|
#[allow(nonstandard_style)]
|
||||||
|
#[derive(serde::Serialize)]
|
||||||
|
pub struct CreateScriptPolicyRequest{
|
||||||
|
pub FromScriptID:ScriptID,
|
||||||
|
pub ToScriptID:ScriptID,
|
||||||
|
pub Policy:Policy,
|
||||||
|
}
|
||||||
|
#[allow(nonstandard_style)]
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
pub struct ScriptPolicyIDResponse{
|
||||||
|
pub ID:ScriptPolicyID,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(nonstandard_style)]
|
||||||
|
#[derive(serde::Serialize)]
|
||||||
|
pub struct UpdateScriptPolicyRequest{
|
||||||
|
pub ScriptPolicyID:ScriptPolicyID,
|
||||||
|
pub FromScriptID:Option<ScriptID>,
|
||||||
|
pub ToScriptID:Option<ScriptID>,
|
||||||
|
pub Policy:Option<Policy>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(nonstandard_style)]
|
||||||
|
pub struct ActionSubmissionUploadedRequest{
|
||||||
|
pub SubmissionID:i64,
|
||||||
|
pub TargetAssetID:Option<u64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct SubmissionID(pub i64);
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Context(crate::context::Context);
|
||||||
|
|
||||||
|
impl Context{
|
||||||
|
pub fn new(base_url:String,cookie:crate::context::Cookie)->reqwest::Result<Self>{
|
||||||
|
Ok(Self(crate::context::Context::new(base_url,Some(cookie))?))
|
||||||
|
}
|
||||||
|
pub async fn get_script(&self,config:GetScriptRequest)->Result<ScriptResponse,Error>{
|
||||||
|
let url_raw=format!("{}/scripts/{}",self.0.base_url,config.ScriptID.0);
|
||||||
|
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::ParseError)?;
|
||||||
|
|
||||||
|
crate::response_ok(
|
||||||
|
self.0.get(url).await.map_err(Error::Reqwest)?
|
||||||
|
).await.map_err(Error::Response)?
|
||||||
|
.json().await.map_err(Error::Reqwest)
|
||||||
|
}
|
||||||
|
pub async fn create_script<'a>(&self,config:CreateScriptRequest<'a>)->Result<ScriptIDResponse,Error>{
|
||||||
|
let url_raw=format!("{}/scripts",self.0.base_url);
|
||||||
|
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::ParseError)?;
|
||||||
|
|
||||||
|
let body=serde_json::to_string(&config).map_err(Error::JSON)?;
|
||||||
|
|
||||||
|
crate::response_ok(
|
||||||
|
self.0.post(url,body).await.map_err(Error::Reqwest)?
|
||||||
|
).await.map_err(Error::Response)?
|
||||||
|
.json().await.map_err(Error::Reqwest)
|
||||||
|
}
|
||||||
|
pub async fn get_script_policy_from_hash<'a>(&self,config:ScriptPolicyHashRequest<'a>)->Result<ScriptPolicyResponse,Error>{
|
||||||
|
let url_raw=format!("{}/script-policy/hash/{}",self.0.base_url,config.hash);
|
||||||
|
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::ParseError)?;
|
||||||
|
|
||||||
|
crate::response_ok(
|
||||||
|
self.0.get(url).await.map_err(Error::Reqwest)?
|
||||||
|
).await.map_err(Error::Response)?
|
||||||
|
.json().await.map_err(Error::Reqwest)
|
||||||
|
}
|
||||||
|
pub async fn create_script_policy(&self,config:CreateScriptPolicyRequest)->Result<ScriptPolicyIDResponse,Error>{
|
||||||
|
let url_raw=format!("{}/script-policy",self.0.base_url);
|
||||||
|
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::ParseError)?;
|
||||||
|
|
||||||
|
let body=serde_json::to_string(&config).map_err(Error::JSON)?;
|
||||||
|
|
||||||
|
crate::response_ok(
|
||||||
|
self.0.post(url,body).await.map_err(Error::Reqwest)?
|
||||||
|
).await.map_err(Error::Response)?
|
||||||
|
.json().await.map_err(Error::Reqwest)
|
||||||
|
}
|
||||||
|
pub async fn update_script_policy(&self,config:UpdateScriptPolicyRequest)->Result<(),Error>{
|
||||||
|
let url_raw=format!("{}/script-policy/id/{}",self.0.base_url,config.ScriptPolicyID.0);
|
||||||
|
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::ParseError)?;
|
||||||
|
|
||||||
|
let body=serde_json::to_string(&config).map_err(Error::JSON)?;
|
||||||
|
|
||||||
|
crate::response_ok(
|
||||||
|
self.0.post(url,body).await.map_err(Error::Reqwest)?
|
||||||
|
).await.map_err(Error::Response)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,9 @@ pub use context::Cookie;
|
|||||||
#[cfg(feature="internal")]
|
#[cfg(feature="internal")]
|
||||||
pub mod internal;
|
pub mod internal;
|
||||||
|
|
||||||
|
#[cfg(feature="external")]
|
||||||
|
pub mod external;
|
||||||
|
|
||||||
//lazy reexport
|
//lazy reexport
|
||||||
pub type ReqwestError=reqwest::Error;
|
pub type ReqwestError=reqwest::Error;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user