From 893bcecc9e3ab37c13d7054b56142c8eb5aaaa0b Mon Sep 17 00:00:00 2001 From: red binder Date: Mon, 27 Apr 2026 18:26:24 +0200 Subject: [PATCH] Remove gRPC RNEX is already in a working state --- .env.example | 3 -- .gitmodules | 3 -- build.rs | 11 ----- grpc-protobufs | 1 - src/grpc/mod.rs | 105 ------------------------------------------------ src/main.rs | 35 ---------------- 6 files changed, 158 deletions(-) delete mode 100644 .gitmodules delete mode 100644 build.rs delete mode 160000 grpc-protobufs delete mode 100644 src/grpc/mod.rs diff --git a/.env.example b/.env.example index 3fb0605..a045f44 100644 --- a/.env.example +++ b/.env.example @@ -19,6 +19,3 @@ S3_BUCKET=account-rs # Make sure to put a secure AES key here as this encrypts all tokens. ACCOUNT_AES_KEY=abcdef0123456789abcdef0123456789 -# You'll only be using gRPC if you're using Pretendo code but it's still recommended to set something secure here. -GRPC_PASSWORD=123456 - diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 64cd88d..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "grpc-protobufs"] - path = grpc-protobufs - url = https://github.com/PretendoNetwork/grpc-protobufs.git diff --git a/build.rs b/build.rs deleted file mode 100644 index f7a79e0..0000000 --- a/build.rs +++ /dev/null @@ -1,11 +0,0 @@ - -fn main(){ - tonic_build::configure() - .build_server(true) - .build_client(false) - .compile_protos( - &["grpc-protobufs/account/account_service.proto"], - &["grpc-protobufs/account"] - ) - .unwrap(); -} \ No newline at end of file diff --git a/grpc-protobufs b/grpc-protobufs deleted file mode 160000 index 4101111..0000000 --- a/grpc-protobufs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 410111190ec9f540d60108b70d55a437a6caf68e diff --git a/src/grpc/mod.rs b/src/grpc/mod.rs deleted file mode 100644 index 992fcb9..0000000 --- a/src/grpc/mod.rs +++ /dev/null @@ -1,105 +0,0 @@ -use crate::Pool; -use crate::grpc::grpc::{ - ExchangeTokenForUserDataRequest, GetNexDataRequest, GetNexDataResponse, GetNexPasswordRequest, - GetNexPasswordResponse, GetUserDataRequest, GetUserDataResponse, UpdatePnidPermissionsRequest, -}; -use once_cell::sync::Lazy; -use std::env; -use tonic::metadata::MetadataMap; -use tonic::{Request, Response, Status, async_trait}; - -/// This module is a legacy module meant for interacting with existing pretendo -/// servers. This will inevitably be removed completely as this is only meant as -/// a stopgap until RNEX is in a fully functional state. - -pub mod grpc { - tonic::include_proto!("account"); -} - -static GRPC_PASSWORD: Lazy> = Lazy::new(|| { - env::var("GRPC_PASSWORD") - .expect("GRPC_PASSWORD not specified") - .into_boxed_str() -}); - -fn verify_grpc_key(meta: &MetadataMap) -> Result<(), Status> { - // req.metadata_mut().insert("x-api-key", API_KEY.clone()); - - let key = meta - .get("x-api-key") - .ok_or(Status::permission_denied("api key missing"))?; - - if key.as_bytes() != GRPC_PASSWORD.as_bytes() { - return Err(Status::permission_denied("GO AWAY")); - } - - Ok(()) -} - -pub struct AccountService(pub Pool); - -#[async_trait] -impl grpc::account_server::Account for AccountService { - async fn exchange_token_for_user_data( - &self, - request: Request, - ) -> Result, Status> { - verify_grpc_key(request.metadata())?; - - Err(Status::unimplemented( - "grpc tecnically isnt supported by account-rs as such no full support is guaranteed(you called a stubbed function)", - )) - } - async fn get_nex_data( - &self, - request: Request, - ) -> Result, Status> { - verify_grpc_key(request.metadata())?; - - Err(Status::unimplemented( - "grpc tecnically isnt supported by account-rs as such no full support is guaranteed(you called a stubbed function)", - )) - } - async fn get_nex_password( - &self, - request: Request, - ) -> Result, Status> { - verify_grpc_key(request.metadata())?; - - let data = request.get_ref(); - - let password = sqlx::query!( - "select nex_password from users where pid = $1", - data.pid as i32 - ) - .fetch_one(&self.0) - .await - .map_err(|_| Status::invalid_argument("No NEX account found"))? - .nex_password; - - // let password_padded = format!("{:a>16}", password); - - Ok(Response::new(GetNexPasswordResponse { password })) - } - async fn update_pnid_permissions( - &self, - request: Request, - ) -> Result, Status> { - verify_grpc_key(request.metadata())?; - - Err(Status::unimplemented( - "grpc tecnically isnt supported by account-rs as such no full support is guaranteed(you called a stubbed function)", - )) - } - - async fn get_user_data( - &self, - request: Request, - ) -> Result, Status> { - verify_grpc_key(request.metadata())?; - - Err(Status::unimplemented( - "grpc tecnically isnt supported by account-rs as such no full support is guaranteed(you called a stubbed function)", - )) - } -} diff --git a/src/main.rs b/src/main.rs index c8e5d99..e645798 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,8 +20,6 @@ mod account; mod error; mod dsresponse; mod data_wrapper; -// #[deprecated] -mod grpc; mod graphql; mod email; mod mii_util; @@ -29,37 +27,6 @@ mod json_api; type Pool = sqlx::Pool; -async fn start_grpc(){ - let act_database_url = env::var("DATABASE_URL").expect("account database url is not set"); - - let pool = PgPoolOptions::new() - .max_connections(5) - .connect(&act_database_url) - .await - .expect("unable to create pool"); - - let grpc_instance = grpc::AccountService(pool); - - let addr: SocketAddr = - SocketAddr::from(( - env::var("ROCKET_ADDRESS").ok() - .map(|v| v.parse().expect("unable to read address")) - .unwrap_or(IpAddr::V4(Ipv4Addr::LOCALHOST)), - 7071 - ) - ); - - - - tokio::spawn(async move{ - Server::builder() - .add_service(grpc::grpc::account_server::AccountServer::new(grpc_instance)) - .serve(addr) - .await - .expect("unable to start grpc server"); - }); - -} #[catch(404)] fn not_found(_req: &Request) -> (Status, (ContentType, RawXml<&'static str>)) { @@ -85,8 +52,6 @@ fn not_found(_req: &Request) -> (Status, (ContentType, RawXml<&'static str>)) { async fn launch() -> _ { dotenv().ok(); - start_grpc().await; - let act_database_url = env::var("DATABASE_URL").expect("account database url is not set"); let pool = PgPoolOptions::new()