Skip to content

Commit

Permalink
Compatibility w/ Rust 1.35-nightly
Browse files Browse the repository at this point in the history
Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
  • Loading branch information
valeriansaliou committed Aug 13, 2019
1 parent a7550d2 commit 0dbdacc
Show file tree
Hide file tree
Showing 23 changed files with 860 additions and 695 deletions.
761 changes: 490 additions & 271 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ doc = false
[dependencies]
log = "0.3"
clap = { version = "2.29", default-features = false }
lazy_static = "1.0"
lazy_static = "1.3"
sha2 = "0.7"
time = "0.1"
rand = "0.4"
Expand All @@ -38,9 +38,8 @@ native-tls = "0.1"
openssl-probe = "0.1"
lettre = { version = "0.7", features = ["smtp-transport"] }
lettre_email = "0.7"
rocket = { version = "0.3", default-features = false }
rocket_codegen = "0.3"
rocket_contrib = { version = "0.3", features = ["tera_templates"] }
rocket = { version = "0.4", features = ["private-cookies"] }
rocket_contrib = { version = "0.4", features = ["tera_templates"] }
diesel = { version = "1.1", features = ["mysql", "chrono", "numeric"] }
r2d2 = "0.8"
r2d2-diesel = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Raider

Raider is easy to integrate in your existing system. You can also customize the dashboard look & feel with templates and styles. It can be used as a self-service affiliates system, for your affiliate users to manage their account, create tracking URLs, review their balance and request for payouts.

_Tested at Rust version: `rust 1.25.0-nightly (8ccab7eed 2018-01-31)`_
_Tested at Rust version: `rustc 1.35.0-nightly (aa99abeb2 2019-04-14)`_

**🇭🇺 Crafted in Budapest, Hungary.**

Expand Down
2 changes: 1 addition & 1 deletion src/config/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// License: Mozilla Public License v2.0 (MPL v2.0)

use log;
use log::{LogRecord, LogLevel, LogMetadata, LogLevelFilter, SetLoggerError};
use log::{LogLevel, LogLevelFilter, LogMetadata, LogRecord, SetLoggerError};

pub struct ConfigLogger;

Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

mod defaults;

pub mod logger;
pub mod config;
pub mod logger;
pub mod reader;
7 changes: 3 additions & 4 deletions src/config/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// Copyright: 2018, Valerian Saliou <valerian@valeriansaliou.name>
// License: Mozilla Public License v2.0 (MPL v2.0)

use log;
use std::fs::File;
use std::io::Read;
use log;
use toml;

use super::config::*;
Expand All @@ -21,9 +21,8 @@ impl ConfigReader {
let mut file = File::open(&APP_ARGS.config).expect("cannot find config file");
let mut conf = String::new();

file.read_to_string(&mut conf).expect(
"cannot read config file",
);
file.read_to_string(&mut conf)
.expect("cannot read config file");

log::debug!("read config file: {}", &APP_ARGS.config);

Expand Down
15 changes: 8 additions & 7 deletions src/exchange/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
// Copyright: 2018, Valerian Saliou <valerian@valeriansaliou.name>
// License: Mozilla Public License v2.0 (MPL v2.0)

use std::thread;
use std::sync::RwLock;
use std::sync::Arc;
use std::collections::HashMap;
use std::time::Duration;
use log;
use reqwest::{Client, StatusCode};
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::RwLock;
use std::thread;
use std::time::Duration;

use APP_CONF;

Expand All @@ -19,7 +19,6 @@ const RETRY_POLL_SECONDS: u64 = 30;

lazy_static! {
static ref RATES: Arc<RwLock<HashMap<String, f32>>> = Arc::new(RwLock::new(HashMap::new()));

static ref HTTP_CLIENT: Client = Client::builder()
.timeout(Duration::from_secs(20))
.gzip(true)
Expand All @@ -46,7 +45,9 @@ fn update_rates() -> Result<(), ()> {
let response = HTTP_CLIENT
.get(&format!(
"{}/api/latest?access_key={}&base={}",
&APP_CONF.exchange.fixer.endpoint, &APP_CONF.exchange.fixer.access_key, &APP_CONF.payout.currency
&APP_CONF.exchange.fixer.endpoint,
&APP_CONF.exchange.fixer.access_key,
&APP_CONF.payout.currency
))
.send();

Expand Down
43 changes: 22 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
// Copyright: 2018, Valerian Saliou <valerian@valeriansaliou.name>
// License: Mozilla Public License v2.0 (MPL v2.0)

#![feature(use_extern_macros, custom_derive, plugin)]
#![plugin(rocket_codegen)]
#![feature(proc_macro_hygiene, decl_macro)]

#[macro_use(log)]
extern crate log;
Expand All @@ -17,27 +16,28 @@ extern crate lazy_static;
extern crate diesel;
#[macro_use]
extern crate serde_derive;
extern crate sha2;
extern crate time;
extern crate rand;
extern crate validate;
extern crate toml;
#[macro_use]
extern crate rocket;
extern crate base64;
extern crate url_serde;
extern crate bigdecimal;
extern crate chrono;
extern crate native_tls;
extern crate openssl_probe;
extern crate iso_country;
extern crate lettre;
extern crate lettre_email;
extern crate native_tls;
extern crate num_traits;
extern crate openssl_probe;
extern crate r2d2;
extern crate r2d2_diesel;
extern crate rocket;
extern crate rocket_contrib;
extern crate rand;
extern crate reqwest;
extern crate bigdecimal;
extern crate num_traits;
extern crate rocket_contrib;
extern crate separator;
extern crate iso_country;
extern crate sha2;
extern crate time;
extern crate toml;
extern crate url_serde;
extern crate validate;

mod config;
mod exchange;
Expand All @@ -46,9 +46,9 @@ mod responder;
mod storage;
mod track;

use std::thread;
use std::ops::Deref;
use std::str::FromStr;
use std::thread;
use std::time::Duration;

use clap::{App, Arg};
Expand All @@ -68,7 +68,7 @@ pub static THREAD_NAME_EXCHANGE: &'static str = "raider-exchange";
pub static THREAD_NAME_RESPONDER: &'static str = "raider-responder";

macro_rules! gen_spawn_managed {
($name:expr, $method:ident, $thread_name:ident, $managed_fn:ident) => (
($name:expr, $method:ident, $thread_name:ident, $managed_fn:ident) => {
fn $method() {
log::debug!("spawn managed thread: {}", $name);

Expand All @@ -93,7 +93,7 @@ macro_rules! gen_spawn_managed {
$method();
}
}
)
};
}

lazy_static! {
Expand Down Expand Up @@ -130,13 +130,14 @@ fn make_app_args() -> AppArgs {
.get_matches();

// Generate owned app arguments
AppArgs { config: String::from(matches.value_of("config").expect("invalid config value")) }
AppArgs {
config: String::from(matches.value_of("config").expect("invalid config value")),
}
}

fn ensure_states() {
// Ensure all statics are valid (a `deref` is enough to lazily initialize them)
APP_ARGS.deref();
APP_CONF.deref();
let (_, _) = (APP_ARGS.deref(), APP_CONF.deref());

// Ensure assets path exists
assert_eq!(
Expand Down
23 changes: 12 additions & 11 deletions src/notifier/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
// Copyright: 2018, Valerian Saliou <valerian@valeriansaliou.name>
// License: Mozilla Public License v2.0 (MPL v2.0)

use std::time::Duration;
use log;
use native_tls::TlsConnector;
use lettre::smtp::{ClientSecurity, SmtpTransportBuilder, SmtpTransport, ConnectionReuseParameters};
use lettre::smtp::authentication::Credentials;
use lettre::smtp::client::net::ClientTlsParameters;
use lettre::smtp::{
ClientSecurity, ConnectionReuseParameters, SmtpTransport, SmtpTransportBuilder,
};
use lettre::EmailTransport;
use lettre_email::EmailBuilder;
use log;
use native_tls::TlsConnector;
use std::time::Duration;

use APP_CONF;

Expand Down Expand Up @@ -52,9 +54,10 @@ impl EmailNotifier {
APP_CONF.email.smtp_username.to_owned(),
APP_CONF.email.smtp_password.to_owned(),
APP_CONF.email.smtp_encrypt,
).map(|mut transport| transport.send(&email_message))
.and(Ok(()))
.or(Err(true));
)
.map(|mut transport| transport.send(&email_message))
.and(Ok(()))
.or(Err(true));
}
}

Expand Down Expand Up @@ -94,10 +97,8 @@ fn acquire_transport(

match (smtp_username, smtp_password) {
(Some(smtp_username_value), Some(smtp_password_value)) => {
transport_builder = transport_builder.credentials(Credentials::new(
smtp_username_value,
smtp_password_value,
));
transport_builder = transport_builder
.credentials(Credentials::new(smtp_username_value, smtp_password_value));
}
_ => {}
}
Expand Down
9 changes: 4 additions & 5 deletions src/responder/asset_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
// License: Mozilla Public License v2.0 (MPL v2.0)

use std::fs::File;
use std::path::{Path, PathBuf};
use std::io;
use std::ops::{Deref, DerefMut};
use std::path::{Path, PathBuf};
use time::{self, Duration};

use rocket::http::hyper::header::{CacheControl, CacheDirective, Expires, HttpDate};
use rocket::http::ContentType;
use rocket::request::Request;
use rocket::response::{self, Responder};
use rocket::http::ContentType;
use rocket::http::hyper::header::{CacheControl, CacheDirective, Expires, HttpDate};

const ASSETS_EXPIRE_SECONDS: u32 = 10800;

Expand Down Expand Up @@ -60,8 +60,7 @@ impl<'r> Responder<'r> for AssetFile {
]));

response.set_header(Expires(HttpDate(
time::now() +
Duration::seconds(ASSETS_EXPIRE_SECONDS as i64),
time::now() + Duration::seconds(ASSETS_EXPIRE_SECONDS as i64),
)));

// Set content type header?
Expand Down
8 changes: 4 additions & 4 deletions src/responder/auth_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// License: Mozilla Public License v2.0 (MPL v2.0)

use log;
use rocket::Outcome;
use rocket::http::{Status, Cookies, Cookie};
use rocket::request::{self, Request, FromRequest};
use rand::{self, Rng};
use sha2::{Sha256, Digest};
use rocket::http::{Cookie, Cookies, Status};
use rocket::request::{self, FromRequest, Request};
use rocket::Outcome;
use sha2::{Digest, Sha256};

use APP_CONF;

Expand Down
4 changes: 2 additions & 2 deletions src/responder/catchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

use rocket::response::Redirect;

#[error(403)]
#[catch(403)]
pub fn forbidden() -> Redirect {
Redirect::to("/initiate/")
}

#[error(410)]
#[catch(410)]
pub fn gone() -> Redirect {
Redirect::to("/dashboard/")
}
7 changes: 5 additions & 2 deletions src/responder/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// Copyright: 2018, Valerian Saliou <valerian@valeriansaliou.name>
// License: Mozilla Public License v2.0 (MPL v2.0)

use url_serde::SerdeUrl;
use separator::FixedPlaceSeparatable;
use url_serde::SerdeUrl;

use config::config::ConfigTrackerBanner;
use APP_CONF;
Expand All @@ -25,7 +25,10 @@ lazy_static! {
logo_dark_url: APP_CONF.branding.logo_dark_url.to_owned(),
custom_html: APP_CONF.branding.custom_html.to_owned(),
payout_currency: APP_CONF.payout.currency.to_owned(),
payout_amount_minimum: APP_CONF.payout.amount_minimum.separated_string_with_fixed_place(2),
payout_amount_minimum: APP_CONF
.payout
.amount_minimum
.separated_string_with_fixed_place(2),
track_url: APP_CONF.tracker.track_url.to_owned(),
track_parameter: APP_CONF.tracker.track_parameter.to_owned(),
banners: ConfigContext::map_banners(&APP_CONF.tracker.banner)
Expand Down
Loading

0 comments on commit 0dbdacc

Please sign in to comment.