Compare commits
No commits in common. "6261b3fb0348cf21d1b968d5b36ac90a51de3b69" and "3759b373511f22f5f535962f2161b35c95dce4d9" have entirely different histories.
6261b3fb03
...
3759b37351
4 changed files with 76 additions and 117 deletions
98
Cargo.lock
generated
98
Cargo.lock
generated
|
@ -107,6 +107,7 @@ dependencies = [
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"serde_yaml",
|
||||||
"sha3",
|
"sha3",
|
||||||
"tokio",
|
"tokio",
|
||||||
"url",
|
"url",
|
||||||
|
@ -141,6 +142,12 @@ dependencies = [
|
||||||
"crypto-common",
|
"crypto-common",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "equivalent"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fnv"
|
name = "fnv"
|
||||||
version = "1.0.7"
|
version = "1.0.7"
|
||||||
|
@ -171,29 +178,6 @@ version = "0.3.31"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
|
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-io"
|
|
||||||
version = "0.3.31"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-macro"
|
|
||||||
version = "0.3.31"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-sink"
|
|
||||||
version = "0.3.31"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-task"
|
name = "futures-task"
|
||||||
version = "0.3.31"
|
version = "0.3.31"
|
||||||
|
@ -207,14 +191,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
|
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-io",
|
|
||||||
"futures-macro",
|
|
||||||
"futures-sink",
|
|
||||||
"futures-task",
|
"futures-task",
|
||||||
"memchr",
|
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"pin-utils",
|
"pin-utils",
|
||||||
"slab",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -244,6 +223,12 @@ version = "0.31.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
|
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.15.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
@ -362,6 +347,16 @@ dependencies = [
|
||||||
"unicode-normalization",
|
"unicode-normalization",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indexmap"
|
||||||
|
version = "2.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da"
|
||||||
|
dependencies = [
|
||||||
|
"equivalent",
|
||||||
|
"hashbrown",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ipnet"
|
name = "ipnet"
|
||||||
version = "2.10.1"
|
version = "2.10.1"
|
||||||
|
@ -620,12 +615,10 @@ dependencies = [
|
||||||
"sync_wrapper",
|
"sync_wrapper",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-rustls",
|
"tokio-rustls",
|
||||||
"tokio-util",
|
|
||||||
"tower-service",
|
"tower-service",
|
||||||
"url",
|
"url",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-futures",
|
"wasm-bindgen-futures",
|
||||||
"wasm-streams",
|
|
||||||
"web-sys",
|
"web-sys",
|
||||||
"webpki-roots",
|
"webpki-roots",
|
||||||
"windows-registry",
|
"windows-registry",
|
||||||
|
@ -748,6 +741,19 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_yaml"
|
||||||
|
version = "0.9.34+deprecated"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"itoa",
|
||||||
|
"ryu",
|
||||||
|
"serde",
|
||||||
|
"unsafe-libyaml",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha3"
|
name = "sha3"
|
||||||
version = "0.10.8"
|
version = "0.10.8"
|
||||||
|
@ -894,19 +900,6 @@ dependencies = [
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tokio-util"
|
|
||||||
version = "0.7.12"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a"
|
|
||||||
dependencies = [
|
|
||||||
"bytes",
|
|
||||||
"futures-core",
|
|
||||||
"futures-sink",
|
|
||||||
"pin-project-lite",
|
|
||||||
"tokio",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower-service"
|
name = "tower-service"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
|
@ -971,6 +964,12 @@ dependencies = [
|
||||||
"tinyvec",
|
"tinyvec",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unsafe-libyaml"
|
||||||
|
version = "0.2.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "untrusted"
|
name = "untrusted"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
|
@ -1077,19 +1076,6 @@ version = "0.2.95"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d"
|
checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-streams"
|
|
||||||
version = "0.4.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65"
|
|
||||||
dependencies = [
|
|
||||||
"futures-util",
|
|
||||||
"js-sys",
|
|
||||||
"wasm-bindgen",
|
|
||||||
"wasm-bindgen-futures",
|
|
||||||
"web-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "web-sys"
|
name = "web-sys"
|
||||||
version = "0.3.72"
|
version = "0.3.72"
|
||||||
|
|
|
@ -6,9 +6,10 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
hex = "0"
|
hex = "0"
|
||||||
reqwest = { version = "0", features = ["json", "multipart", "rustls-tls", "stream"], default-features=false }
|
reqwest = { version = "0", features = ["json", "multipart", "rustls-tls"], default-features=false }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
serde_yaml = "0"
|
||||||
sha3 = "0"
|
sha3 = "0"
|
||||||
tokio = { version = "1", features = ["fs", "macros", "rt-multi-thread"] }
|
tokio = { version = "1", features = ["fs", "macros", "rt-multi-thread"] }
|
||||||
url = { version = "2", features = ["serde"] }
|
url = { version = "2", features = ["serde"] }
|
||||||
|
|
72
src/main.rs
72
src/main.rs
|
@ -58,21 +58,21 @@ async fn build_request(
|
||||||
request_builder
|
request_builder
|
||||||
.form(&serde_json::from_slice::<HashMap<String, String>>(&buffer)?)
|
.form(&serde_json::from_slice::<HashMap<String, String>>(&buffer)?)
|
||||||
}
|
}
|
||||||
model::Body::Multipart(mp) => {
|
model::Body::Multipart(fbvec) => {
|
||||||
let mut form = reqwest::multipart::Form::new();
|
let mut form = reqwest::multipart::Form::new();
|
||||||
for (name, path) in &mp.files {
|
for mb in fbvec {
|
||||||
let mb_: PathBuf = srcpath_.to_owned().join(path);
|
let mb_ = srcpath_.to_owned().join(mb);
|
||||||
form = form.file(name.clone(), mb_).await?;
|
|
||||||
}
|
|
||||||
if let Some(mp_form) = &mp.form {
|
|
||||||
let mut buffer = Vec::<u8>::new();
|
let mut buffer = Vec::<u8>::new();
|
||||||
let mut file = tokio::fs::File::open(srcpath_.to_owned().join(mp_form)).await?;
|
let mut file = tokio::fs::File::open(&mb_).await?;
|
||||||
let read = file.read_buf(&mut buffer).await?;
|
let read = file.read_buf(&mut buffer).await?;
|
||||||
buffer.truncate(read);
|
buffer.truncate(read);
|
||||||
let form_hash_map: HashMap<String, String> = serde_json::from_slice(&buffer)?;
|
let name = mb_
|
||||||
for (k, v) in form_hash_map.into_iter() {
|
.file_name()
|
||||||
form = form.text(k, v);
|
.ok_or_else(|| anyhow!("Failed to get file name"))?
|
||||||
}
|
.to_str()
|
||||||
|
.ok_or_else(|| anyhow!("Failed to get file name"))?
|
||||||
|
.to_string();
|
||||||
|
form = form.part(name, reqwest::multipart::Part::bytes(buffer));
|
||||||
}
|
}
|
||||||
request_builder.multipart(form)
|
request_builder.multipart(form)
|
||||||
}
|
}
|
||||||
|
@ -85,17 +85,11 @@ async fn build_request(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn check(input: model::CheckInput) -> Result<model::CheckOutput> {
|
async fn check(input: model::CheckInput) -> Result<model::CheckOutput> {
|
||||||
eprintln!("Calling {:?} {}", &input.source.method, &input.source.url);
|
|
||||||
|
|
||||||
let (client, request) = build_request(&input.source, None).await?;
|
let (client, request) = build_request(&input.source, None).await?;
|
||||||
let mut response = client.execute(request).await?;
|
let mut response = client.execute(request).await?;
|
||||||
|
|
||||||
eprintln!("Response code {}", &response.status());
|
|
||||||
eprintln!("Headers {:?}", &response.headers());
|
|
||||||
|
|
||||||
Ok(model::CheckOutput(
|
Ok(model::CheckOutput(
|
||||||
match input.source.version_check_method {
|
match input.source.version_check_method {
|
||||||
model::VersionCheckMethod::None => vec![model::Version::None("none".to_string())],
|
model::VersionCheckMethod::None => vec![model::Version::None],
|
||||||
model::VersionCheckMethod::Hash => {
|
model::VersionCheckMethod::Hash => {
|
||||||
let mut hasher = sha3::Sha3_256::new();
|
let mut hasher = sha3::Sha3_256::new();
|
||||||
while let Some(chunk) = response.chunk().await? {
|
while let Some(chunk) = response.chunk().await? {
|
||||||
|
@ -121,18 +115,12 @@ async fn in_(input: model::InInput, dest: &Path) -> Result<model::InOutput> {
|
||||||
version: input.version,
|
version: input.version,
|
||||||
params: input.params,
|
params: input.params,
|
||||||
};
|
};
|
||||||
|
|
||||||
eprintln!("Calling {:?} {}", &input.source.method, &input.source.url);
|
|
||||||
|
|
||||||
let (client, request) = build_request(&input.source, None).await?;
|
let (client, request) = build_request(&input.source, None).await?;
|
||||||
let mut response = client.execute(request).await?;
|
let mut response = client.execute(request).await?;
|
||||||
|
|
||||||
eprintln!("Response code {}", &response.status());
|
|
||||||
eprintln!("Headers {:?}", &response.headers());
|
|
||||||
|
|
||||||
let dest_code = dest.to_owned().join("code");
|
let dest_code = dest.to_owned().join("code");
|
||||||
let dest_headers = dest.to_owned().join("headers");
|
let dest_headers = dest.to_owned().join("headers");
|
||||||
let dest_bytes = dest.to_owned().join("body");
|
let dest_bytes = dest.to_owned().join("output");
|
||||||
|
|
||||||
let mut dest_code_writer = tokio::io::BufWriter::new(tokio::fs::File::create(dest_code).await?);
|
let mut dest_code_writer = tokio::io::BufWriter::new(tokio::fs::File::create(dest_code).await?);
|
||||||
dest_code_writer
|
dest_code_writer
|
||||||
|
@ -170,7 +158,7 @@ async fn in_(input: model::InInput, dest: &Path) -> Result<model::InOutput> {
|
||||||
|
|
||||||
let out = model::InOutput {
|
let out = model::InOutput {
|
||||||
version: match input.source.version_check_method {
|
version: match input.source.version_check_method {
|
||||||
model::VersionCheckMethod::None => model::Version::None("none".to_string()),
|
model::VersionCheckMethod::None => model::Version::None,
|
||||||
model::VersionCheckMethod::Hash => model::Version::Hash(hex::encode(hash)),
|
model::VersionCheckMethod::Hash => model::Version::Hash(hex::encode(hash)),
|
||||||
model::VersionCheckMethod::Header(headername) => {
|
model::VersionCheckMethod::Header(headername) => {
|
||||||
let headervalue: &HeaderValue = response
|
let headervalue: &HeaderValue = response
|
||||||
|
@ -182,13 +170,11 @@ async fn in_(input: model::InInput, dest: &Path) -> Result<model::InOutput> {
|
||||||
},
|
},
|
||||||
metadata: vec![],
|
metadata: vec![],
|
||||||
};
|
};
|
||||||
if let Some(input_version) = &input.version {
|
if out.version != input.version {
|
||||||
if out.version != *input_version {
|
return Err(anyhow!(format!(
|
||||||
return Err(anyhow!(format!(
|
"Did not get correct version of resource, requested '{:?}', got '{:?}'",
|
||||||
"Did not get correct version of resource, requested '{:?}', got '{:?}'",
|
input.version, out.version
|
||||||
input.version, out.version
|
)));
|
||||||
)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
@ -198,20 +184,18 @@ async fn out(input: model::OutInput, src: &Path) -> Result<model::OutOutput> {
|
||||||
source: input.source.merge_params(&input.params),
|
source: input.source.merge_params(&input.params),
|
||||||
params: input.params,
|
params: input.params,
|
||||||
};
|
};
|
||||||
|
|
||||||
eprintln!("Calling {:?} {}", &input.source.method, &input.source.url);
|
|
||||||
|
|
||||||
let (client, request) = build_request(&input.source, Some(src)).await?;
|
let (client, request) = build_request(&input.source, Some(src)).await?;
|
||||||
let response = client.execute(request).await?;
|
let response = client.execute(request).await?;
|
||||||
let err = response.error_for_status_ref().map(|_| ());
|
response.error_for_status()?;
|
||||||
|
let version = check(model::CheckInput {
|
||||||
eprintln!("Response code {}", &response.status());
|
source: input.source.clone(),
|
||||||
eprintln!("Headers {:?}", &response.headers());
|
version: model::Version::None,
|
||||||
eprintln!("Body {:?}", response.text().await?);
|
})
|
||||||
|
.await?
|
||||||
err?;
|
.0[0]
|
||||||
|
.clone();
|
||||||
Ok(model::OutOutput {
|
Ok(model::OutOutput {
|
||||||
version: model::Version::None("none".to_string()),
|
version,
|
||||||
metadata: vec![],
|
metadata: vec![],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
20
src/model.rs
20
src/model.rs
|
@ -1,6 +1,5 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
@ -55,20 +54,12 @@ pub enum Auth {
|
||||||
Bearer(String),
|
Bearer(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct BodyMultipart {
|
|
||||||
#[serde(default)]
|
|
||||||
pub files: HashMap<String, PathBuf>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub form: Option<PathBuf>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum Body {
|
pub enum Body {
|
||||||
Raw(PathBuf),
|
Raw(PathBuf),
|
||||||
Form(PathBuf),
|
Form(PathBuf),
|
||||||
Multipart(BodyMultipart),
|
Multipart(Vec<PathBuf>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)]
|
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)]
|
||||||
|
@ -138,7 +129,7 @@ impl Source {
|
||||||
pub enum Version {
|
pub enum Version {
|
||||||
Header(String),
|
Header(String),
|
||||||
Hash(String),
|
Hash(String),
|
||||||
None(String),
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
||||||
|
@ -159,22 +150,19 @@ pub struct Params {
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct CheckInput {
|
pub struct CheckInput {
|
||||||
pub source: Source,
|
pub source: Source,
|
||||||
#[serde(default)]
|
pub version: Version,
|
||||||
pub version: Option<Version>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct InInput {
|
pub struct InInput {
|
||||||
pub source: Source,
|
pub source: Source,
|
||||||
pub version: Option<Version>,
|
pub version: Version,
|
||||||
#[serde(default)]
|
|
||||||
pub params: Params,
|
pub params: Params,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct OutInput {
|
pub struct OutInput {
|
||||||
pub source: Source,
|
pub source: Source,
|
||||||
#[serde(default)]
|
|
||||||
pub params: Params,
|
pub params: Params,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue