From b982383b712e0157ea6e0791df534c4195cda042 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 29 Jan 2018 21:57:06 +1100 Subject: [PATCH] Stub API for starting a installation --- Cargo.lock | 44 ++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 7 +++---- src/rest.rs | 32 +++++++++++++++++++++++++++----- static/index.html | 29 ++++++++++++++++++++++------- 5 files changed, 97 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b7b5755..5d18d8f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -165,6 +165,16 @@ dependencies = [ "tokio-tls 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "idna" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "includedir" version = "0.2.2" @@ -248,6 +258,11 @@ dependencies = [ "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "matches" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "mime" version = "0.2.6" @@ -688,11 +703,34 @@ dependencies = [ "version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "unicode-bidi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unicode-xid" version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "url" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "vcpkg" version = "0.2.2" @@ -778,6 +816,7 @@ dependencies = [ "serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-core 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "web-view 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -804,6 +843,7 @@ dependencies = [ "checksum httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2f407128745b78abc95c0ffbe4e5d37427fdc0d45470710cfef8c44522a2e37" "checksum hyper 0.11.15 (registry+https://github.com/rust-lang/crates.io-index)" = "4d6105c5eeb03068b10ff34475a0d166964f98e7b9777cc34b342a225af9b87c" "checksum hyper-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c81fa95203e2a6087242c38691a0210f23e9f3f8f944350bd676522132e2985" +"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" "checksum includedir 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ed470a2a5c0afe4587796a886aa185fcef159feaefd8c4f40d85423aeeec4a3a" "checksum includedir_codegen 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4cb2bb86e79496ab481fc7865ce8c2960cf1eb40cc1411524ce67fce54f3c95e" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" @@ -816,6 +856,7 @@ dependencies = [ "checksum libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "1e5d97d6708edaa407429faa671b942dc0f2727222fb6b6539bf1db936e4b121" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" +"checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" "checksum mime 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e2e00e17be181010a91dbfefb01660b17311059dc8c7f48b9017677721e732bd" "checksum mime_guess 1.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "dc7e82a15629bb4ecd9e72365bf33d1382be91e030f820edb8e2a21c02430da8" @@ -867,7 +908,10 @@ dependencies = [ "checksum toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7540f4ffc193e0d3c94121edb19b055670d369f77d5804db11ae053a45b6e7e" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicase 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "284b6d3db520d67fbe88fd778c21510d1b0ba4a551e5d0fbb023d33405f6de8a" +"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" +"checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" +"checksum url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa35e768d4daf1d85733418a49fb42e10d7f633e394fccab4ab7aba897053fe2" "checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b" "checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" "checksum walkdir 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c66c0b9792f0a765345452775f3adbd28dde9d33f30d13e5dcc5ae17cf6f3780" diff --git a/Cargo.toml b/Cargo.toml index 6a2ee50..e4d7859 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ hyper-tls = "0.1.2" tokio-core = "*" futures = "*" mime_guess = "1.8.3" +url = "*" includedir = "0.2.2" phf = "0.7.21" diff --git a/src/main.rs b/src/main.rs index 1efd60b..5193970 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,16 +32,15 @@ use installer::InstallerFramework; use rest::WebServer; -use sources::types::ReleaseSource; - // TODO: Fetch this over a HTTP request? static RAW_CONFIG: &'static str = include_str!("../config.toml"); fn main() { let config = Config::from_toml_str(RAW_CONFIG).unwrap(); - let github_releases = sources::github::GithubReleases{}; - println!("{:?}", github_releases.get_current_releases(&config.packages[0].source.config)); + /*let github_releases = sources::github::GithubReleases{}; + println!("{:?}", github_releases.get_current_releases(&config.packages[0].source.config));*/ + let app_name = config.general.name.clone(); let framework = InstallerFramework::new(config); diff --git a/src/rest.rs b/src/rest.rs index 925c0e7..529f654 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -4,23 +4,29 @@ /// as talking to external applications. extern crate nfd; +extern crate url; -use rest::nfd::Response as NfdResponse; +use self::nfd::Response as NfdResponse; use serde_json; +use futures::Stream; +use futures::Future; use futures::future; use futures::future::FutureResult; -use hyper::{self, Error as HyperError, Get, StatusCode}; +use hyper::{self, Error as HyperError, Get, Post, StatusCode}; use hyper::header::{ContentLength, ContentType}; use hyper::server::{Http, Request, Response, Service}; +use self::url::form_urlencoded; + use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::thread::{self, JoinHandle}; use std::process::exit; use std::sync::Arc; use std::sync::mpsc::channel; +use std::collections::HashMap; use assets; @@ -90,11 +96,11 @@ impl Service for WebService { type Request = Request; type Response = Response; type Error = hyper::Error; - type Future = FutureResult; + type Future = Box>; /// HTTP request handler fn call(&self, req: Self::Request) -> Self::Future { - future::ok(match (req.method(), req.path()) { + Box::new(future::ok(match (req.method(), req.path()) { // This endpoint should be usable directly from a