From 2a549386a6e01ab5ae01bb3ad8183a9adda14a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 30 Aug 2016 14:25:39 +0200 Subject: [PATCH] Fetching from github --- dapps/src/apps/fetcher.rs | 19 ++++++++++++++++++- dapps/src/apps/urlhint.rs | 3 +-- dapps/src/handlers/client/mod.rs | 2 +- dapps/src/handlers/fetch.rs | 4 ++-- logger/src/lib.rs | 2 ++ 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/dapps/src/apps/fetcher.rs b/dapps/src/apps/fetcher.rs index 347c8da5f..afbfda96a 100644 --- a/dapps/src/apps/fetcher.rs +++ b/dapps/src/apps/fetcher.rs @@ -19,7 +19,7 @@ //! Uses `URLHint` to resolve addresses into Dapps bundle file location. use zip; -use std::{fs, env}; +use std::{fs, env, fmt}; use std::io::{self, Read, Write}; use std::path::PathBuf; use std::sync::Arc; @@ -146,6 +146,23 @@ pub enum ValidationError { HashMismatch { expected: H256, got: H256, }, } +impl fmt::Display for ValidationError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match *self { + ValidationError::Io(ref io) => write!(f, "Unexpected IO error occured: {:?}", io), + ValidationError::Zip(ref zip) => write!(f, "Unable to read ZIP archive: {:?}", zip), + ValidationError::InvalidDappId => write!(f, "Dapp ID is invalid. It should be 32 bytes hash of content."), + ValidationError::ManifestNotFound => write!(f, "Downloaded Dapp bundle did not contain valid manifest.json file."), + ValidationError::ManifestSerialization(ref err) => { + write!(f, "There was an error during Dapp Manifest serialization: {:?}", err) + }, + ValidationError::HashMismatch { ref expected, ref got } => { + write!(f, "Hash of downloaded content did not match. Expected:{:?}, Got:{:?}.", expected, got) + }, + } + } +} + impl From for ValidationError { fn from(err: io::Error) -> Self { ValidationError::Io(err) diff --git a/dapps/src/apps/urlhint.rs b/dapps/src/apps/urlhint.rs index cbf85b10a..30017cb00 100644 --- a/dapps/src/apps/urlhint.rs +++ b/dapps/src/apps/urlhint.rs @@ -33,8 +33,7 @@ pub struct GithubApp { impl GithubApp { pub fn url(&self) -> String { - // format!("https://github.com/{}/{}/archive/{}.zip", self.account, self.repo, self.commit.to_hex()) - format!("http://github.todr.me/{}/{}/zip/{}", self.account, self.repo, self.commit.to_hex()) + format!("https://github.com/{}/{}/archive/{}.zip", self.account, self.repo, self.commit.to_hex()) } fn commit(bytes: &[u8]) -> Option<[u8;COMMIT_LEN]> { diff --git a/dapps/src/handlers/client/mod.rs b/dapps/src/handlers/client/mod.rs index 64d24914b..4bd984bb2 100644 --- a/dapps/src/handlers/client/mod.rs +++ b/dapps/src/handlers/client/mod.rs @@ -57,7 +57,7 @@ impl Client { } } - pub fn close(mut self) { + pub fn close(self) { self.http_client.close(); self.https_client.close(); } diff --git a/dapps/src/handlers/fetch.rs b/dapps/src/handlers/fetch.rs index fd80e9729..5169af985 100644 --- a/dapps/src/handlers/fetch.rs +++ b/dapps/src/handlers/fetch.rs @@ -44,7 +44,7 @@ enum FetchState { } pub trait DappHandler { - type Error: fmt::Debug; + type Error: fmt::Debug + fmt::Display; fn validate_and_install(&self, app: PathBuf) -> Result; fn done(&self, Option<&Manifest>); @@ -165,7 +165,7 @@ impl server::Handler for AppFetcherHandler { trace!(target: "dapps", "Error while validating dapp: {:?}", e); FetchState::Error(ContentHandler::html( StatusCode::BadGateway, - format!("

Downloaded bundle does not contain valid app.

{:?}
", e), + format!("

Downloaded bundle does not contain valid app.

{}
", e), )) }, Ok(manifest) => FetchState::Done(manifest) diff --git a/logger/src/lib.rs b/logger/src/lib.rs index e9082a7b3..e672a3e28 100644 --- a/logger/src/lib.rs +++ b/logger/src/lib.rs @@ -61,6 +61,8 @@ pub fn setup_log(config: &Config) -> Result, String> { let mut builder = LogBuilder::new(); // Disable ws info logging by default. builder.filter(Some("ws"), LogLevelFilter::Warn); + // Disable rustls info logging by default. + builder.filter(Some("rustls"), LogLevelFilter::Warn); builder.filter(None, LogLevelFilter::Info); if env::var("RUST_LOG").is_ok() {