validation: pull out submissions api
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Quaternions 2024-12-14 03:31:19 -08:00
parent 1450c0f3a2
commit 4ce5d5e535
14 changed files with 1494 additions and 40 deletions

1
submissions-api-rs/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

1451
submissions-api-rs/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
[package] [package]
name = "api" name = "submissions-api"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
publish = ["strafesnet"] publish = ["strafesnet"]

24
validation/Cargo.lock generated
View File

@ -41,16 +41,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "api"
version = "0.1.0"
dependencies = [
"reqwest",
"serde",
"serde_json",
"url",
]
[[package]] [[package]]
name = "arrayref" name = "arrayref"
version = "0.3.9" version = "0.3.9"
@ -968,7 +958,6 @@ dependencies = [
name = "maps-validation" name = "maps-validation"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"api",
"async-nats", "async-nats",
"futures", "futures",
"rbx_asset", "rbx_asset",
@ -979,6 +968,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"siphasher", "siphasher",
"submissions-api",
"tokio", "tokio",
] ]
@ -1812,6 +1802,18 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "submissions-api"
version = "0.1.0"
source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
checksum = "7969c6c0b770ecfb57220c340f732d62a6fb1165b9ef038e33e7cd5a9658bdd5"
dependencies = [
"reqwest",
"serde",
"serde_json",
"url",
]
[[package]] [[package]]
name = "subtle" name = "subtle"
version = "2.6.1" version = "2.6.1"

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
api = { path = "api" } submissions-api = { version = "0.1.0", registry = "strafesnet" }
async-nats = "0.38.0" async-nats = "0.38.0"
futures = "0.3.31" futures = "0.3.31"
rbx_asset = { version = "0.2.5", registry = "strafesnet" } rbx_asset = { version = "0.2.5", registry = "strafesnet" }

View File

@ -11,7 +11,7 @@ RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json COPY --from=planner /app/recipe.json recipe.json
COPY api ./api
# Notice that we are specifying the --target flag! # Notice that we are specifying the --target flag!
RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json
COPY . . COPY . .

View File

