Browse Source

Ran code formatting and cleaned imports.

develop
Drew Short 6 years ago
parent
commit
9cad1dfc91
  1. 16
      src/config/default.rs
  2. 6
      src/config/error.rs
  3. 7
      src/config/load.rs
  4. 17
      src/config/model.rs
  5. 15
      src/main.rs
  6. 5
      src/server/api.rs
  7. 2
      src/server/router.rs

16
src/config/default.rs

@ -5,7 +5,7 @@ fn get_default_config() -> Config {
server: ServerConfig { server: ServerConfig {
host: Option::Some(String::from("localhost")), host: Option::Some(String::from("localhost")),
port: Option::Some(8080), port: Option::Some(8080),
workers: Option::Some(4)
workers: Option::Some(4),
}, },
cloudflare: CloudflareConfig { cloudflare: CloudflareConfig {
email: String::from("something@something.com"), email: String::from("something@something.com"),
@ -13,9 +13,9 @@ fn get_default_config() -> Config {
domains: vec![ domains: vec![
CloudflareDomainConfig { CloudflareDomainConfig {
domain: String::from("IAmNotADomain.com"), domain: String::from("IAmNotADomain.com"),
zone_id: String::from("IAmNotAZoneID")
zone_id: String::from("IAmNotAZoneID"),
} }
]
],
}, },
ddns: DDNSConfig { ddns: DDNSConfig {
domains: vec![ domains: vec![
@ -23,7 +23,7 @@ fn get_default_config() -> Config {
domain: String::from("IAmNotADomain.com"), domain: String::from("IAmNotADomain.com"),
subdomains: vec![ subdomains: vec![
String::from("ddns") String::from("ddns")
]
],
} }
] ]
}, },
@ -39,12 +39,12 @@ fn get_default_config() -> Config {
subdomain: String::from("ddns"), subdomain: String::from("ddns"),
targets: vec![ targets: vec![
String::from("home") String::from("home")
]
],
} }
]
],
} }
]
],
} }
]
],
} }
} }

6
src/config/error.rs

@ -4,14 +4,14 @@ use std::fmt;
#[derive(Debug)] #[derive(Debug)]
pub struct ConfigError { pub struct ConfigError {
description: String, description: String,
original_error: Option<Box<Error>>
original_error: Option<Box<Error>>,
} }
impl ConfigError { impl ConfigError {
pub fn new(description: &str, original_error: Option<Box<Error>>) -> ConfigError { pub fn new(description: &str, original_error: Option<Box<Error>>) -> ConfigError {
ConfigError { ConfigError {
description: String::from(description), description: String::from(description),
original_error
original_error,
} }
} }
} }
@ -23,7 +23,7 @@ impl fmt::Display for ConfigError {
match &self.original_error { match &self.original_error {
Some(original_error) => { Some(original_error) => {
write!(f, "{}: \"{}\"", self.description, original_error) write!(f, "{}: \"{}\"", self.description, original_error)
},
}
None => write!(f, "{}", self.description) None => write!(f, "{}", self.description)
} }
} }

7
src/config/load.rs

@ -1,7 +1,8 @@
use serde_yaml;
use std::fs::File; use std::fs::File;
use std::io::prelude::*; use std::io::prelude::*;
use serde_yaml;
use config::error::ConfigError; use config::error::ConfigError;
use config::model::Config; use config::model::Config;
@ -23,10 +24,10 @@ pub fn read(path: &str) -> Result<Config, ConfigError> {
} else { } else {
Result::Err(ConfigError::new("Empty Configuration File", Option::None)) Result::Err(ConfigError::new("Empty Configuration File", Option::None))
} }
},
}
Err(e) => Result::Err(ConfigError::new("Cannot Read Configuration File", Option::Some(Box::from(e)))) Err(e) => Result::Err(ConfigError::new("Cannot Read Configuration File", Option::Some(Box::from(e))))
} }
},
}
Err(_e) => Result::Err(ConfigError::new(&format!("Configuration File Doesn't Exist \"{}\"", path), Option::None)) Err(_e) => Result::Err(ConfigError::new(&format!("Configuration File Doesn't Exist \"{}\"", path), Option::None))
} }
} }

17
src/config/model.rs

