summaryrefslogtreecommitdiffstats
path: root/rust/src/bin/fatcat-tokio.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-05-14 23:17:26 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-05-14 23:17:26 -0700
commit2c56f2b65bcf3b3f85db9d2a34501154c9c9404d (patch)
treed9580fb8578f6e1ea0f47dd1e6402ebd41d3a0e9 /rust/src/bin/fatcat-tokio.rs
parente468707ee53f4a8ff75b00a1eec44921672464b6 (diff)
downloadfatcat-2c56f2b65bcf3b3f85db9d2a34501154c9c9404d.tar.gz
fatcat-2c56f2b65bcf3b3f85db9d2a34501154c9c9404d.zip
regenerated and pseudo-integrated
Diffstat (limited to 'rust/src/bin/fatcat-tokio.rs')
-rw-r--r--rust/src/bin/fatcat-tokio.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/rust/src/bin/fatcat-tokio.rs b/rust/src/bin/fatcat-tokio.rs
new file mode 100644
index 00000000..cc603908
--- /dev/null
+++ b/rust/src/bin/fatcat-tokio.rs
@@ -0,0 +1,67 @@
+//! Main binary entry point for fatcat implementation.
+
+#![allow(missing_docs)]
+
+// Imports required by this file.
+extern crate fatcat;
+extern crate fatcat_api;
+extern crate hyper;
+extern crate swagger;
+//extern crate openssl;
+//extern crate native_tls;
+extern crate tokio_proto;
+//extern crate tokio_tls;
+extern crate clap;
+
+//use openssl::x509::X509_FILETYPE_PEM;
+//use openssl::ssl::{SslAcceptorBuilder, SslMethod};
+//use openssl::error::ErrorStack;
+use clap::{App, Arg};
+use hyper::server::Http;
+use swagger::auth::AllowAllAuthenticator;
+use tokio_proto::TcpServer;
+
+// Builds an SSL implementation for Simple HTTPS from some hard-coded file names
+/*
+fn ssl() -> Result<SslAcceptorBuilder, ErrorStack> {
+ 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(ssl)
+}
+*/
+
+/// 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"),
+ )
+ .get_matches();
+
+ let service_fn = fatcat_api::server::auth::NewService::new(AllowAllAuthenticator::new(
+ fatcat::NewService,
+ "cosmo",
+ ));
+
+ let addr = "127.0.0.1:8080"
+ .parse()
+ .expect("Failed to parse bind address");
+ if matches.is_present("https") {
+ unimplemented!()
+ //let ssl = ssl().expect("Failed to load SSL keys");
+ //let builder: native_tls::TlsAcceptorBuilder = native_tls::backend::openssl::TlsAcceptorBuilderExt::from_openssl(ssl);
+ //let tls_acceptor = builder.build().expect("Failed to build TLS acceptor");
+ //TcpServer::new(tokio_tls::proto::Server::new(Http::new(), tls_acceptor), addr).serve(service_fn);
+ } else {
+ // Using HTTP
+ TcpServer::new(Http::new(), addr).serve(service_fn);
+ }
+}