Skip to content

Commit

Permalink
move to env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed Nov 9, 2024
1 parent fa7b7b5 commit bfed6a4
Show file tree
Hide file tree
Showing 8 changed files with 722 additions and 492 deletions.
1,144 changes: 687 additions & 457 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"

[dependencies]
anyhow = "1.0"
mongodb = "3.0"
mongodb = "3.1"
futures = "0.3"
chrono = "0.4"
influxdb2 = "0.5"
Expand All @@ -20,10 +20,11 @@ serde_derive = "1.0"
questdb-rs = "4.0"
sqlx = { version = "0.8", features = ["runtime-tokio", "postgres", "time"] }
time = { version = "0.3", features = ["macros", "rand"] }
regex = "1.10"
regex = "1.11"
dotenvy = "0.15"

[dependencies.clickhouse]
version = "0.12"
version = "0.13"
features = ["time"]

[dependencies.serde]
Expand All @@ -35,11 +36,11 @@ version = "0.3"
features = ["tls"]

[dependencies.bson]
version = "2.9"
version = "2.13"
features = ["chrono-0_4"]

[dependencies.tokio]
version = "1.36"
version = "1.41"
features = ["full"]

[dependencies.bf_sparta]
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

FROM rust:1.80 as builder
FROM rust:1.82 as builder
WORKDIR /usr/src/myapp
COPY . .
ARG github_token
Expand Down
11 changes: 0 additions & 11 deletions debug.log

This file was deleted.

2 changes: 1 addition & 1 deletion src/connectors/clickhouse_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// platform: &str,
// server_infos: Vec<server_info::ServerInfo>,
// ) -> anyhow::Result<()> {
// let client = Client::default().with_url("http://100.76.59.110:8123");
// let client = Client::default().with_url("");
// let mut insert = client.insert("game_servers")?;
// for server_info in server_infos {
// if !server_info.name.is_empty() {
Expand Down
9 changes: 6 additions & 3 deletions src/connectors/mongo.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::env;

use crate::structs::old_games;
use bf_sparta::cookie::Cookie;
use bson::Document;
Expand Down Expand Up @@ -57,10 +59,11 @@ pub struct ManagerInfo {

impl MongoClient {
pub async fn connect() -> Result<Self> {
// Possible env
const MONGO_URL: &str = "mongodb://zjobse:[email protected]:27017";
// Try connect to mongo client
let client = Client::with_uri_str(MONGO_URL).await?;
let client = Client::with_uri_str(
env::var("MONGO_DETAILS_STRING").expect("MONGO_DETAILS_STRING wasn't set"),
)
.await?;

// Server manager DB
let db = client.database("serverManager");
Expand Down
8 changes: 4 additions & 4 deletions src/connectors/quest_db.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// use crate::structs::server_info;
// use questdb::ingress::{Buffer, Sender};

// let mut sender = SenderBuilder::new("167.86.108.125", 9009).connect()?;
// let mut sender = SenderBuilder::new("", 9009).connect()?;

// pub fn push_server(
// frontend_game_name: &str,
// region: &str,
// platform: &str,
// server_infos: Vec<server_info::ServerInfo>,
// ) -> anyhow::Result<()> {
// let mut quest_sender = Sender::from_conf("http::addr=167.86.108.125:9009;")?;
// let mut quest_sender = Sender::from_conf("http::addr=:9009;")?;
// for server_info in server_infos {
// if !server_info.name.is_empty() {
// let mut buffer = &mut Buffer::new();
Expand Down Expand Up @@ -53,7 +53,7 @@
// }

// pub fn push_totals(global_result: &results::RegionResult) -> anyhow::Result<()> {
// let mut quest_sender = SenderBuilder::new("167.86.108.125", 9009).connect()?;
// let mut quest_sender = SenderBuilder::new("", 9009).connect()?;
// let buffer = &mut Buffer::new();
// buffer
// .table("Game info")?
Expand All @@ -72,7 +72,7 @@
// platform: &str,
// platform_result: &HashMap<String, results::RegionResult>
// ) -> anyhow::Result<()> {
// let mut quest_sender = SenderBuilder::new("167.86.108.125", 9009).connect()?;
// let mut quest_sender = SenderBuilder::new("", 9009).connect()?;
// for (region, region_result) in platform_result {
// let buffer = &mut Buffer::new();
// if vec!["bf1", "bfv", "bf4", "battlebit"].contains(&frontend_game_name) {
Expand Down
27 changes: 17 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use influxdb2::Client;
use sqlx::postgres::PgPool;
use std::{
collections::HashMap,
env,
ops::Add,
sync::{atomic, Arc},
time::Duration,
Expand All @@ -20,6 +21,11 @@ use warp::Filter;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
match dotenvy::dotenv() {
Ok(_) => {}
Err(_) => log::info!(".env not found, using env variables..."),
};

let mins_between_runs = 5;
let hours_between_detailed_runs = 12;
let last_update = Arc::new(atomic::AtomicI64::new(chrono::Utc::now().timestamp() / 60));
Expand Down Expand Up @@ -50,17 +56,17 @@ async fn main() -> anyhow::Result<()> {
});

let influx_client = Client::new(
"http://167.235.137.239:8086/",
"Gametools",
"B_wltARyGe85ohqEYFH0xX9lTQAtw4DdQf0tcee8IcptUInOpZx3oVmnjBSRSDHKV1nEl63xQS8sqCQO7xbETg==",
env::var("INFLUX_URL").expect("INFLUX_URL wasn't set"),
env::var("INFLUX_USER").expect("INFLUX_USER wasn't set"),
env::var("INFLUX_PASS").expect("INFLUX_PASS wasn't set"),
);
let mut mongo_client = MongoClient::connect().await?;

let pool =
PgPool::connect("postgres://gametools:[email protected]:5432/tsdb")
.await?;
let pool = PgPool::connect(&env::var("DATABASE_URL").expect("DATABASE_URL wasn't set")).await?;

let api_main_account = env::var("API_MAIN_ACCOUNT").expect("API_MAIN_ACCOUNT wasn't set");

let mut cookie = match mongo_client.get_cookies("[email protected]").await {
let mut cookie = match mongo_client.get_cookies(&api_main_account).await {
Ok(result) => result,
Err(_) => bf_sparta::cookie::Cookie {
sid: "".to_string(),
Expand All @@ -73,16 +79,17 @@ async fn main() -> anyhow::Result<()> {
Err(e) => {
log::warn!("Cookie failed, {} - requesting new cookie", e);
let cookie_auth = cookie_request::request_cookie(cookie_request::Login {
email: "[email protected]".to_string(),
pass: "bqgPAHJDphaTpPcbRk8jfHhbCecnTnRN".to_string(),
email: api_main_account.clone(),
pass: env::var("API_MAIN_ACCOUNT_PASSWORD")
.expect("API_MAIN_ACCOUNT_PASSWORD wasn't set"),
})
.await?;
let cookie = bf_sparta::cookie::Cookie {
sid: cookie_auth.sid,
remid: cookie_auth.remid,
};
mongo_client
.push_new_cookies("[email protected]", &cookie)
.push_new_cookies(&api_main_account, &cookie)
.await?;
cookie
}
Expand Down

0 comments on commit bfed6a4

Please sign in to comment.