@ -1,16 +1,15 @@
#[derive(Debug, PartialEq, Serialize, Deserialize)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct ServerConfig { pub struct ServerConfig {
pub host: Option<String>, pub host: Option<String>,
pub port: Option<i32>, pub port: Option<i32>,
pub workers: Option<usize>
pub workers: Option<usize>,
} }
#[derive(Debug, PartialEq, Serialize, Deserialize)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct CloudflareDomainConfig { pub struct CloudflareDomainConfig {
pub domain: String, pub domain: String,
pub zone_id: String
pub zone_id: String,
} }
@ -18,14 +17,14 @@ pub struct CloudflareDomainConfig {
pub struct CloudflareConfig { pub struct CloudflareConfig {
pub domains: Vec<CloudflareDomainConfig>, pub domains: Vec<CloudflareDomainConfig>,
pub key: String, pub key: String,
pub email: String
pub email: String,
} }
#[derive(Debug, PartialEq, Serialize, Deserialize)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct DDNSDomain { pub struct DDNSDomain {
pub domain: String, pub domain: String,
pub subdomains: Vec<String>
pub subdomains: Vec<String>,
} }
@ -38,14 +37,14 @@ pub struct DDNSConfig {
#[derive(Debug, PartialEq, Serialize, Deserialize)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct UserSubdomainConfig { pub struct UserSubdomainConfig {
pub subdomain: String, pub subdomain: String,
pub targets: Vec<String>
pub targets: Vec<String>,
} }
#[derive(Debug, PartialEq, Serialize, Deserialize)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct UserDomainConfig { pub struct UserDomainConfig {
pub domain: String, pub domain: String,
pub subdomains: Vec<UserSubdomainConfig>
pub subdomains: Vec<UserSubdomainConfig>,
} }
@ -53,7 +52,7 @@ pub struct UserDomainConfig {
pub struct UserConfig { pub struct UserConfig {
pub username: String, pub username: String,
pub token: String, pub token: String,
pub domains: Vec<UserDomainConfig>
pub domains: Vec<UserDomainConfig>,
} }
@ -62,5 +61,5 @@ pub struct Config {
pub server: ServerConfig, pub server: ServerConfig,
pub cloudflare: CloudflareConfig, pub cloudflare: CloudflareConfig,
pub ddns: DDNSConfig, pub ddns: DDNSConfig,
pub users: Vec<UserConfig>
pub users: Vec<UserConfig>,
} }

15
src/main.rs

@ -1,17 +1,16 @@
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate log;
#[macro_use]
extern crate lazy_static;
extern crate actix_web; extern crate actix_web;
extern crate bytes; extern crate bytes;
extern crate clap; extern crate clap;
extern crate env_logger; extern crate env_logger;
extern crate futures; extern crate futures;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate num_cpus; extern crate num_cpus;
extern crate serde; extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_yaml; extern crate serde_yaml;
use clap::{App, Arg}; use clap::{App, Arg};
@ -77,7 +76,7 @@ fn main() {
Ok(c) => { Ok(c) => {
info!("Loaded configuration from \"{}\"", config_path); info!("Loaded configuration from \"{}\"", config_path);
Option::Some(c) Option::Some(c)
},
}
Err(e) => { Err(e) => {
error!("{}", e); error!("{}", e);
Option::None Option::None

5
src/server/api.rs

@ -1,9 +1,10 @@
use std::io::Read;
use actix_web::{AsyncResponder, FutureResponse, HttpMessage, HttpRequest, HttpResponse, Scope};
use actix_web::http::Method; use actix_web::http::Method;
use actix_web::http::StatusCode; use actix_web::http::StatusCode;
use actix_web::{AsyncResponder, FutureResponse, HttpMessage, HttpRequest, HttpResponse, Scope};
use bytes::{Buf, Bytes, IntoBuf}; use bytes::{Buf, Bytes, IntoBuf};
use futures::future::Future; use futures::future::Future;
use std::io::Read;
pub fn route(scope: Scope<()>) -> Scope<()> { pub fn route(scope: Scope<()>) -> Scope<()> {
scope.resource("address", |r| r.method(Method::GET).f(get_address)) scope.resource("address", |r| r.method(Method::GET).f(get_address))

2
src/server/router.rs

@ -1,7 +1,7 @@
extern crate actix_web; extern crate actix_web;
use actix_web::{App, http};
use actix_web::middleware::Logger; use actix_web::middleware::Logger;
use actix_web::{http, App};
use server; use server;

Loading…
Cancel
Save