-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace vessel legacy with vessel-rs
- Loading branch information
Showing
26 changed files
with
2,480 additions
and
109 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod services; | ||
pub mod summit; | ||
pub mod vessel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use service_core::operation; | ||
|
||
operation!(ImportSucceeded, POST, "summit/importSucceeded", ACCESS_TOKEN | SERVICE_ACCOUNT | NOT_EXPIRED, req: ImportBody); | ||
operation!(ImportFailed, POST, "summit/importFailed", ACCESS_TOKEN | SERVICE_ACCOUNT | NOT_EXPIRED, req: ImportBody); | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct ImportBody { | ||
#[serde(rename = "taskID")] | ||
pub task_id: u64, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//! Handle errors | ||
use itertools::Itertools; | ||
|
||
/// Format an error chain | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//! Download local or remote files | ||
use std::{io, path::Path}; | ||
|
||
use futures::StreamExt; | ||
use sha2::{Digest, Sha256}; | ||
use thiserror::Error; | ||
use tokio::{fs::File, io::AsyncWriteExt}; | ||
use url::Url; | ||
|
||
/// Downloads the file at [`Url`] to destination [`Path`] and validates it matches | ||
/// the provided sha256sum | ||
pub async fn download_and_verify(url: Url, dest: impl AsRef<Path>, sha256sum: &str) -> Result<(), Error> { | ||
let mut stream = moss::request::get(url).await?; | ||
|
||
let mut file = File::create(dest).await.map_err(Error::CreateFile)?; | ||
let mut hasher = Sha256::default(); | ||
|
||
while let Some(bytes) = stream.next().await { | ||
let mut bytes = bytes?; | ||
|
||
hasher.update(bytes.as_ref()); | ||
|
||
file.write_all_buf(&mut bytes).await.map_err(Error::Write)?; | ||
} | ||
|
||
file.flush().await.map_err(Error::Write)?; | ||
|
||
let hash = hex::encode(hasher.finalize()); | ||
|
||
if hash != sha256sum { | ||
return Err(Error::Sha256Mismatch { | ||
expected: sha256sum.to_string(), | ||
actual: hash, | ||
}); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Request error | ||
#[derive(Debug, Error)] | ||
pub enum Error { | ||
/// Error fetching remote file | ||
#[error("fetch")] | ||
Fetch(#[source] reqwest::Error), | ||
/// Error reading local file | ||
#[error("read")] | ||
Read(#[source] io::Error), | ||
/// Error writing to file | ||
#[error("write")] | ||
Write(#[source] io::Error), | ||
/// Error creating file | ||
#[error("create file")] | ||
CreateFile(#[source] io::Error), | ||
/// Sha256 mismatch | ||
#[error("invalid sha256, expected {expected} actual {actual}")] | ||
Sha256Mismatch { | ||
/// Expected hash | ||
expected: String, | ||
/// Actual hash | ||
actual: String, | ||
}, | ||
} | ||
|
||
impl From<moss::request::Error> for Error { | ||
fn from(error: moss::request::Error) -> Self { | ||
match error { | ||
moss::request::Error::Fetch(e) => Error::Fetch(e), | ||
moss::request::Error::Read(e) => Error::Read(e), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.