summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rust/Cargo.lock43
-rw-r--r--rust/Cargo.toml3
-rw-r--r--rust/src/api_server.rs10
-rw-r--r--rust/src/bin/fatcat-iron.rs6
-rw-r--r--rust/src/lib.rs2
5 files changed, 64 insertions, 0 deletions
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index f226a884..9508d3ca 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -314,6 +314,7 @@ dependencies = [
"iron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"iron-slog 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"iron-test 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "iron_diesel_middleware 0.4.0 (git+https://github.com/darayus/iron-diesel-middleware)",
"slog 2.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"slog-term 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -476,6 +477,17 @@ dependencies = [
]
[[package]]
+name = "iron_diesel_middleware"
+version = "0.4.0"
+source = "git+https://github.com/darayus/iron-diesel-middleware#d663e4a238b8a3952a31b90d7cba56ee292013c2"
+dependencies = [
+ "diesel 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "iron 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "r2d2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "r2d2-diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "isatty"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -779,6 +791,25 @@ dependencies = [
]
[[package]]
+name = "r2d2"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "antidote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "scheduled-thread-pool 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "r2d2-diesel"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "diesel 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "r2d2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "rand"
version = "0.3.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -870,6 +901,14 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "scheduled-thread-pool"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "antidote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "serde"
version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1293,6 +1332,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum iron 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d8e17268922834707e1c29e8badbf9c712c9c43378e1b6a3388946baff10be2"
"checksum iron-slog 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eb0cc34306c77baf5089b3af209a0547c0ce36cdeaee2424a9fa0e45c042f4a0"
"checksum iron-test 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b1944bcf30f8b3f51ebf01e715517dd9755e9480934778d6de70179a41d283c1"
+"checksum iron_diesel_middleware 0.4.0 (git+https://github.com/darayus/iron-diesel-middleware)" = "<none>"
"checksum isatty 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a118a53ba42790ef25c82bb481ecf36e2da892646cccd361e69a6bb881e19398"
"checksum itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae3088ea4baeceb0284ee9eea42f591226e6beaecf65373e41b38d95a1b8e7a1"
"checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682"
@@ -1331,6 +1371,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1b06e2f335f48d24442b35a19df506a835fb3547bc3c06ef27340da9acf5cae7"
"checksum quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1eca14c727ad12702eb4b6bfb5a232287dcf8385cb8ca83a3eeaf6519c44c408"
"checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8"
+"checksum r2d2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f9078ca6a8a5568ed142083bb2f7dc9295b69d16f867ddcc9849e51b17d8db46"
+"checksum r2d2-diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9c29bad92da76d02bc2c020452ebc3a3fe6fa74cfab91e711c43116e4fb1a3"
"checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1"
"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5"
"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd"
@@ -1343,6 +1385,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649"
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f"
+"checksum scheduled-thread-pool 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a2ff3fc5223829be817806c6441279c676e454cc7da608faf03b0ccc09d3889"
"checksum serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8"
"checksum serde 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)" = "97f6a6c3caba0cf8f883b53331791036404ce3c1bd895961cf8bb2f8cecfd84b"
"checksum serde_derive 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)" = "f51b0ef935cf8a41a77bce553da1f8751a739b7ad82dd73669475a22e6ecedb0"
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 4e86d830..868523ff 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -25,6 +25,9 @@ slog = "^2.0"
slog-term = "*"
slog-async = "*"
+[dependencies.iron_diesel_middleware]
+git = "https://github.com/darayus/iron-diesel-middleware"
+
#hyper-openssl = {version = "0.2", optional = true}
#hyper-tls = {version = "0.1.2", optional = true}
#tokio-core = "0.1.6"
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs
index 59836e31..cac222e6 100644
--- a/rust/src/api_server.rs
+++ b/rust/src/api_server.rs
@@ -7,6 +7,11 @@ use futures::{self, Future};
use std::collections::HashMap;
+use self::models::*;
+use diesel;
+use diesel::prelude::*;
+use iron_diesel_middleware::DieselPooledConnection;
+
use swagger;
use fatcat_api::models;
@@ -28,11 +33,16 @@ impl Api for Server {
context: &Context,
) -> Box<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send> {
let context = context.clone();
+ let con: DieselPooledConnection<diesel::pg::PgConnection> = req.db_conn();
println!(
"container_id_get(\"{}\") - X-Span-ID: {:?}",
id,
context.x_span_id.unwrap_or(String::from("<none>")).clone()
);
+ println!(
+ "container count: {}",
+ containers.count().load(&con).expect("DB Error"),
+ );
Box::new(futures::failed("Generic failure".into()))
}
diff --git a/rust/src/bin/fatcat-iron.rs b/rust/src/bin/fatcat-iron.rs
index 0bed0fa2..1f443e8e 100644
--- a/rust/src/bin/fatcat-iron.rs
+++ b/rust/src/bin/fatcat-iron.rs
@@ -37,6 +37,11 @@ fn main() {
let logger = Logger::root(drain, o!());
let formatter = DefaultLogFormatter;
+ dotenv().ok();
+ let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
+
+ let diesel_middleware: DieselMiddleware<diesel::pg::PgConnection> = DieselMiddleware::new(database_url).unwrap();
+
let server = fatcat::server().unwrap();
let router = fatcat_api::router(server);
@@ -49,6 +54,7 @@ fn main() {
chain.link_before(AllowAllMiddleware::new("cosmo"));
chain.link_after(fatcat::XClacksOverheadMiddleware);
+ chain.link_before(diesel_middleware);
if matches.is_present("https") {
unimplemented!()
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 55040f0c..fecea06e 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -2,6 +2,7 @@
extern crate fatcat_api;
extern crate chrono;
extern crate diesel;
+extern crate iron_diesel_middleware;
extern crate dotenv;
extern crate futures;
#[macro_use] extern crate hyper;
@@ -23,6 +24,7 @@ use std::env;
use hyper::header::Headers;
use iron::{Request, Response};
use iron::middleware::AfterMiddleware;
+use iron_diesel_middleware::{DieselMiddleware, DieselPooledConnection, DieselReqExt};
pub fn establish_connection() -> PgConnection {
dotenv().ok();