Skip to content

Commit

Permalink
Converted to Actix, async/await rework, working ArangoDB connection, …
Browse files Browse the repository at this point in the history
…auth rework, working ms refresh, lot of fixes
  • Loading branch information
Litarvan committed Feb 8, 2020
1 parent cf09417 commit f087aac
Show file tree
Hide file tree
Showing 30 changed files with 5,011 additions and 1,343 deletions.
10 changes: 0 additions & 10 deletions .env.example

This file was deleted.

9 changes: 4 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/target
**/*.rs.bk
Cargo.lock
/.idea
.env
.idea/
target/
epilyon.toml
*.iml
2,304 changes: 2,304 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

29 changes: 16 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ authors = ["Adrien Navratil <[email protected]>"]
edition = "2018"

[dependencies]
rocket = "0.4.2"
rocket_contrib = "0.4.2"
serde = "1.0.101"
serde_derive = "1.0.101"
serde_json = "1.0.41"
chrono = { version = "0.4", features = ["serde"] }
time = "0.1.42"
uuid = { version = "0.7.4", features = ["v4"] }
dotenv = "0.14.1"
reqwest = "0.9.22"
log = "0.4"
pretty_env_logger = "0.3"
jsonwebtoken = "5.0.1"
actix-web = "2.0.0"
actix-rt = "1.0.0"
log = "0.4.8"
pretty_env_logger = "0.3.1"
serde = "1.0.104"
serde_derive = "1.0.104"
serde_json = "1.0.44"
toml = "0.5.5"
reqwest = { version = "0.10.1", features = ["json"] }
lopdf = "0.23.0"
chrono = { version = "0.4.10", features = ["serde"] }
time = "0.1.42"
lazy_static = "1.4.0"
uuid = { version = "0.8.1", features = ["v4"] }
failure = "0.1.6"
futures = "0.3.1"
base64 = "0.11.0"
actix = "0.9.0"
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Epilyon server

Backend of the Epilyon app -- Keeping EPITA students organized
117 changes: 117 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Epilyon, keeping EPITA students organized
* Copyright (C) 2019-2020 Adrien 'Litarvan' Navratil
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use std::fs;
use std::path::Path;
use std::process::exit;

use log::{info, warn, error};
use lazy_static::lazy_static;
use serde_derive::{Serialize, Deserialize};

lazy_static! {
pub static ref CONFIG: EpiConfig = load();
}

#[derive(Serialize, Deserialize)]
pub struct EpiConfig {
pub address: String,
pub port: u16,

pub db_host: String,
pub db_port: u16,
pub db_user: String,
pub db_password: String,
pub db_database: String,

pub cri_url: String,
pub cri_accessor_username: String,
pub cri_accessor_password: String,
pub cri_promos: Vec<String>,

pub ms_tenant_url: String,
pub ms_client_id: String,
pub ms_scopes: Vec<String>,
pub ms_redirect_uri: String,
pub ms_secret: String
}

fn default() -> EpiConfig {
EpiConfig {
address: "localhost".to_string(),
port: 7899,

db_host: "localhost".to_string(),
db_port: 8529,
db_user: "epilyon".to_string(),
db_password: "".to_string(),
db_database: "epilyon".to_string(),

cri_url: "https://cri.epita.fr".to_string(),
cri_accessor_username: "firstname.lastname".to_string(),
cri_accessor_password: "password".to_string(),
cri_promos: vec!["2024".to_string(), "2023".to_string()],

ms_tenant_url: "https://login.microsoftonline.com/your_tenant_url".to_string(),
ms_client_id: "your_client_id".to_string(),
ms_scopes: vec!["openid".to_string(), "offline_access".to_string(), "profile".to_string(), "mail.read".to_string()],
ms_redirect_uri: "http://localhost:7899/auth/redirect".to_string(),
ms_secret: "your_secret_key".to_string()
}
}

fn load() -> EpiConfig {
let config_path = match std::env::var("EPILYON_CONFIG") {
Ok(c) => c,
Err(_) => "./epilyon.toml".to_string()
};

if !Path::new(&config_path).exists() {
warn!("Configuration file at '{}' does not exist, creating a default one", config_path);

let config = default();
match toml::to_string(&config) {
Ok(str) => match fs::write(&config_path, str) {
Ok(_) => {
warn!("Fill it before restarting the server");
exit(0);
},
Err(e) => error!("Failed writing default config at '{}', please check if the parent folder exists \
and if the program has the permission to write in there: {}", config_path, e)
},
Err(e) => error!("Failed serializing default config, this is very bad, please contact the devs: {}", e)
}

exit(1);
}

info!("Reading config from '{}'", config_path);

match fs::read_to_string(config_path) {
Ok(s) => match toml::from_str::<EpiConfig>(&s) {
Ok(c) => c,
Err(e) => {
error!("Error while deserializing the config file, there is probably a syntax error in it: {}", e);
exit(1);
}
},
Err(e) => {
error!("Error while reading the config file, the program may not have the permissions to read it: {}", e);
exit(1);
}
}
}
Loading

0 comments on commit f087aac

Please sign in to comment.