-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/00-team/simurgh
- Loading branch information
Showing
4 changed files
with
30 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
DATABASE_URL="sqlite://main.db" | ||
gmail="" | ||
gmail_pass="" | ||
discord_webhook="" | ||
HEIMDALL_TOKEN="heimdall.00-team.org site token" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,41 @@ | ||
use std::{env, sync::OnceLock}; | ||
|
||
use lettre::{message::Mailbox, SmtpTransport}; | ||
use std::sync::OnceLock; | ||
|
||
#[derive(Debug)] | ||
pub struct Config { | ||
pub mail_from: Mailbox, | ||
pub mail_server: SmtpTransport, | ||
pub discord_webhook: String, | ||
pub heimdall_token: String, | ||
} | ||
|
||
impl Config { | ||
pub const RECORD_DIR: &'static str = "./record/"; | ||
pub const TOKEN_ABC: &'static [u8] = b"!@#$%^&*_+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*_+"; | ||
pub const API_KEY_ABC: &'static [u8] = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; | ||
pub const API_KEY_ABC: &'static [u8] = | ||
b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; | ||
pub const CODE_ABC: &'static [u8] = b"0123456789"; | ||
pub const SLUG_ABC: &'static [u8] = | ||
b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-"; | ||
} | ||
|
||
macro_rules! evar { | ||
($name:literal) => { | ||
std::env::var($name).expect(concat!($name, " was not found in env")) | ||
}; | ||
} | ||
|
||
pub fn config() -> &'static Config { | ||
static STATE: OnceLock<Config> = OnceLock::new(); | ||
let mail = env::var("GMAIL").expect("no GMAIL in env"); | ||
let pass = env::var("GMAIL_PASS").expect("no GMAIL_PASS in env"); | ||
let mail = evar!("GMAIL"); | ||
let mail_server = SmtpTransport::relay("smtp.gmail.com") | ||
.expect("smpt relay failed") | ||
.port(465) | ||
.credentials((&mail, &pass).into()) | ||
.credentials((&mail, &evar!("GMAIL_PASS")).into()) | ||
.build(); | ||
|
||
STATE.get_or_init(|| Config { | ||
mail_from: mail.parse().expect("could not parse GMAIL"), | ||
mail_server, | ||
discord_webhook: env::var("DISCORD_WEBHOOK").unwrap(), | ||
heimdall_token: evar!("HEIMDALL_TOKEN"), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters