From 28978964a77e853031874230c2415b1b835e93fc Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 15 May 2018 00:35:52 -0700 Subject: fmt and cleanup --- rust/src/api_server.rs | 277 +++++++++++++++++++++++++++++++------------- rust/src/bin/fatcat-iron.rs | 50 +++----- 2 files changed, 209 insertions(+), 118 deletions(-) (limited to 'rust/src') diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index fa3b3958..59836e31 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -2,172 +2,287 @@ #![allow(unused_imports)] -use futures::{self, Future}; use chrono; +use futures::{self, Future}; use std::collections::HashMap; use swagger; -use fatcat_api::{Api, ApiError, Context, - ContainerIdGetResponse, - ContainerLookupGetResponse, - ContainerPostResponse, - CreatorIdGetResponse, - CreatorLookupGetResponse, - CreatorPostResponse, - EditgroupIdAcceptPostResponse, - EditgroupIdGetResponse, - EditgroupPostResponse, - EditorUsernameChangelogGetResponse, - EditorUsernameGetResponse, - FileIdGetResponse, - FileLookupGetResponse, - FilePostResponse, - ReleaseIdGetResponse, - ReleaseLookupGetResponse, - ReleasePostResponse, - WorkIdGetResponse, - WorkPostResponse -}; use fatcat_api::models; +use fatcat_api::{Api, ApiError, ContainerIdGetResponse, ContainerLookupGetResponse, + ContainerPostResponse, Context, CreatorIdGetResponse, CreatorLookupGetResponse, + CreatorPostResponse, EditgroupIdAcceptPostResponse, EditgroupIdGetResponse, + EditgroupPostResponse, EditorUsernameChangelogGetResponse, + EditorUsernameGetResponse, FileIdGetResponse, FileLookupGetResponse, + FilePostResponse, ReleaseIdGetResponse, ReleaseLookupGetResponse, + ReleasePostResponse, WorkIdGetResponse, WorkPostResponse}; #[derive(Copy, Clone)] pub struct Server; impl Api for Server { - - - fn container_id_get(&self, id: String, context: &Context) -> Box + Send> { + fn container_id_get( + &self, + id: String, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("container_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "container_id_get(\"{}\") - X-Span-ID: {:?}", + id, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn container_lookup_get(&self, issn: String, context: &Context) -> Box + Send> { + fn container_lookup_get( + &self, + issn: String, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("container_lookup_get(\"{}\") - X-Span-ID: {:?}", issn, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "container_lookup_get(\"{}\") - X-Span-ID: {:?}", + issn, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn container_post(&self, body: Option, context: &Context) -> Box + Send> { + fn container_post( + &self, + body: Option, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("container_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "container_post({:?}) - X-Span-ID: {:?}", + body, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn creator_id_get(&self, id: String, context: &Context) -> Box + Send> { + fn creator_id_get( + &self, + id: String, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("creator_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "creator_id_get(\"{}\") - X-Span-ID: {:?}", + id, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn creator_lookup_get(&self, orcid: String, context: &Context) -> Box + Send> { + fn creator_lookup_get( + &self, + orcid: String, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("creator_lookup_get(\"{}\") - X-Span-ID: {:?}", orcid, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "creator_lookup_get(\"{}\") - X-Span-ID: {:?}", + orcid, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn creator_post(&self, body: Option, context: &Context) -> Box + Send> { + fn creator_post( + &self, + body: Option, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("creator_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "creator_post({:?}) - X-Span-ID: {:?}", + body, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn editgroup_id_accept_post(&self, id: i32, context: &Context) -> Box + Send> { + fn editgroup_id_accept_post( + &self, + id: i32, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("editgroup_id_accept_post({}) - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "editgroup_id_accept_post({}) - X-Span-ID: {:?}", + id, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn editgroup_id_get(&self, id: i32, context: &Context) -> Box + Send> { + fn editgroup_id_get( + &self, + id: i32, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("editgroup_id_get({}) - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "editgroup_id_get({}) - X-Span-ID: {:?}", + id, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn editgroup_post(&self, context: &Context) -> Box + Send> { + fn editgroup_post( + &self, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("editgroup_post() - X-Span-ID: {:?}", context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "editgroup_post() - X-Span-ID: {:?}", + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn editor_username_changelog_get(&self, username: String, context: &Context) -> Box + Send> { + fn editor_username_changelog_get( + &self, + username: String, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("editor_username_changelog_get(\"{}\") - X-Span-ID: {:?}", username, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "editor_username_changelog_get(\"{}\") - X-Span-ID: {:?}", + username, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn editor_username_get(&self, username: String, context: &Context) -> Box + Send> { + fn editor_username_get( + &self, + username: String, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("editor_username_get(\"{}\") - X-Span-ID: {:?}", username, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "editor_username_get(\"{}\") - X-Span-ID: {:?}", + username, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn file_id_get(&self, id: String, context: &Context) -> Box + Send> { + fn file_id_get( + &self, + id: String, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("file_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "file_id_get(\"{}\") - X-Span-ID: {:?}", + id, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn file_lookup_get(&self, sha1: String, context: &Context) -> Box + Send> { + fn file_lookup_get( + &self, + sha1: String, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("file_lookup_get(\"{}\") - X-Span-ID: {:?}", sha1, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "file_lookup_get(\"{}\") - X-Span-ID: {:?}", + sha1, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn file_post(&self, body: Option, context: &Context) -> Box + Send> { + fn file_post( + &self, + body: Option, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("file_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "file_post({:?}) - X-Span-ID: {:?}", + body, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn release_id_get(&self, id: String, context: &Context) -> Box + Send> { + fn release_id_get( + &self, + id: String, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("release_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "release_id_get(\"{}\") - X-Span-ID: {:?}", + id, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn release_lookup_get(&self, doi: String, context: &Context) -> Box + Send> { + fn release_lookup_get( + &self, + doi: String, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("release_lookup_get(\"{}\") - X-Span-ID: {:?}", doi, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "release_lookup_get(\"{}\") - X-Span-ID: {:?}", + doi, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn release_post(&self, body: Option, context: &Context) -> Box + Send> { + fn release_post( + &self, + body: Option, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("release_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "release_post({:?}) - X-Span-ID: {:?}", + body, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn work_id_get(&self, id: String, context: &Context) -> Box + Send> { + fn work_id_get( + &self, + id: String, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("work_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "work_id_get(\"{}\") - X-Span-ID: {:?}", + id, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - - fn work_post(&self, body: Option, context: &Context) -> Box + Send> { + fn work_post( + &self, + body: Option, + context: &Context, + ) -> Box + Send> { let context = context.clone(); - println!("work_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("")).clone()); + println!( + "work_post({:?}) - X-Span-ID: {:?}", + body, + context.x_span_id.unwrap_or(String::from("")).clone() + ); Box::new(futures::failed("Generic failure".into())) } - } diff --git a/rust/src/bin/fatcat-iron.rs b/rust/src/bin/fatcat-iron.rs index 8c87f55f..4c168981 100644 --- a/rust/src/bin/fatcat-iron.rs +++ b/rust/src/bin/fatcat-iron.rs @@ -1,52 +1,28 @@ -//! Main binary entry point for fatcat implementation. - #![allow(missing_docs)] -// Imports required by this file. +extern crate chrono; +extern crate clap; extern crate fatcat; extern crate fatcat_api; -extern crate swagger; -extern crate iron; -//extern crate hyper_openssl; -extern crate clap; - -// Imports required by server library. -// extern crate fatcat; -// extern crate swagger; extern crate futures; -extern crate chrono; +extern crate iron; +extern crate swagger; #[macro_use] extern crate error_chain; -//use hyper_openssl::OpensslServer; -//use hyper_openssl::openssl::x509::X509_FILETYPE_PEM; -//use hyper_openssl::openssl::ssl::{SslAcceptorBuilder, SslMethod}; -//use hyper_openssl::openssl::error::ErrorStack; use clap::{App, Arg}; -use iron::{Iron, Chain}; +use iron::{Chain, Iron}; use swagger::auth::AllowAllMiddleware; -/* -/// Builds an SSL implementation for Simple HTTPS from some hard-coded file names -fn ssl() -> Result { - let mut ssl = SslAcceptorBuilder::mozilla_intermediate_raw(SslMethod::tls())?; - - // Server authentication - ssl.set_private_key_file("examples/server-key.pem", X509_FILETYPE_PEM)?; - ssl.set_certificate_chain_file("examples/server-chain.pem")?; - ssl.check_private_key()?; - - Ok(OpensslServer::from(ssl.build())) -} -*/ - /// Create custom server, wire it to the autogenerated router, /// and pass it to the web server. fn main() { let matches = App::new("server") - .arg(Arg::with_name("https") - .long("https") - .help("Whether to use HTTPS or not")) + .arg( + Arg::with_name("https") + .long("https") + .help("Whether to use HTTPS or not"), + ) .get_matches(); let server = fatcat::server().unwrap(); @@ -60,10 +36,10 @@ fn main() { if matches.is_present("https") { unimplemented!() - // Using Simple HTTPS - //Iron::new(chain).https("localhost:8080", ssl().expect("Failed to load SSL keys")).expect("Failed to start HTTPS server"); } else { // Using HTTP - Iron::new(chain).http("localhost:8080").expect("Failed to start HTTP server"); + Iron::new(chain) + .http("localhost:8080") + .expect("Failed to start HTTP server"); } } -- cgit v1.2.3