diff --git a/Cargo.toml b/Cargo.toml index c4e4452b23348e2d99a78e423b4ce626d37e214e..376d567705e86e380dea1debd24f7d08bdf0cf74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ name = "bitwarden_rs" version = "1.0.0" authors = ["Daniel GarcÃa <dani-garcia@users.noreply.github.com>"] +edition = "2018" [features] enable_syslog = ["syslog", "fern/syslog-4"] diff --git a/src/api/core/accounts.rs b/src/api/core/accounts.rs index ce8572b7da8e2e2264cd9b4e9ec4602b051623ef..fbe00796ef10aa5191fe5888e24a571c97246e73 100644 --- a/src/api/core/accounts.rs +++ b/src/api/core/accounts.rs @@ -1,13 +1,13 @@ use rocket_contrib::json::Json; -use db::models::*; -use db::DbConn; +use crate::db::models::*; +use crate::db::DbConn; -use api::{EmptyResult, JsonResult, JsonUpcase, NumberOrString, PasswordData, UpdateType, WebSocketUsers}; -use auth::Headers; -use mail; +use crate::api::{EmptyResult, JsonResult, JsonUpcase, NumberOrString, PasswordData, UpdateType, WebSocketUsers}; +use crate::auth::Headers; +use crate::mail; -use CONFIG; +use crate::CONFIG; use rocket::{Route, State}; diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index 41e704dc1f5a0a2752b8c5e59d97975dc12f3b1a..e5a7c59e74d3d6b92987d64ad5bd26496541916a 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -12,15 +12,15 @@ use multipart::server::{Multipart, SaveResult}; use data_encoding::HEXLOWER; -use db::models::*; -use db::DbConn; +use crate::db::models::*; +use crate::db::DbConn; -use crypto; +use crate::crypto; -use api::{self, EmptyResult, JsonResult, JsonUpcase, PasswordData, UpdateType, WebSocketUsers}; -use auth::Headers; +use crate::api::{self, EmptyResult, JsonResult, JsonUpcase, PasswordData, UpdateType, WebSocketUsers}; +use crate::auth::Headers; -use CONFIG; +use crate::CONFIG; pub fn routes() -> Vec<Route> { routes![ diff --git a/src/api/core/folders.rs b/src/api/core/folders.rs index e60c281ffa11d6b51e3343b1d0dfa705309e9bd8..4c1cdff689f0ee0a0bcc2d65067ba5f3fb1547e5 100644 --- a/src/api/core/folders.rs +++ b/src/api/core/folders.rs @@ -2,11 +2,11 @@ use rocket::State; use rocket_contrib::json::Json; use serde_json::Value; -use db::DbConn; -use db::models::*; +use crate::db::DbConn; +use crate::db::models::*; -use api::{JsonResult, EmptyResult, JsonUpcase, WebSocketUsers, UpdateType}; -use auth::Headers; +use crate::api::{JsonResult, EmptyResult, JsonUpcase, WebSocketUsers, UpdateType}; +use crate::auth::Headers; use rocket::Route; diff --git a/src/api/core/mod.rs b/src/api/core/mod.rs index d4b4d2e7394044416d2356b0c626e9ab2f0111bb..46ee76e2ec21d41a5144b90b141c61e14292c093 100644 --- a/src/api/core/mod.rs +++ b/src/api/core/mod.rs @@ -34,11 +34,11 @@ use rocket::Route; use rocket_contrib::json::Json; use serde_json::Value; -use db::DbConn; -use db::models::*; +use crate::db::DbConn; +use crate::db::models::*; -use api::{JsonResult, EmptyResult, JsonUpcase}; -use auth::Headers; +use crate::api::{JsonResult, EmptyResult, JsonUpcase}; +use crate::auth::Headers; #[put("/devices/identifier/<uuid>/clear-token")] fn clear_device_token(uuid: String, headers: Headers, conn: DbConn) -> EmptyResult { @@ -72,7 +72,7 @@ fn put_device_token(uuid: String, data: JsonUpcase<Value>, headers: Headers, con // This should save the push token, but we don't have push functionality - use util::format_date; + use crate::util::format_date; Ok(Json(json!({ "Id": device.uuid, diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index f38876dd1377c0f3f1baa7a47036809b5e47fbc8..0350b2e140da0ab4b843b1f61eeedbf71141ef0c 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -3,12 +3,12 @@ use rocket::request::Form; use rocket_contrib::json::Json; use serde_json::Value; -use CONFIG; -use db::DbConn; -use db::models::*; +use crate::CONFIG; +use crate::db::DbConn; +use crate::db::models::*; -use api::{PasswordData, JsonResult, EmptyResult, NumberOrString, JsonUpcase, WebSocketUsers, UpdateType}; -use auth::{Headers, AdminHeaders, OwnerHeaders}; +use crate::api::{PasswordData, JsonResult, EmptyResult, NumberOrString, JsonUpcase, WebSocketUsers, UpdateType}; +use crate::auth::{Headers, AdminHeaders, OwnerHeaders}; use serde::{Deserialize, Deserializer}; diff --git a/src/api/core/two_factor.rs b/src/api/core/two_factor.rs index a236138457fdcfb8fe81924872ba90913311f8c9..d25a6b4215689e82426adba04b763101006c9a11 100644 --- a/src/api/core/two_factor.rs +++ b/src/api/core/two_factor.rs @@ -4,15 +4,15 @@ use serde_json; use serde_json::Value; -use db::{ +use crate::db::{ models::{TwoFactor, TwoFactorType, User}, DbConn, }; -use crypto; +use crate::crypto; -use api::{ApiResult, JsonResult, JsonUpcase, NumberOrString, PasswordData}; -use auth::Headers; +use crate::api::{ApiResult, JsonResult, JsonUpcase, NumberOrString, PasswordData}; +use crate::auth::Headers; use rocket::Route; @@ -74,7 +74,7 @@ struct RecoverTwoFactor { fn recover(data: JsonUpcase<RecoverTwoFactor>, conn: DbConn) -> JsonResult { let data: RecoverTwoFactor = data.into_inner().data; - use db::models::User; + use crate::db::models::User; // Get the user let mut user = match User::find_by_mail(&data.Email, &conn) { @@ -252,7 +252,7 @@ use u2f::messages::{RegisterResponse, SignResponse, U2fSignRequest}; use u2f::protocol::{Challenge, U2f}; use u2f::register::Registration; -use CONFIG; +use crate::CONFIG; const U2F_VERSION: &str = "U2F_V2"; diff --git a/src/api/icons.rs b/src/api/icons.rs index 585a2c2b1ce02d484e10978ea5443e8fc10b6fff..a3ff1d391ea4cb688f1f6d169f0628f61e378728 100644 --- a/src/api/icons.rs +++ b/src/api/icons.rs @@ -7,7 +7,7 @@ use rocket::http::ContentType; use reqwest; -use CONFIG; +use crate::CONFIG; pub fn routes() -> Vec<Route> { routes![icon] diff --git a/src/api/identity.rs b/src/api/identity.rs index 940fcbf9acbfb93e958f842ab8f84e743af2ad42..8236b1d7fa8f31f68157aa05c1f3722cf0e9739b 100644 --- a/src/api/identity.rs +++ b/src/api/identity.rs @@ -8,14 +8,14 @@ use serde_json::Value; use num_traits::FromPrimitive; -use db::models::*; -use db::DbConn; +use crate::db::models::*; +use crate::db::DbConn; -use util::{self, JsonMap}; +use crate::util::{self, JsonMap}; -use api::{ApiResult, EmptyResult, JsonResult}; +use crate::api::{ApiResult, EmptyResult, JsonResult}; -use CONFIG; +use crate::CONFIG; pub fn routes() -> Vec<Route> { routes![login] @@ -194,13 +194,13 @@ fn twofactor_auth( } Some(TwoFactorType::U2f) => { - use api::core::two_factor; + use crate::api::core::two_factor; two_factor::validate_u2f_login(user_uuid, &twofactor_code, conn)?; } Some(TwoFactorType::YubiKey) => { - use api::core::two_factor; + use crate::api::core::two_factor; two_factor::validate_yubikey_login(user_uuid, twofactor_code, conn)?; } @@ -217,7 +217,7 @@ fn twofactor_auth( } fn _json_err_twofactor(providers: &[i32], user_uuid: &str, conn: &DbConn) -> ApiResult<Value> { - use api::core::two_factor; + use crate::api::core::two_factor; let mut result = json!({ "error" : "invalid_grant", diff --git a/src/api/mod.rs b/src/api/mod.rs index 332b3cf0f11454142bdeff988c4906a2d14bf76d..9c8e49ebc45a5ff27e3d8cd03812f65c68301b78 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -20,7 +20,7 @@ type ApiResult<T> = Result<T, BadRequest<Json<Value>>>; type JsonResult = ApiResult<Json<Value>>; type EmptyResult = ApiResult<()>; -use util; +use crate::util; type JsonUpcase<T> = Json<util::UpCase<T>>; // Common structs representing JSON data received diff --git a/src/api/notifications.rs b/src/api/notifications.rs index df40cf894cf197b16f5b3f4974a05ffd22f35f55..6e4f216afe46b428030bd7b9e2b272125c9a13c4 100644 --- a/src/api/notifications.rs +++ b/src/api/notifications.rs @@ -2,11 +2,11 @@ use rocket::Route; use rocket_contrib::json::Json; use serde_json::Value as JsonValue; -use api::JsonResult; -use auth::Headers; -use db::DbConn; +use crate::api::JsonResult; +use crate::auth::Headers; +use crate::db::DbConn; -use CONFIG; +use crate::CONFIG; pub fn routes() -> Vec<Route> { routes![negotiate, websockets_err] @@ -19,7 +19,7 @@ fn websockets_err() -> JsonResult { #[post("/hub/negotiate")] fn negotiate(_headers: Headers, _conn: DbConn) -> JsonResult { - use crypto; + use crate::crypto; use data_encoding::BASE64URL; let conn_id = BASE64URL.encode(&crypto::get_random(vec![0u8; 16])); @@ -52,7 +52,7 @@ use chashmap::CHashMap; use chrono::NaiveDateTime; use serde_json::from_str; -use db::models::{Cipher, Folder, User}; +use crate::db::models::{Cipher, Folder, User}; use rmpv::Value; @@ -139,7 +139,7 @@ impl Handler for WSHandler { let _id = &query_split[1][3..]; // Validate the user - use auth; + use crate::auth; let claims = match auth::decode_jwt(access_token) { Ok(claims) => claims, Err(_) => { diff --git a/src/api/web.rs b/src/api/web.rs index 53b7d9a442d5052b066b15431f545490ebfdb487..8db632a906b677890357de19356f62caefdb8433 100644 --- a/src/api/web.rs +++ b/src/api/web.rs @@ -9,7 +9,7 @@ use rocket::Route; use rocket_contrib::json::Json; use serde_json::Value; -use CONFIG; +use crate::CONFIG; pub fn routes() -> Vec<Route> { if CONFIG.web_vault_enabled { @@ -74,7 +74,7 @@ fn attachments(uuid: String, file: PathBuf) -> io::Result<NamedFile> { #[get("/alive")] fn alive() -> Json<String> { - use util::format_date; + use crate::util::format_date; use chrono::Utc; Json(format_date(&Utc::now().naive_utc())) diff --git a/src/auth.rs b/src/auth.rs index 28f706d31ab29b6198e9aed05952f1fd97bf3745..6e85538125b7489de91f2ba4a644541c6015b14f 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -2,21 +2,21 @@ /// JWT Handling /// -use util::read_file; +use crate::util::read_file; use chrono::Duration; -use jwt; +use jsonwebtoken::{self, Algorithm, Header}; use serde::ser::Serialize; -use CONFIG; +use crate::CONFIG; -const JWT_ALGORITHM: jwt::Algorithm = jwt::Algorithm::RS256; +const JWT_ALGORITHM: Algorithm = Algorithm::RS256; lazy_static! { pub static ref DEFAULT_VALIDITY: Duration = Duration::hours(2); pub static ref JWT_ISSUER: String = CONFIG.domain.clone(); - static ref JWT_HEADER: jwt::Header = jwt::Header::new(JWT_ALGORITHM); + static ref JWT_HEADER: Header = Header::new(JWT_ALGORITHM); static ref PRIVATE_RSA_KEY: Vec<u8> = match read_file(&CONFIG.private_rsa_key) { Ok(key) => key, @@ -30,14 +30,14 @@ lazy_static! { } pub fn encode_jwt<T: Serialize>(claims: &T) -> String { - match jwt::encode(&JWT_HEADER, claims, &PRIVATE_RSA_KEY) { + match jsonwebtoken::encode(&JWT_HEADER, claims, &PRIVATE_RSA_KEY) { Ok(token) => token, Err(e) => panic!("Error encoding jwt {}", e) } } pub fn decode_jwt(token: &str) -> Result<JWTClaims, String> { - let validation = jwt::Validation { + let validation = jsonwebtoken::Validation { leeway: 30, // 30 seconds validate_exp: true, validate_iat: false, // IssuedAt is the same as NotBefore @@ -48,7 +48,7 @@ pub fn decode_jwt(token: &str) -> Result<JWTClaims, String> { algorithms: vec![JWT_ALGORITHM], }; - match jwt::decode(token, &PUBLIC_RSA_KEY, &validation) { + match jsonwebtoken::decode(token, &PUBLIC_RSA_KEY, &validation) { Ok(decoded) => Ok(decoded.claims), Err(msg) => { error!("Error validating jwt - {:#?}", msg); @@ -94,8 +94,8 @@ pub struct JWTClaims { use rocket::Outcome; use rocket::request::{self, Request, FromRequest}; -use db::DbConn; -use db::models::{User, Organization, UserOrganization, UserOrgType, UserOrgStatus, Device}; +use crate::db::DbConn; +use crate::db::models::{User, Organization, UserOrganization, UserOrgType, UserOrgStatus, Device}; pub struct Headers { pub host: String, diff --git a/src/db/mod.rs b/src/db/mod.rs index dff2b0cc3a82f4e097dcaaa4e5633e4dcc173bf6..e72dc771083051a1c4b91affdb3d41b63f6a2afb 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -9,7 +9,7 @@ use rocket::http::Status; use rocket::request::{self, FromRequest}; use rocket::{Outcome, Request, State}; -use CONFIG; +use crate::CONFIG; /// An alias to the database connection used type Connection = SqliteConnection; diff --git a/src/db/models/attachment.rs b/src/db/models/attachment.rs index 29c3f61b3703101ef6bcfbcd6ca944d52552b52d..5cec96c79fac1651e06c79bee6016e0fe1bc1e75 100644 --- a/src/db/models/attachment.rs +++ b/src/db/models/attachment.rs @@ -1,7 +1,7 @@ use serde_json::Value; use super::Cipher; -use CONFIG; +use crate::CONFIG; #[derive(Debug, Identifiable, Queryable, Insertable, Associations)] #[table_name = "attachments"] @@ -32,7 +32,7 @@ impl Attachment { } pub fn to_json(&self, host: &str) -> Value { - use util::get_display_size; + use crate::util::get_display_size; let web_path = format!("{}/attachments/{}/{}", host, self.cipher_uuid, self.id); let display_size = get_display_size(self.file_size); @@ -51,8 +51,8 @@ impl Attachment { use diesel; use diesel::prelude::*; -use db::DbConn; -use db::schema::attachments; +use crate::db::DbConn; +use crate::db::schema::attachments; /// Database methods impl Attachment { @@ -64,7 +64,7 @@ impl Attachment { } pub fn delete(self, conn: &DbConn) -> QueryResult<()> { - use util; + use crate::util; use std::{thread, time}; let mut retries = 10; diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs index 5a5ac05930a6ad271d172ab7719108bec218fdbf..8caa2e0274530f14ecfcac5383bff85727b91d92 100644 --- a/src/db/models/cipher.rs +++ b/src/db/models/cipher.rs @@ -63,14 +63,14 @@ impl Cipher { use diesel; use diesel::prelude::*; -use db::DbConn; -use db::schema::*; +use crate::db::DbConn; +use crate::db::schema::*; /// Database methods impl Cipher { pub fn to_json(&self, host: &str, user_uuid: &str, conn: &DbConn) -> Value { use serde_json; - use util::format_date; + use crate::util::format_date; use super::Attachment; let attachments = Attachment::find_by_cipher(&self.uuid, conn); diff --git a/src/db/models/collection.rs b/src/db/models/collection.rs index 0535cef4451ea42c6fd7d4ad63d75d743aeafded..5b5a40c68ad5e59151f54a5713c47764400b5686 100644 --- a/src/db/models/collection.rs +++ b/src/db/models/collection.rs @@ -37,8 +37,8 @@ impl Collection { use diesel; use diesel::prelude::*; -use db::DbConn; -use db::schema::*; +use crate::db::DbConn; +use crate::db::schema::*; /// Database methods impl Collection { diff --git a/src/db/models/device.rs b/src/db/models/device.rs index ca9983785ab83191665780218933903b8cd169d1..81c2d0f94e2af8585607d7397e8dfdb03dbd52aa 100644 --- a/src/db/models/device.rs +++ b/src/db/models/device.rs @@ -45,7 +45,7 @@ impl Device { pub fn refresh_twofactor_remember(&mut self) -> String { use data_encoding::BASE64; - use crypto; + use crate::crypto; let twofactor_remember = BASE64.encode(&crypto::get_random(vec![0u8; 180])); self.twofactor_remember = Some(twofactor_remember.clone()); @@ -62,7 +62,7 @@ impl Device { // If there is no refresh token, we create one if self.refresh_token.is_empty() { use data_encoding::BASE64URL; - use crypto; + use crate::crypto; self.refresh_token = BASE64URL.encode(&crypto::get_random_64()); } @@ -77,7 +77,7 @@ impl Device { // Create the JWT claims struct, to send to the client - use auth::{encode_jwt, JWTClaims, DEFAULT_VALIDITY, JWT_ISSUER}; + use crate::auth::{encode_jwt, JWTClaims, DEFAULT_VALIDITY, JWT_ISSUER}; let claims = JWTClaims { nbf: time_now.timestamp(), exp: (time_now + *DEFAULT_VALIDITY).timestamp(), @@ -106,8 +106,8 @@ impl Device { use diesel; use diesel::prelude::*; -use db::DbConn; -use db::schema::devices; +use crate::db::DbConn; +use crate::db::schema::devices; /// Database methods impl Device { diff --git a/src/db/models/folder.rs b/src/db/models/folder.rs index 5b52a557817a9a43ec87a9d2b3bde221b10c8e8e..9e38408699883f7af76e437a9ee3541278de04d9 100644 --- a/src/db/models/folder.rs +++ b/src/db/models/folder.rs @@ -43,7 +43,7 @@ impl Folder { } pub fn to_json(&self) -> Value { - use util::format_date; + use crate::util::format_date; json!({ "Id": self.uuid, @@ -65,8 +65,8 @@ impl FolderCipher { use diesel; use diesel::prelude::*; -use db::DbConn; -use db::schema::{folders, folders_ciphers}; +use crate::db::DbConn; +use crate::db::schema::{folders, folders_ciphers}; /// Database methods impl Folder { diff --git a/src/db/models/organization.rs b/src/db/models/organization.rs index d21fd39032c23e16cdf5a0a6581a3471a53f3851..bddb3dd7343a447a0ddd7c020cbcecde5fc8c009 100644 --- a/src/db/models/organization.rs +++ b/src/db/models/organization.rs @@ -236,8 +236,8 @@ impl UserOrganization { use diesel; use diesel::prelude::*; -use db::DbConn; -use db::schema::{organizations, users_organizations, users_collections, ciphers_collections}; +use crate::db::DbConn; +use crate::db::schema::{organizations, users_organizations, users_collections, ciphers_collections}; /// Database methods impl Organization { diff --git a/src/db/models/two_factor.rs b/src/db/models/two_factor.rs index b47a3a8112baab4a49cbfad7ff1f54ebaa056aa9..878dafdae9ab9d18266cd06d929c0b0ec3a05454 100644 --- a/src/db/models/two_factor.rs +++ b/src/db/models/two_factor.rs @@ -78,8 +78,8 @@ impl TwoFactor { use diesel; use diesel::prelude::*; -use db::DbConn; -use db::schema::twofactor; +use crate::db::DbConn; +use crate::db::schema::twofactor; /// Database methods impl TwoFactor { diff --git a/src/db/models/user.rs b/src/db/models/user.rs index 283ec3c92e91a857bf9ddcf986c3c514f3848e39..d830b601c7205267b6398a81de69fd1c72d491e9 100644 --- a/src/db/models/user.rs +++ b/src/db/models/user.rs @@ -3,8 +3,8 @@ use serde_json::Value; use uuid::Uuid; -use crypto; -use CONFIG; +use crate::crypto; +use crate::CONFIG; #[derive(Debug, Identifiable, Queryable, Insertable)] @@ -113,8 +113,8 @@ impl User { use diesel; use diesel::prelude::*; -use db::DbConn; -use db::schema::{users, invitations}; +use crate::db::DbConn; +use crate::db::schema::{users, invitations}; use super::{Cipher, Folder, Device, UserOrganization, UserOrgType}; /// Database methods diff --git a/src/mail.rs b/src/mail.rs index cb50e3640b1ed6f86cfc9f63d597bd71c73ac913..8a64c24b84bec6a2bb3c3c2d59994a0bc1ad70df 100644 --- a/src/mail.rs +++ b/src/mail.rs @@ -4,7 +4,7 @@ use lettre::smtp::ConnectionReuseParameters; use lettre::smtp::authentication::Credentials; use lettre_email::EmailBuilder; -use MailConfig; +use crate::MailConfig; fn mailer(config: &MailConfig) -> SmtpTransport { let client_security = if config.smtp_ssl { diff --git a/src/main.rs b/src/main.rs index 3731f61e3186185b83dc09a2ccf0149ebbb0c993..0566d6ba8a3efce77298ab8129655dd55e8adb19 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,47 +1,15 @@ -#![feature(proc_macro_hygiene, decl_macro, custom_derive, vec_remove_item, try_trait, nll)] -#![recursion_limit="128"] +#![feature(proc_macro_hygiene, decl_macro, vec_remove_item, try_trait)] +#![recursion_limit = "128"] #![allow(proc_macro_derive_resolution_fallback)] // TODO: Remove this when diesel update fixes warnings -#[macro_use] -extern crate rocket; -extern crate rocket_contrib; -extern crate reqwest; -extern crate multipart; -extern crate ws; -extern crate rmpv; -extern crate chashmap; -extern crate serde; -#[macro_use] -extern crate serde_derive; -#[macro_use] -extern crate serde_json; -#[macro_use] -extern crate log; -extern crate fern; -#[cfg(feature = "enable_syslog")] -extern crate syslog; -#[macro_use] -extern crate diesel; -#[macro_use] -extern crate diesel_migrations; -extern crate ring; -extern crate uuid; -extern crate chrono; -extern crate oath; -extern crate data_encoding; -extern crate jsonwebtoken as jwt; -extern crate u2f; -extern crate yubico; -extern crate dotenv; -#[macro_use] -extern crate lazy_static; -#[macro_use] -extern crate num_derive; -extern crate num_traits; -extern crate lettre; -extern crate lettre_email; -extern crate native_tls; -extern crate byteorder; +#[macro_use] extern crate rocket; +#[macro_use] extern crate serde_derive; +#[macro_use] extern crate serde_json; +#[macro_use] extern crate log; +#[macro_use] extern crate diesel; +#[macro_use] extern crate diesel_migrations; +#[macro_use] extern crate lazy_static; +#[macro_use] extern crate num_derive; use std::{path::Path, process::{exit, Command}}; use rocket::Rocket; @@ -75,7 +43,7 @@ mod migrations { pub fn run_migrations() { // Make sure the database is up to date (create if it doesn't exist, or run the migrations) - let connection = ::db::get_connection().expect("Can't conect to DB"); + let connection = crate::db::get_connection().expect("Can't conect to DB"); use std::io::stdout; embedded_migrations::run_with_output(&connection, &mut stdout()).expect("Can't run migrations"); @@ -234,7 +202,7 @@ pub struct MailConfig { impl MailConfig { fn load() -> Option<Self> { - use util::{get_env, get_env_or}; + use crate::util::{get_env, get_env_or}; // When SMTP_HOST is absent, we assume the user does not want to enable it. let smtp_host = match get_env("SMTP_HOST") { @@ -316,7 +284,7 @@ pub struct Config { impl Config { fn load() -> Self { - use util::{get_env, get_env_or}; + use crate::util::{get_env, get_env_or}; dotenv::dotenv().ok(); let df = get_env_or("DATA_FOLDER", "data".to_string()); diff --git a/src/util.rs b/src/util.rs index 05c38b247dce8dafc58ca73b0ca13da04b95e4f0..4bbd145ddb621442e0f45cf4f765fc869bebee4e 100644 --- a/src/util.rs +++ b/src/util.rs @@ -23,7 +23,7 @@ macro_rules! err { #[macro_export] macro_rules! err_json { ($expr:expr) => {{ - return Err($crate::rocket::response::status::BadRequest(Some($crate::rocket_contrib::json::Json($expr)))); + return Err(rocket::response::status::BadRequest(Some(rocket_contrib::json::Json($expr)))); }} } @@ -31,7 +31,7 @@ macro_rules! err_json { macro_rules! err_handler { ($expr:expr) => {{ error!("{}", $expr); - return $crate::rocket::Outcome::Failure(($crate::rocket::http::Status::Unauthorized, $expr)); + return rocket::Outcome::Failure((rocket::http::Status::Unauthorized, $expr)); }} }