Skip to content

Commit fe436a0

Browse files
committed
Update dependencies of the Elasticsearch package
1 parent e04f08e commit fe436a0

File tree

11 files changed

+80
-152
lines changed

11 files changed

+80
-152
lines changed

elasticsearch/Cargo.toml

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,32 @@ native-tls = ["reqwest/native-tls"]
2626
rustls-tls = ["reqwest/rustls-tls"]
2727

2828
[dependencies]
29-
base64 = "^0.11"
30-
bytes = "^1.0"
31-
dyn-clone = "~1"
32-
lazy_static = "1.4"
33-
percent-encoding = "2.1.0"
34-
reqwest = { version = "~0.11", default-features = false, features = ["gzip", "json"] }
35-
url = "^2.1"
36-
serde = { version = "~1", features = ["derive"] }
37-
serde_json = "~1"
38-
serde_with = "~1"
39-
void = "1.0.2"
29+
base64 = "0.22"
30+
bytes = "1"
31+
dyn-clone = "1"
32+
lazy_static = "1"
33+
percent-encoding = "2"
34+
reqwest = { version = "0.12", default-features = false, features = ["gzip", "json"] }
35+
url = "2"
36+
serde = { version = "1", features = ["derive"] }
37+
serde_json = "1"
38+
serde_with = "1"
39+
void = "1"
4040

4141
[dev-dependencies]
42-
chrono = { version = "^0.4", features = ["serde"] }
43-
clap = "~2"
44-
failure = "0.1.5"
45-
futures = "0.3.1"
46-
http = "0.2"
47-
hyper = { version = "0.14", default-features = false, features = ["tcp", "stream", "server"] }
48-
os_type = "2.2"
49-
regex="1.4"
50-
sysinfo = "0.12.0"
51-
textwrap = "^0.11"
52-
tokio = { version = "1.0", default-features = false, features = ["macros", "net", "time", "rt-multi-thread"] }
53-
xml-rs = "^0.8"
42+
chrono = { version = "0.4", features = ["serde"] }
43+
clap = { version = "4", features = ["env"]}
44+
failure = "0.1"
45+
futures = "0.3"
46+
http = "1"
47+
axum = "0.7"
48+
hyper = { version = "1", features = ["server", "http1"] }
49+
os_type = "2"
50+
regex="1"
51+
#sysinfo = "0.31"
52+
textwrap = "0.16"
53+
tokio = { version = "1", default-features = false, features = ["macros", "net", "time", "rt-multi-thread"] }
54+
xml-rs = "0.8"
5455

5556
[build-dependencies]
56-
rustc_version = "0.2"
57+
rustc_version = "0.4"

elasticsearch/examples/cat_indices.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use elasticsearch::{
2424
http::transport::{SingleNodeConnectionPool, TransportBuilder},
2525
Elasticsearch, Error, DEFAULT_ADDRESS,
2626
};
27-
use sysinfo::SystemExt;
2827
use url::Url;
2928

3029
#[tokio::main]
@@ -51,12 +50,6 @@ fn create_client() -> Result<Elasticsearch, Error> {
5150
}
5251
}
5352

54-
/// Determines if Fiddler.exe proxy process is running
55-
fn running_proxy() -> bool {
56-
let system = sysinfo::System::new();
57-
!system.get_process_by_name("Fiddler").is_empty()
58-
}
59-
6053
let mut url = Url::parse(cluster_addr().as_ref()).unwrap();
6154

6255
// if the url is https and specifies a username and password, remove from the url and set credentials
@@ -100,11 +93,6 @@ fn create_client() -> Result<Elasticsearch, Error> {
10093
None => builder,
10194
};
10295

103-
if running_proxy() {
104-
let proxy_url = Url::parse("http://localhost:8888").unwrap();
105-
builder = builder.proxy(proxy_url, None, None);
106-
}
107-
10896
let transport = builder.build()?;
10997
Ok(Elasticsearch::new(transport))
11098
}

elasticsearch/examples/index_questions_answers/main.rs

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#[macro_use]
2020
extern crate serde_json;
2121

22-
use clap::{App, Arg};
22+
use clap::{Arg, Command};
2323
#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
2424
use elasticsearch::cert::CertificateValidation;
2525
use elasticsearch::{
@@ -31,7 +31,6 @@ use elasticsearch::{
3131
BulkOperation, BulkParts, Elasticsearch, Error, DEFAULT_ADDRESS,
3232
};
3333
use serde_json::Value;
34-
use sysinfo::SystemExt;
3534
use url::Url;
3635

3736
mod stack_overflow;
@@ -49,58 +48,50 @@ static POSTS_INDEX: &'static str = "posts";
4948
// TODO: Concurrent bulk requests
5049
#[tokio::main]
5150
pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
52-
let matches = App::new("index_questions_answers")
51+
let matches = Command::new("index_questions_answers")
5352
.about(
5453
"indexes Stack Overflow questions and answers into Elasticsearch with the Rust client",
5554
)
5655
.arg(
57-
Arg::with_name("path")
58-
.short("p")
56+
Arg::new("path")
57+
.short('p')
5958
.long("path")
6059
.value_name("PATH")
6160
.help("The path to the Posts.xml file containing questions and answers. Can be obtained from https://archive.org/download/stackexchange/stackoverflow.com-Posts.7z (large file)")
6261
.required(true)
63-
.takes_value(true),
6462
)
6563
.arg(
66-
Arg::with_name("limit")
67-
.short("l")
64+
Arg::new("limit")
65+
.short('l')
6866
.long("limit")
6967
.value_name("LIMIT")
7068
.help("The number of questions and answers from Posts.xml to index")
7169
.required(false)
72-
.takes_value(true),
7370
)
7471
.arg(
75-
Arg::with_name("size")
76-
.short("s")
72+
Arg::new("size")
73+
.short('s')
7774
.long("size")
7875
.value_name("SIZE")
7976
.help("The number of documents in each bulk request")
8077
.required(false)
81-
.takes_value(true),
8278
)
8379
.arg(
84-
Arg::with_name("delete")
85-
.short("d")
80+
Arg::new("delete")
81+
.short('d')
8682
.long("delete")
8783
.help("Whether to delete the index before indexing")
8884
.required(false)
89-
.takes_value(false),
9085
)
9186
.get_matches();
9287

93-
let path = matches.value_of("path").expect("missing 'path' argument");
94-
let limit = match matches.value_of("limit") {
95-
Some(l) => Some(l.parse::<usize>()?),
96-
_ => None,
97-
};
98-
let size = match matches.value_of("size") {
99-
Some(l) => l.parse::<usize>()?,
100-
_ => 1000,
101-
};
88+
let path = matches
89+
.get_one::<String>("path")
90+
.expect("missing 'path' argument");
91+
let limit = matches.get_one::<usize>("limit").copied();
92+
let size = matches.get_one::<usize>("size").copied().unwrap_or(1000);
10293

103-
let delete = matches.is_present("delete");
94+
let delete = matches.contains_id("delete");
10495
let client = create_client()?;
10596

10697
create_index_if_not_exists(&client, delete).await?;
@@ -368,12 +359,6 @@ fn create_client() -> Result<Elasticsearch, Error> {
368359
}
369360
}
370361

371-
/// Determines if Fiddler.exe proxy process is running
372-
fn running_proxy() -> bool {
373-
let system = sysinfo::System::new();
374-
!system.get_process_by_name("Fiddler").is_empty()
375-
}
376-
377362
let mut url = Url::parse(cluster_addr().as_ref()).unwrap();
378363

379364
// if the url is https and specifies a username and password, remove from the url and set credentials
@@ -417,11 +402,6 @@ fn create_client() -> Result<Elasticsearch, Error> {
417402
None => builder,
418403
};
419404

420-
if running_proxy() {
421-
let proxy_url = Url::parse("http://localhost:8888").unwrap();
422-
builder = builder.proxy(proxy_url, None, None);
423-
}
424-
425405
let transport = builder.build()?;
426406
Ok(Elasticsearch::new(transport))
427407
}

elasticsearch/examples/search_questions/main.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use elasticsearch::{
2525
};
2626
use serde_json::{json, Value};
2727
use std::env;
28-
use sysinfo::SystemExt;
2928
use url::Url;
3029
mod stack_overflow;
3130
use stack_overflow::*;
@@ -118,12 +117,6 @@ fn create_client() -> Result<Elasticsearch, Error> {
118117
}
119118
}
120119

121-
/// Determines if Fiddler.exe proxy process is running
122-
fn running_proxy() -> bool {
123-
let system = sysinfo::System::new();
124-
!system.get_process_by_name("Fiddler").is_empty()
125-
}
126-
127120
let mut url = Url::parse(cluster_addr().as_ref()).unwrap();
128121

129122
// if the url is https and specifies a username and password, remove from the url and set credentials
@@ -167,11 +160,6 @@ fn create_client() -> Result<Elasticsearch, Error> {
167160
None => builder,
168161
};
169162

170-
if running_proxy() {
171-
let proxy_url = Url::parse("http://localhost:8888").unwrap();
172-
builder = builder.proxy(proxy_url, None, None);
173-
}
174-
175163
let transport = builder.build()?;
176164
Ok(Elasticsearch::new(transport))
177165
}

elasticsearch/examples/search_questions_answers/main.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use elasticsearch::{
2828
};
2929
use serde_json::Value;
3030
use std::env;
31-
use sysinfo::SystemExt;
3231
use url::Url;
3332
mod stack_overflow;
3433
use stack_overflow::*;
@@ -105,12 +104,6 @@ fn create_client() -> Result<Elasticsearch, Error> {
105104
}
106105
}
107106

108-
/// Determines if Fiddler.exe proxy process is running
109-
fn running_proxy() -> bool {
110-
let system = sysinfo::System::new();
111-
!system.get_process_by_name("Fiddler").is_empty()
112-
}
113-
114107
let mut url = Url::parse(cluster_addr().as_ref()).unwrap();
115108

116109
// if the url is https and specifies a username and password, remove from the url and set credentials
@@ -154,11 +147,6 @@ fn create_client() -> Result<Elasticsearch, Error> {
154147
None => builder,
155148
};
156149

157-
if running_proxy() {
158-
let proxy_url = Url::parse("http://localhost:8888").unwrap();
159-
builder = builder.proxy(proxy_url, None, None);
160-
}
161-
162150
let transport = builder.build()?;
163151
Ok(Elasticsearch::new(transport))
164152
}

elasticsearch/src/http/transport.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::{
3535
Method,
3636
},
3737
};
38-
use base64::write::EncoderWriter as Base64Encoder;
38+
use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, write::EncoderWriter, Engine};
3939
use bytes::BytesMut;
4040
use lazy_static::lazy_static;
4141
use serde::Serialize;
@@ -429,7 +429,7 @@ impl Transport {
429429
Credentials::ApiKey(i, k) => {
430430
let mut header_value = b"ApiKey ".to_vec();
431431
{
432-
let mut encoder = Base64Encoder::new(&mut header_value, base64::STANDARD);
432+
let mut encoder = EncoderWriter::new(&mut header_value, &BASE64_STANDARD);
433433
write!(encoder, "{}:", i).unwrap();
434434
write!(encoder, "{}", k).unwrap();
435435
}
@@ -561,7 +561,7 @@ impl CloudId {
561561
}
562562

563563
let data = parts[1];
564-
let decoded_result = base64::decode(data);
564+
let decoded_result = BASE64_STANDARD.decode(data);
565565
if decoded_result.is_err() {
566566
return Err(crate::error::lib(format!(
567567
"cannot base 64 decode '{}'",
@@ -685,7 +685,7 @@ pub mod tests {
685685

686686
#[test]
687687
fn can_parse_cloud_id_with_kibana_uuid() {
688-
let base64 = base64::encode("cloud-endpoint.example$3dadf823f05388497ea684236d918a1a$3f26e1609cf54a0f80137a80de560da4");
688+
let base64 = BASE64_STANDARD.encode("cloud-endpoint.example$3dadf823f05388497ea684236d918a1a$3f26e1609cf54a0f80137a80de560da4");
689689
let cloud_id = format!("my_cluster:{}", base64);
690690
let result = CloudId::parse(&cloud_id);
691691
assert!(result.is_ok());
@@ -699,7 +699,7 @@ pub mod tests {
699699

700700
#[test]
701701
fn can_parse_cloud_id_without_kibana_uuid() {
702-
let base64 = base64::encode("cloud-endpoint.example$3dadf823f05388497ea684236d918a1a$");
702+
let base64 = BASE64_STANDARD.encode("cloud-endpoint.example$3dadf823f05388497ea684236d918a1a$");
703703
let cloud_id = format!("my_cluster:{}", base64);
704704
let result = CloudId::parse(&cloud_id);
705705
assert!(result.is_ok());
@@ -713,7 +713,7 @@ pub mod tests {
713713

714714
#[test]
715715
fn can_parse_cloud_id_with_different_port() {
716-
let base64 = base64::encode("cloud-endpoint.example:4463$3dadf823f05388497ea684236d918a1a$3f26e1609cf54a0f80137a80de560da4");
716+
let base64 = BASE64_STANDARD.encode("cloud-endpoint.example:4463$3dadf823f05388497ea684236d918a1a$3f26e1609cf54a0f80137a80de560da4");
717717
let cloud_id = format!("my_cluster:{}", base64);
718718
let result = CloudId::parse(&cloud_id);
719719
assert!(result.is_ok());
@@ -728,7 +728,7 @@ pub mod tests {
728728

729729
#[test]
730730
fn cloud_id_must_contain_colon() {
731-
let base64 = base64::encode("cloud-endpoint.example$3dadf823f05388497ea684236d918a1a$3f26e1609cf54a0f80137a80de560da4");
731+
let base64 = BASE64_STANDARD.encode("cloud-endpoint.example$3dadf823f05388497ea684236d918a1a$3f26e1609cf54a0f80137a80de560da4");
732732
let cloud_id = format!("my_cluster{}", base64);
733733
let cloud = CloudId::parse(&cloud_id);
734734
assert!(cloud.is_err());
@@ -743,7 +743,7 @@ pub mod tests {
743743

744744
#[test]
745745
fn cloud_id_first_part_cannot_be_empty() {
746-
let base64 = base64::encode("cloud-endpoint.example$3dadf823f05388497ea684236d918a1a$3f26e1609cf54a0f80137a80de560da4");
746+
let base64 = BASE64_STANDARD.encode("cloud-endpoint.example$3dadf823f05388497ea684236d918a1a$3f26e1609cf54a0f80137a80de560da4");
747747
let cloud_id = format!(":{}", base64);
748748
let cloud = CloudId::parse(&cloud_id);
749749
assert!(cloud.is_err());
@@ -758,7 +758,7 @@ pub mod tests {
758758

759759
#[test]
760760
fn cloud_id_second_part_must_have_at_least_two_parts() {
761-
let base64 = base64::encode("cloud-endpoint.example");
761+
let base64 = BASE64_STANDARD.encode("cloud-endpoint.example");
762762
let cloud_id = format!("my_cluster:{}", base64);
763763
let result = CloudId::parse(&cloud_id);
764764
assert!(result.is_err());

elasticsearch/tests/auth.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@ use common::*;
2121

2222
use elasticsearch::auth::Credentials;
2323

24-
use base64::{self, write::EncoderWriter as Base64Encoder};
25-
// use std::fs::File;
26-
// use std::io::Read;
24+
use base64::{write::EncoderWriter, engine::general_purpose::STANDARD as BASE64_STANDARD};
2725
use std::io::Write;
2826

2927
#[tokio::test]
3028
async fn basic_auth_header() -> Result<(), failure::Error> {
3129
let server = server::http(move |req| async move {
3230
let mut header_value = b"Basic ".to_vec();
3331
{
34-
let mut encoder = Base64Encoder::new(&mut header_value, base64::STANDARD);
32+
let mut encoder = EncoderWriter::new(&mut header_value, &BASE64_STANDARD);
3533
write!(encoder, "username:password").unwrap();
3634
}
3735

@@ -56,7 +54,7 @@ async fn api_key_header() -> Result<(), failure::Error> {
5654
let server = server::http(move |req| async move {
5755
let mut header_value = b"ApiKey ".to_vec();
5856
{
59-
let mut encoder = Base64Encoder::new(&mut header_value, base64::STANDARD);
57+
let mut encoder = EncoderWriter::new(&mut header_value, &BASE64_STANDARD);
6058
write!(encoder, "id:api_key").unwrap();
6159
}
6260

elasticsearch/tests/cert.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async fn default_certificate_validation() -> Result<(), failure::Error> {
6565
))),
6666
Err(e) => {
6767
let expected = expected_error_message();
68-
let actual = e.to_string();
68+
let actual = format!("{:?}", e);
6969
assert!(
7070
actual.contains(&expected),
7171
"Expected error message to contain '{}' but was '{}'",
@@ -285,7 +285,7 @@ async fn fail_certificate_certificate_validation() -> Result<(), failure::Error>
285285
))),
286286
Err(e) => {
287287
let expected = expected_error_message();
288-
let actual = e.to_string();
288+
let actual = format!("{:?}", e);
289289
assert!(
290290
actual.contains(&expected),
291291
"Expected error message to contain '{}' but was '{}'",

0 commit comments

Comments
 (0)