diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00c3ddb..2e0ba42 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -91,4 +91,14 @@ jobs: - name: Upload coverage to Codecov uses: codecov/codecov-action@v1 with: - files: ./coverage.lcov \ No newline at end of file + files: ./coverage.lcov + + semver: + name: semverver + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Check semver + uses: obi1kenobi/cargo-semver-checks-action@v1 + with: + crate-name: hawkbit \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f64864c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rust-analyzer.cargo.allFeatures": true +} \ No newline at end of file diff --git a/hawkbit/Cargo.toml b/hawkbit/Cargo.toml index 6dcc370..18f8d64 100644 --- a/hawkbit/Cargo.toml +++ b/hawkbit/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "hawkbit" -version = "0.6.0" +version = "0.7.0" authors = ["Guillaume Desmottes "] -edition = "2018" +edition = "2021" categories = ["api-bindings"] description = "Client side API to interact with Eclipse hawkBit" license = "MIT OR Apache-2.0" @@ -12,29 +12,29 @@ documentation = "https://docs.rs/hawkbit_mock/" [dependencies] reqwest = { version = "0.11", features = ["json", "stream"] } -tokio = { version = "1.1", features = ["time", "fs"] } +tokio = { version = "1.21", features = ["time", "fs"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" -url = "2.2" -strum = { version = "0.21", features = ["derive"] } +url = "2.3" +strum = { version = "0.24", features = ["derive"] } cfg-if = "1.0" -digest = { version = "0.9", optional = true } -md-5 = { version = "0.9", optional = true } -sha-1 = { version = "0.9", optional = true } -sha2 = { version = "0.9", optional = true } +digest = { version = "0.10", optional = true } +md-5 = { version = "0.10", optional = true } +sha-1 = { version = "0.10", optional = true } +sha2 = { version = "0.10", optional = true } generic-array = {version = "0.14", optional = true } futures = "0.3" -bytes = "1.0" +bytes = "1.2" [dev-dependencies] hawkbit_mock = { path = "../hawkbit_mock/" } structopt = "0.3" anyhow = "1.0" log = "0.4" -env_logger = "0.8" +env_logger = "0.9" tempdir = "0.3" -assert_matches = "1.4" +assert_matches = "1.5" [features] hash-digest= ["digest", "generic-array"] diff --git a/hawkbit/src/ddi/cancel_action.rs b/hawkbit/src/ddi/cancel_action.rs index 0cf7217..a6fbec8 100644 --- a/hawkbit/src/ddi/cancel_action.rs +++ b/hawkbit/src/ddi/cancel_action.rs @@ -65,6 +65,7 @@ impl CancelAction { #[derive(Debug, Deserialize)] struct CancelReply { + #[allow(dead_code)] id: String, #[serde(rename = "cancelAction")] cancel_action: CancelActionReply, diff --git a/hawkbit/src/ddi/deployment_base.rs b/hawkbit/src/ddi/deployment_base.rs index f8922db..c2ebdfd 100644 --- a/hawkbit/src/ddi/deployment_base.rs +++ b/hawkbit/src/ddi/deployment_base.rs @@ -48,6 +48,7 @@ struct Reply { id: String, deployment: Deployment, #[serde(rename = "actionHistory")] + #[allow(dead_code)] action_history: Option, } @@ -61,7 +62,7 @@ struct Deployment { } /// How the download or update should be processed by the target. -#[derive(Debug, Deserialize, Serialize, Copy, Clone, PartialEq)] +#[derive(Debug, Deserialize, Serialize, Copy, Clone, PartialEq, Eq)] #[serde(rename_all = "lowercase")] pub enum Type { /// Do not process yet @@ -73,7 +74,7 @@ pub enum Type { } /// Separation of download and installation by defining a maintenance window for the installation. -#[derive(Debug, Deserialize, Serialize, Copy, Clone, PartialEq)] +#[derive(Debug, Deserialize, Serialize, Copy, Clone, PartialEq, Eq)] #[serde(rename_all = "lowercase")] pub enum MaintenanceWindow { /// Maintenance window is available @@ -109,8 +110,11 @@ struct ArtifactInternal { #[derive(Debug, Deserialize, Clone)] struct Hashes { + #[cfg(feature = "hash-sha1")] sha1: String, + #[cfg(feature = "hash-md5")] md5: String, + #[cfg(feature = "hash-sha256")] sha256: String, } @@ -192,6 +196,7 @@ impl<'de> Deserialize<'de> for Links { #[derive(Debug)] struct Download { content: Link, + #[allow(dead_code)] md5sum: Option, } @@ -205,8 +210,10 @@ struct Links { #[derive(Debug, Deserialize)] struct ActionHistory { + #[allow(dead_code)] status: String, #[serde(default)] + #[allow(dead_code)] messages: Vec, } @@ -396,7 +403,7 @@ impl<'a> Artifact<'a> { .links .https .as_ref() - .or_else(|| self.artifact.links.http.as_ref()) + .or(self.artifact.links.http.as_ref()) .expect("Missing content link in for artifact"); let resp = self @@ -506,6 +513,7 @@ impl<'a> Artifact<'a> { #[derive(Debug)] pub struct DownloadedArtifact { file: PathBuf, + #[allow(dead_code)] hashes: Hashes, } @@ -516,6 +524,7 @@ cfg_if::cfg_if! { task::Poll, }; use digest::Digest; + use digest::OutputSizeUser; const HASH_BUFFER_SIZE: usize = 4096; @@ -538,8 +547,9 @@ cfg_if::cfg_if! { struct DownloadHasher where T: Digest, - ::OutputSize: core::ops::Add, - <::OutputSize as core::ops::Add>::Output: generic_array::ArrayLength, + ::OutputSize: core::ops::Add, + <::OutputSize as core::ops::Add>::Output: generic_array::ArrayLength, + { hasher: T, expected: String, @@ -549,8 +559,8 @@ cfg_if::cfg_if! { impl DownloadHasher where T: Digest, - ::OutputSize: core::ops::Add, - <::OutputSize as core::ops::Add>::Output: generic_array::ArrayLength + ::OutputSize: core::ops::Add, + <::OutputSize as core::ops::Add>::Output: generic_array::ArrayLength, { fn update(&mut self, data: impl AsRef<[u8]>) { self.hasher.update(data); @@ -603,8 +613,8 @@ cfg_if::cfg_if! { struct DownloadStreamHash where T: Digest, - ::OutputSize: core::ops::Add, - <::OutputSize as core::ops::Add>::Output: generic_array::ArrayLength, + ::OutputSize: core::ops::Add, + <::OutputSize as core::ops::Add>::Output: generic_array::ArrayLength, { stream: Box> + Unpin + Send + Sync>, hasher: DownloadHasher, @@ -613,10 +623,10 @@ cfg_if::cfg_if! { impl Stream for DownloadStreamHash where T: Digest, - ::OutputSize: core::ops::Add, - <::OutputSize as core::ops::Add>::Output: generic_array::ArrayLength, T: Unpin, T: Clone, + ::OutputSize: core::ops::Add, + <::OutputSize as core::ops::Add>::Output: generic_array::ArrayLength, { type Item = Result; @@ -648,7 +658,7 @@ cfg_if::cfg_if! { } } -impl<'a> DownloadedArtifact { +impl DownloadedArtifact { fn new(file: PathBuf, hashes: Hashes) -> Self { Self { file, hashes } } @@ -662,8 +672,9 @@ impl<'a> DownloadedArtifact { async fn hash(&self, mut hasher: DownloadHasher) -> Result<(), Error> where T: Digest, - ::OutputSize: core::ops::Add, - <::OutputSize as core::ops::Add>::Output: generic_array::ArrayLength, + ::OutputSize: core::ops::Add, + <::OutputSize as core::ops::Add>::Output: + generic_array::ArrayLength, { use tokio::io::AsyncReadExt; diff --git a/hawkbit_mock/Cargo.toml b/hawkbit_mock/Cargo.toml index 554d53d..f60b48a 100644 --- a/hawkbit_mock/Cargo.toml +++ b/hawkbit_mock/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/collabora/hawkbit-rs" documentation = "https://docs.rs/hawkbit/" [dependencies] -hawkbit = { version = "0.6.0", path = "../hawkbit/" } -httpmock = "0.5.4" +hawkbit = { version = "0.7.0", path = "../hawkbit/" } +httpmock = "0.6.6" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/hawkbit_mock/src/ddi.rs b/hawkbit_mock/src/ddi.rs index 2a4392c..514257c 100644 --- a/hawkbit_mock/src/ddi.rs +++ b/hawkbit_mock/src/ddi.rs @@ -30,7 +30,7 @@ use std::{ use httpmock::{ Method::{GET, POST, PUT}, - MockRef, MockRefExt, MockServer, + Mock, MockExt, MockServer, }; use serde_json::{json, Map, Value}; @@ -178,7 +178,7 @@ impl Target { self.cancel_action.borrow().as_ref(), )); - let mut old = MockRef::new(old, &self.server); + let mut old = Mock::new(old, &self.server); old.delete(); } @@ -349,7 +349,7 @@ impl Target { finished: Finished, progress: Option, details: Vec<&str>, - ) -> MockRef<'_> { + ) -> Mock<'_> { self.server.mock(|when, then| { let expected = match progress { Some(progress) => json!({ @@ -471,7 +471,7 @@ impl Target { execution: Execution, finished: Finished, details: Vec<&str>, - ) -> MockRef<'_> { + ) -> Mock<'_> { self.server.mock(|when, then| { let expected = json!({ "id": cancel_id, @@ -499,14 +499,14 @@ impl Target { /// Return the number of times the poll API has been called by the client. pub fn poll_hits(&self) -> usize { - let mock = MockRef::new(self.poll.get(), &self.server); + let mock = Mock::new(self.poll.get(), &self.server); mock.hits() } /// Return the number of times the target configuration has been uploaded by the client. pub fn config_data_hits(&self) -> usize { self.config_data.borrow().as_ref().map_or(0, |m| { - let mock = MockRef::new(m.mock, &self.server); + let mock = Mock::new(m.mock, &self.server); mock.hits() }) } @@ -514,7 +514,7 @@ impl Target { /// Return the number of times the deployment details have been fetched by the client. pub fn deployment_hits(&self) -> usize { self.deployment.borrow().as_ref().map_or(0, |m| { - let mock = MockRef::new(m.mock, &self.server); + let mock = Mock::new(m.mock, &self.server); mock.hits() }) } @@ -522,7 +522,7 @@ impl Target { /// Return the number of times the cancel action URL has been fetched by the client. pub fn cancel_action_hits(&self) -> usize { self.cancel_action.borrow().as_ref().map_or(0, |m| { - let mock = MockRef::new(m.mock, &self.server); + let mock = Mock::new(m.mock, &self.server); mock.hits() }) } @@ -536,7 +536,7 @@ struct PendingAction { impl Drop for PendingAction { fn drop(&mut self) { - let mut mock = MockRef::new(self.mock, &self.server); + let mut mock = Mock::new(self.mock, &self.server); mock.delete(); } }