@ -9,7 +9,7 @@ mod message_handler;
#[allow(dead_code)] #[allow(dead_code)]
#[derive(Debug)] #[derive(Debug)]
pub enum StartupError{ pub enum StartupError{
API(api::ReqwestError), API(submissions_api::ReqwestError),
NatsConnect(async_nats::ConnectError), NatsConnect(async_nats::ConnectError),
NatsGetStream(async_nats::jetstream::context::GetStreamError), NatsGetStream(async_nats::jetstream::context::GetStreamError),
NatsConsumer(async_nats::jetstream::stream::ConsumerError), NatsConsumer(async_nats::jetstream::stream::ConsumerError),
@ -34,7 +34,7 @@ async fn main()->Result<(),StartupError>{
// maps-service api // maps-service api
let api_host=std::env::var("API_HOST").expect("API_HOST env required"); let api_host=std::env::var("API_HOST").expect("API_HOST env required");
let api=api::Context::new(api_host).map_err(StartupError::API)?; let api=submissions_api::Context::new(api_host).map_err(StartupError::API)?;
// nats // nats
let nats_host=std::env::var("NATS_HOST").expect("NATS_HOST env required"); let nats_host=std::env::var("NATS_HOST").expect("NATS_HOST env required");

View File

@ -26,7 +26,7 @@ pub struct MessageHandler{
impl MessageHandler{ impl MessageHandler{
pub fn new( pub fn new(
cookie_context:rbx_asset::cookie::CookieContext, cookie_context:rbx_asset::cookie::CookieContext,
api:api::Context, api:submissions_api::Context,
)->Self{ )->Self{
Self{ Self{
publish_new:crate::publish_new::Publisher::new(cookie_context.clone(),api.clone()), publish_new:crate::publish_new::Publisher::new(cookie_context.clone(),api.clone()),

View File

@ -6,7 +6,7 @@ pub enum PublishError{
Get(rbx_asset::cookie::GetError), Get(rbx_asset::cookie::GetError),
Json(serde_json::Error), Json(serde_json::Error),
Upload(rbx_asset::cookie::UploadError), Upload(rbx_asset::cookie::UploadError),
ApiActionSubmissionPublish(api::Error), ApiActionSubmissionPublish(submissions_api::Error),
} }
impl std::fmt::Display for PublishError{ impl std::fmt::Display for PublishError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
@ -17,12 +17,12 @@ impl std::error::Error for PublishError{}
pub struct Publisher{ pub struct Publisher{
roblox_cookie:rbx_asset::cookie::CookieContext, roblox_cookie:rbx_asset::cookie::CookieContext,
api:api::Context, api:submissions_api::Context,
} }
impl Publisher{ impl Publisher{
pub const fn new( pub const fn new(
roblox_cookie:rbx_asset::cookie::CookieContext, roblox_cookie:rbx_asset::cookie::CookieContext,
api:api::Context, api:submissions_api::Context,
)->Self{ )->Self{
Self{ Self{
roblox_cookie, roblox_cookie,
@ -54,7 +54,7 @@ impl Publisher{
// mark submission as published // mark submission as published
self.api.action_submission_publish( self.api.action_submission_publish(
api::SubmissionID(publish_info.SubmissionID) submissions_api::SubmissionID(publish_info.SubmissionID)
).await.map_err(PublishError::ApiActionSubmissionPublish)?; ).await.map_err(PublishError::ApiActionSubmissionPublish)?;
Ok(()) Ok(())

View File

@ -7,7 +7,7 @@ pub enum PublishError{
Json(serde_json::Error), Json(serde_json::Error),
Create(rbx_asset::cookie::CreateError), Create(rbx_asset::cookie::CreateError),
SystemTime(std::time::SystemTimeError), SystemTime(std::time::SystemTimeError),
ApiActionSubmissionPublish(api::Error), ApiActionSubmissionPublish(submissions_api::Error),
} }
impl std::fmt::Display for PublishError{ impl std::fmt::Display for PublishError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
@ -18,12 +18,12 @@ impl std::error::Error for PublishError{}
pub struct Publisher{ pub struct Publisher{
roblox_cookie:rbx_asset::cookie::CookieContext, roblox_cookie:rbx_asset::cookie::CookieContext,
api:api::Context, api:submissions_api::Context,
} }
impl Publisher{ impl Publisher{
pub const fn new( pub const fn new(
roblox_cookie:rbx_asset::cookie::CookieContext, roblox_cookie:rbx_asset::cookie::CookieContext,
api:api::Context, api:submissions_api::Context,
)->Self{ )->Self{
Self{ Self{
roblox_cookie, roblox_cookie,
@ -52,7 +52,7 @@ impl Publisher{
// mark submission as published // mark submission as published
self.api.action_submission_publish( self.api.action_submission_publish(
api::SubmissionID(publish_info.SubmissionID) submissions_api::SubmissionID(publish_info.SubmissionID)
).await.map_err(PublishError::ApiActionSubmissionPublish)?; ).await.map_err(PublishError::ApiActionSubmissionPublish)?;
Ok(()) Ok(())

View File

@ -20,10 +20,10 @@ pub enum ValidateError{
Get(rbx_asset::cookie::GetError), Get(rbx_asset::cookie::GetError),
Json(serde_json::Error), Json(serde_json::Error),
ReadDom(ReadDomError), ReadDom(ReadDomError),
ApiGetScriptPolicy(api::Error), ApiGetScriptPolicy(submissions_api::Error),
ApiGetScript(api::Error), ApiGetScript(submissions_api::Error),
ApiUpdateSubmissionModel(api::Error), ApiUpdateSubmissionModel(submissions_api::Error),
ApiActionSubmissionValidate(api::Error), ApiActionSubmissionValidate(submissions_api::Error),
WriteDom(rbx_binary::EncodeError), WriteDom(rbx_binary::EncodeError),
Upload(rbx_asset::cookie::UploadError), Upload(rbx_asset::cookie::UploadError),
Create(rbx_asset::cookie::CreateError), Create(rbx_asset::cookie::CreateError),
@ -37,13 +37,13 @@ impl std::error::Error for ValidateError{}
pub struct Validator{ pub struct Validator{
roblox_cookie:rbx_asset::cookie::CookieContext, roblox_cookie:rbx_asset::cookie::CookieContext,
api:api::Context, api:submissions_api::Context,
} }
impl Validator{ impl Validator{
pub const fn new( pub const fn new(
roblox_cookie:rbx_asset::cookie::CookieContext, roblox_cookie:rbx_asset::cookie::CookieContext,
api:api::Context, api:submissions_api::Context,
)->Self{ )->Self{
Self{ Self{
roblox_cookie, roblox_cookie,
@ -86,18 +86,18 @@ impl Validator{
let hash=std::hash::Hasher::finish(&hasher); let hash=std::hash::Hasher::finish(&hasher);
// fetch the script policy // fetch the script policy
let script_policy=self.api.get_script_policy_from_hash(api::ScriptPolicyHashRequest{ let script_policy=self.api.get_script_policy_from_hash(submissions_api::ScriptPolicyHashRequest{
hash:format!("{:x}",hash), hash:format!("{:x}",hash),
}).await.map_err(ValidateError::ApiGetScriptPolicy)?; }).await.map_err(ValidateError::ApiGetScriptPolicy)?;
// write the policy to the script_map, fetching the replacement code if necessary // write the policy to the script_map, fetching the replacement code if necessary
*replacement=match script_policy.Policy{ *replacement=match script_policy.Policy{
api::Policy::None=>Policy::None, submissions_api::Policy::None=>Policy::None,
api::Policy::Allowed=>Policy::Allowed, submissions_api::Policy::Allowed=>Policy::Allowed,
api::Policy::Blocked=>Policy::Blocked, submissions_api::Policy::Blocked=>Policy::Blocked,
api::Policy::Delete=>Policy::Delete, submissions_api::Policy::Delete=>Policy::Delete,
api::Policy::Replace=>{ submissions_api::Policy::Replace=>{
let script=self.api.get_script(api::GetScriptRequest{ let script=self.api.get_script(submissions_api::GetScriptRequest{
ScriptID:script_policy.ToScriptID, ScriptID:script_policy.ToScriptID,
}).await.map_err(ValidateError::ApiGetScript)?; }).await.map_err(ValidateError::ApiGetScript)?;
Policy::Replace(script.Source) Policy::Replace(script.Source)
@ -166,7 +166,7 @@ impl Validator{
}; };
// update the submission to use the validated model // update the submission to use the validated model
self.api.update_submission_model(api::UpdateSubmissionModelRequest{ self.api.update_submission_model(submissions_api::UpdateSubmissionModelRequest{
ID:validate_info.SubmissionID, ID:validate_info.SubmissionID,
ModelID:model_id, ModelID:model_id,
ModelVersion:1, //TODO ModelVersion:1, //TODO
@ -175,7 +175,7 @@ impl Validator{
// update the submission model status to validated // update the submission model status to validated
self.api.action_submission_validate( self.api.action_submission_validate(
api::SubmissionID(validate_info.SubmissionID) submissions_api::SubmissionID(validate_info.SubmissionID)
).await.map_err(ValidateError::ApiActionSubmissionValidate)?; ).await.map_err(ValidateError::ApiActionSubmissionValidate)?;
Ok(()) Ok(())