RNEX is already in a working state
This commit is contained in:
parent
c0fdc1445d
commit
893bcecc9e
6 changed files with 0 additions and 158 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
3
.gitmodules
vendored
3
.gitmodules
vendored
|
|
@ -1,3 +0,0 @@
|
|||
[submodule "grpc-protobufs"]
|
||||
path = grpc-protobufs
|
||||
url = https://github.com/PretendoNetwork/grpc-protobufs.git
|
||||
11
build.rs
11
build.rs
|
|
@ -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();
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 410111190ec9f540d60108b70d55a437a6caf68e
|
||||
105
src/grpc/mod.rs
105
src/grpc/mod.rs
|
|
@ -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<Box<str>> = 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<ExchangeTokenForUserDataRequest>,
|
||||
) -> Result<Response<GetUserDataResponse>, 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<GetNexDataRequest>,
|
||||
) -> Result<Response<GetNexDataResponse>, 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<GetNexPasswordRequest>,
|
||||
) -> Result<Response<GetNexPasswordResponse>, 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<UpdatePnidPermissionsRequest>,
|
||||
) -> Result<Response<()>, 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<GetUserDataRequest>,
|
||||
) -> Result<Response<GetUserDataResponse>, 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)",
|
||||
))
|
||||
}
|
||||
}
|
||||
35
src/main.rs
35
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<Postgres>;
|
||||
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue