Skip to content

Upgrade dependencies and adapt empty ini properties #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,34 @@ full = ["open"]
auth = ["chrono","hmac","sha1","base64","urlencoding"]

[dependencies]
async-stream = { version = "0.3.2", optional = true }
async-trait = "0.1.50"
async-stream = { version = "0.3.5", optional = true }
async-trait = "0.1.80"
cfg-if = "1.0.0"
chrono = { version = "0.4.19", optional = true }
cidr-utils = { version = "0.5.4", optional = true }
form_urlencoded = "1.0.1"
futures-core = "0.3.15"
futures-util = "0.3.15"
hostname = { version = "0.3.1", optional = true }
http = "0.2.4"
log = "0.4.14"
once_cell = "1.8.0"
reqwest = { version = "0.11.4", features = ["cookies", "json"], default-features = false }
rust-ini = { version = "0.17.0", optional = true }
serde = { version = "1.0.126", features = ["derive"] }
serde_json = { version = "1.0.64", features = ["preserve_order"] }
systemstat = { version = "0.1.8", optional = true }
thiserror = "1.0.25"
url = "2.2.2"
chrono = { version = "0.4.26", optional = true }
cidr-utils = { version = "0.6.1", optional = true }
form_urlencoded = "1.2.1"
futures-core = "0.3.30"
futures-util = "0.3.30"
hostname = { version = "0.4.0", optional = true }
http = "1.1.0"
log = "0.4.18"
once_cell = "1.17.2"
reqwest = { version = "0.12.5", features = ["cookies", "json"], default-features = false }
rust-ini = { version = "0.21.0", optional = true }
serde = { version = "1.0.203", features = ["derive"] }
serde_json = { version = "1.0.117", features = ["preserve_order"] }
systemstat = { version = "0.2.3", optional = true }
thiserror = "1.0.61"
url = "2.5.2"
hmac = { version = "0.12.1", optional = true }
sha1 = { version = "0.10.1", optional = true }
base64 = { version = "0.13.0", optional = true }
urlencoding = { version = "2.1.0", optional = true }
sha1 = { version = "0.10.6", optional = true }
base64 = { version = "0.22.1", optional = true }
urlencoding = { version = "2.1.3", optional = true }

[dev-dependencies]
env_logger = "0.8.4"
futures = { version = "0.3.15", features = ["alloc"] }
tokio = { version = "1.7.1", features = ["full"] }
env_logger = "0.11.3"
futures = { version = "0.3.30", features = ["alloc"] }
tokio = { version = "1.29.1", features = ["full"] }

[[test]]
name = "conf"
Expand Down
2 changes: 1 addition & 1 deletion examples/watch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use apollo_client::conf::{meta::IpValue, requests::WatchRequest, ApolloConfClientBuilder};
use cidr_utils::cidr::IpCidr;
use futures_util::{pin_mut, stream::StreamExt};
use std::error::Error;
use std::{error::Error, str::FromStr};
use url::Url;

#[tokio::main]
Expand Down
3 changes: 2 additions & 1 deletion src/conf/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Display for IpValue {
IpValue::HostCidr(cidr) => {
Self::get_all_addrs()
.iter()
.find(|addr| cidr.contains(**addr))
.find(|addr| cidr.contains(*addr))
.map(|s| Cow::Owned(s.to_string()))
.unwrap_or(Cow::Borrowed("127.0.0.1"))
}
Expand All @@ -155,6 +155,7 @@ impl Display for IpValue {
#[cfg(test)]
mod tests {
use super::*;
use std::str::FromStr;

#[test]
fn test_notification_new() {
Expand Down
4 changes: 2 additions & 2 deletions src/conf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
//! use apollo_client::conf::{meta::IpValue, requests::WatchRequest, ApolloConfClientBuilder};
//! use cidr_utils::cidr::IpCidr;
//! use futures_util::{pin_mut, stream::StreamExt};
//! use std::error::Error;
//! use std::{error::Error, str::FromStr};
//! use url::Url;
//!
//! #[tokio::main]
Expand Down Expand Up @@ -236,7 +236,7 @@ impl ApolloConfClient {
/// use apollo_client::conf::{meta::IpValue, requests::WatchRequest, ApolloConfClient};
/// use cidr_utils::cidr::IpCidr;
/// use futures_util::{pin_mut, stream::StreamExt};
/// use std::error::Error;
/// use std::{error::Error, str::FromStr};
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn Error>> {
Expand Down
3 changes: 0 additions & 3 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ pub enum ApolloClientError {

#[error("this URL is cannot-be-a-base")]
UrlCannotBeABase,

#[error("configuration is empty")]
EmptyConfiguration,
}

/// Apollo api response error, when http status is not success.
Expand Down
7 changes: 3 additions & 4 deletions src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub(crate) trait PerformRequest {
/// https://www.apolloconfig.com/#/zh/usage/other-language-client-user-guide?id=_15-%e9%85%8d%e7%bd%ae%e8%ae%bf%e9%97%ae%e5%af%86%e9%92%a5
#[cfg(all(feature = "auth", feature = "conf"))]
fn signature(&self, mut request_builder: reqwest::RequestBuilder) -> reqwest::RequestBuilder {
use base64::{engine::general_purpose::STANDARD, Engine};
use hmac::{Mac, SimpleHmac};
use sha1::Sha1;
type HmacWithSha1 = SimpleHmac<Sha1>;
Expand All @@ -129,7 +130,7 @@ pub(crate) trait PerformRequest {
}
if let Ok(mut hmac) = HmacWithSha1::new_from_slice(access_key.as_bytes()) {
hmac.update(format!("{}\n{}", ts, url).as_bytes());
let sign = base64::encode(hmac.finalize().into_bytes());
let sign = STANDARD.encode(hmac.finalize().into_bytes());
request_builder = request_builder
.header(
reqwest::header::AUTHORIZATION,
Expand Down Expand Up @@ -164,9 +165,7 @@ impl PerformResponse for ini::Properties {
async fn from_response(response: Response) -> ApolloClientResult<Self> {
let content = response.text().await?;
let i = ini::Ini::load_from_str(&content)?;
Ok(i.section(None::<&'static str>)
.ok_or(crate::errors::ApolloClientError::EmptyConfiguration)?
.clone())
Ok(i.section(None::<&'static str>).cloned().unwrap_or_default())
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async fn test_cached_fetch_request() {
..Default::default()
})
.await;
assert!(matches!(result, Err(ApolloClientError::EmptyConfiguration)));
assert_eq!(result.unwrap(), Properties::new());
}
}

Expand Down
Loading