Skip to content
Permalink
Browse files

Ship migrations, ca certs.

  • Loading branch information...
remexre committed Jan 31, 2019
1 parent 160c915 commit 11b601100add6a2482d279214d4b5c5dadabacdf
Showing with 109 additions and 11 deletions.
  1. +64 −0 Cargo.lock
  2. +3 −1 Cargo.toml
  3. +1 −1 Dockerfile
  4. +25 −3 src/dal/mailer.rs
  5. +5 −2 src/dal/mod.rs
  6. +2 −0 src/lib.rs
  7. +9 −4 src/main.rs

Some generated files are not rendered by default. Learn more.

@@ -9,7 +9,9 @@ version = "0.1.0"
[dependencies]
antidote = "1.0.0"
chrono = { version = "0.4.6", features = ["serde"] }
chrono-humanize = "0.0.11"
diesel = { version = "1.4.1", default_features = false, features = ["chrono", "postgres", "r2d2", "uuid"] }
diesel_migrations = "1.4.0"
dotenv = "0.13.0"
failure = "0.1.5"
fern = { version = "0.5.7", features = ["syslog-4"] }
@@ -20,6 +22,7 @@ lazy_static = "1.2.0"
lettre = "0.8.3"
lettre_email = "0.8.3"
log = "0.4.6"
native-tls = "0.1.5"
packer = "0.3.1"
serde = "1.0.85"
serde_derive = "1.0.85"
@@ -31,7 +34,6 @@ tokio = "0.1.15"
tokio-threadpool = "0.1.11"
uuid = { version = "0.6.5", features = ["serde", "v4"] }
warp = "0.1.12"
chrono-humanize = "0.0.11"

[patch.crates-io]
warp = { git = "https://github.com/remexre/warp", branch = "vec-u8-replysealed" }
@@ -4,7 +4,7 @@ COPY . .
RUN cargo build --release

FROM debian:stable-slim
RUN apt-get update && apt-get install -y libpq5 && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y ca-certificates libpq5 && rm -rf /var/lib/apt/lists/*
COPY --from=0 /usr/src/nihctfplat/target/release/nihctfplat /usr/local/bin/nihctfplat

USER nobody
@@ -6,10 +6,15 @@ use futures::{
Future,
};
use lettre::{
smtp::{authentication::Credentials, SmtpTransport},
smtp::{
authentication::Credentials,
client::net::{ClientTlsParameters, DEFAULT_TLS_PROTOCOLS},
ClientSecurity, SmtpTransport,
},
EmailTransport,
};
use lettre_email::EmailBuilder;
use native_tls::TlsConnector;
use std::sync::Arc;

/// A connection to the mailer.
@@ -21,8 +26,25 @@ pub struct Mailer {

impl Mailer {
/// Connects to an SMTP server.
pub fn connect(host: &str, user: String, pass: String, from: String) -> Fallible<Mailer> {
let smtp = SmtpTransport::simple_builder(host)?
pub fn connect(
host: &str,
secure: bool,
user: String,
pass: String,
from: String,
) -> Fallible<Mailer> {
let smtp = if secure {
SmtpTransport::simple_builder(host)?
} else {
let mut tls_builder = TlsConnector::builder()?;
let _ = tls_builder.supported_protocols(DEFAULT_TLS_PROTOCOLS)?;

let tls_parameters =
ClientTlsParameters::new(host.to_string(), tls_builder.build().unwrap());

SmtpTransport::builder(host, ClientSecurity::Opportunistic(tls_parameters))?
};
let smtp = smtp
.credentials(Credentials::new(user.clone(), pass))
.build();
Ok(Mailer {
@@ -8,6 +8,8 @@ mod mailer;
#[allow(proc_macro_derive_resolution_fallback, unused_import_braces)]
mod schema;

embed_migrations!("migrations");

pub use crate::dal::mailer::Mailer;
use crate::{
dal::schema::{auths, logins, teams, users},
@@ -18,7 +20,7 @@ use chrono::{DateTime, Utc};
use diesel::{
dsl::{insert_into, now, update},
prelude::*,
r2d2::{ConnectionManager, Pool, PoolError},
r2d2::{ConnectionManager, Pool},
};
use failure::{bail, Error};
use futures::{
@@ -37,8 +39,9 @@ pub struct DB {

impl DB {
/// Connects to the database with at the given URL.
pub fn connect(database_url: &str) -> Result<DB, PoolError> {
pub fn connect(database_url: &str) -> Result<DB, Error> {
let pool = Arc::new(Pool::new(ConnectionManager::new(database_url))?);
embedded_migrations::run(&pool.get()?)?;
Ok(DB { pool })
}

@@ -42,6 +42,8 @@

#[macro_use]
extern crate diesel;
#[macro_use]
extern crate diesel_migrations;

#[macro_use]
pub mod util;
@@ -37,6 +37,7 @@ fn run(options: Options) -> Fallible<()> {
.clone();
let mailer = Mailer::connect(
&options.smtp_host,
!options.smtp_insecure,
options.smtp_user,
options.smtp_pass,
smtp_from,
@@ -71,20 +72,24 @@ pub struct Options {

/// The SMTP server's hostname.
#[structopt(long = "smtp-host", env = "SMTP_HOST")]
smtp_host: String,
pub smtp_host: String,

/// Whether to make SMTP less secure.
#[structopt(long = "smtp-insecure")]
pub smtp_insecure: bool,

/// The user to authenticate to the SMTP server with. Usually your email address.
#[structopt(long = "smtp-user", env = "SMTP_USER")]
smtp_user: String,
pub smtp_user: String,

/// The password to authenticate to the SMTP server with.
#[structopt(long = "smtp-pass", env = "SMTP_PASS")]
smtp_pass: String,
pub smtp_pass: String,

/// The From address for emails. Maybe be of the form "email@host.com" or
/// "Foo Bar <email@host.com>". Defaults to the SMTP user.
#[structopt(long = "smtp-from", env = "SMTP_FROM")]
smtp_from: Option<String>,
pub smtp_from: Option<String>,

/// The syslog server to send logs to.
#[structopt(short = "s", long = "syslog-server", env = "SYSLOG_SERVER")]

0 comments on commit 11b6011

Please sign in to comment.
You can’t perform that action at this time.