Skip to content

Commit 48a2559

Browse files
authored
Upgrade dependencies and adapt empty ini properties (#18)
1 parent b9a1967 commit 48a2559

File tree

7 files changed

+33
-36
lines changed

7 files changed

+33
-36
lines changed

Cargo.toml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,34 @@ full = ["open"]
3030
auth = ["chrono","hmac","sha1","base64","urlencoding"]
3131

3232
[dependencies]
33-
async-stream = { version = "0.3.2", optional = true }
34-
async-trait = "0.1.50"
33+
async-stream = { version = "0.3.5", optional = true }
34+
async-trait = "0.1.80"
3535
cfg-if = "1.0.0"
36-
chrono = { version = "0.4.19", optional = true }
37-
cidr-utils = { version = "0.5.4", optional = true }
38-
form_urlencoded = "1.0.1"
39-
futures-core = "0.3.15"
40-
futures-util = "0.3.15"
41-
hostname = { version = "0.3.1", optional = true }
42-
http = "0.2.4"
43-
log = "0.4.14"
44-
once_cell = "1.8.0"
45-
reqwest = { version = "0.11.4", features = ["cookies", "json"], default-features = false }
46-
rust-ini = { version = "0.17.0", optional = true }
47-
serde = { version = "1.0.126", features = ["derive"] }
48-
serde_json = { version = "1.0.64", features = ["preserve_order"] }
49-
systemstat = { version = "0.1.8", optional = true }
50-
thiserror = "1.0.25"
51-
url = "2.2.2"
36+
chrono = { version = "0.4.26", optional = true }
37+
cidr-utils = { version = "0.6.1", optional = true }
38+
form_urlencoded = "1.2.1"
39+
futures-core = "0.3.30"
40+
futures-util = "0.3.30"
41+
hostname = { version = "0.4.0", optional = true }
42+
http = "1.1.0"
43+
log = "0.4.18"
44+
once_cell = "1.17.2"
45+
reqwest = { version = "0.12.5", features = ["cookies", "json"], default-features = false }
46+
rust-ini = { version = "0.21.0", optional = true }
47+
serde = { version = "1.0.203", features = ["derive"] }
48+
serde_json = { version = "1.0.117", features = ["preserve_order"] }
49+
systemstat = { version = "0.2.3", optional = true }
50+
thiserror = "1.0.61"
51+
url = "2.5.2"
5252
hmac = { version = "0.12.1", optional = true }
53-
sha1 = { version = "0.10.1", optional = true }
54-
base64 = { version = "0.13.0", optional = true }
55-
urlencoding = { version = "2.1.0", optional = true }
53+
sha1 = { version = "0.10.6", optional = true }
54+
base64 = { version = "0.22.1", optional = true }
55+
urlencoding = { version = "2.1.3", optional = true }
5656

5757
[dev-dependencies]
58-
env_logger = "0.8.4"
59-
futures = { version = "0.3.15", features = ["alloc"] }
60-
tokio = { version = "1.7.1", features = ["full"] }
58+
env_logger = "0.11.3"
59+
futures = { version = "0.3.30", features = ["alloc"] }
60+
tokio = { version = "1.29.1", features = ["full"] }
6161

6262
[[test]]
6363
name = "conf"

examples/watch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use apollo_client::conf::{meta::IpValue, requests::WatchRequest, ApolloConfClientBuilder};
22
use cidr_utils::cidr::IpCidr;
33
use futures_util::{pin_mut, stream::StreamExt};
4-
use std::error::Error;
4+
use std::{error::Error, str::FromStr};
55
use url::Url;
66

77
#[tokio::main]

src/conf/meta.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl Display for IpValue {
141141
IpValue::HostCidr(cidr) => {
142142
Self::get_all_addrs()
143143
.iter()
144-
.find(|addr| cidr.contains(**addr))
144+
.find(|addr| cidr.contains(*addr))
145145
.map(|s| Cow::Owned(s.to_string()))
146146
.unwrap_or(Cow::Borrowed("127.0.0.1"))
147147
}
@@ -155,6 +155,7 @@ impl Display for IpValue {
155155
#[cfg(test)]
156156
mod tests {
157157
use super::*;
158+
use std::str::FromStr;
158159

159160
#[test]
160161
fn test_notification_new() {

src/conf/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
//! use apollo_client::conf::{meta::IpValue, requests::WatchRequest, ApolloConfClientBuilder};
4949
//! use cidr_utils::cidr::IpCidr;
5050
//! use futures_util::{pin_mut, stream::StreamExt};
51-
//! use std::error::Error;
51+
//! use std::{error::Error, str::FromStr};
5252
//! use url::Url;
5353
//!
5454
//! #[tokio::main]
@@ -236,7 +236,7 @@ impl ApolloConfClient {
236236
/// use apollo_client::conf::{meta::IpValue, requests::WatchRequest, ApolloConfClient};
237237
/// use cidr_utils::cidr::IpCidr;
238238
/// use futures_util::{pin_mut, stream::StreamExt};
239-
/// use std::error::Error;
239+
/// use std::{error::Error, str::FromStr};
240240
///
241241
/// #[tokio::main]
242242
/// async fn main() -> Result<(), Box<dyn Error>> {

src/errors.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ pub enum ApolloClientError {
3232

3333
#[error("this URL is cannot-be-a-base")]
3434
UrlCannotBeABase,
35-
36-
#[error("configuration is empty")]
37-
EmptyConfiguration,
3835
}
3936

4037
/// Apollo api response error, when http status is not success.

src/meta.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub(crate) trait PerformRequest {
108108
/// 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
109109
#[cfg(all(feature = "auth", feature = "conf"))]
110110
fn signature(&self, mut request_builder: reqwest::RequestBuilder) -> reqwest::RequestBuilder {
111+
use base64::{engine::general_purpose::STANDARD, Engine};
111112
use hmac::{Mac, SimpleHmac};
112113
use sha1::Sha1;
113114
type HmacWithSha1 = SimpleHmac<Sha1>;
@@ -129,7 +130,7 @@ pub(crate) trait PerformRequest {
129130
}
130131
if let Ok(mut hmac) = HmacWithSha1::new_from_slice(access_key.as_bytes()) {
131132
hmac.update(format!("{}\n{}", ts, url).as_bytes());
132-
let sign = base64::encode(hmac.finalize().into_bytes());
133+
let sign = STANDARD.encode(hmac.finalize().into_bytes());
133134
request_builder = request_builder
134135
.header(
135136
reqwest::header::AUTHORIZATION,
@@ -164,9 +165,7 @@ impl PerformResponse for ini::Properties {
164165
async fn from_response(response: Response) -> ApolloClientResult<Self> {
165166
let content = response.text().await?;
166167
let i = ini::Ini::load_from_str(&content)?;
167-
Ok(i.section(None::<&'static str>)
168-
.ok_or(crate::errors::ApolloClientError::EmptyConfiguration)?
169-
.clone())
168+
Ok(i.section(None::<&'static str>).cloned().unwrap_or_default())
170169
}
171170
}
172171

tests/conf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async fn test_cached_fetch_request() {
9595
..Default::default()
9696
})
9797
.await;
98-
assert!(matches!(result, Err(ApolloClientError::EmptyConfiguration)));
98+
assert_eq!(result.unwrap(), Properties::new());
9999
}
100100
}
101101

0 commit comments

Comments
 (0)