Skip to content

Commit

Permalink
Update aws-sigv4 to >= 0.57 (#201)
Browse files Browse the repository at this point in the history
* cargo fmt

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Update aws-sigv4 to `>= 0.57`

- Expose signing time source as configurable for testability.
- Explicitly add global default headers upfront rather than via reqwest::Client so that they are taken into account for signing.
- Add test cases for sigv4 based off those in opensearch-net.

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

* Changelog

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

---------

Signed-off-by: Thomas Farr <tsfarr@amazon.com>
  • Loading branch information
Xtansia committed Nov 6, 2023
1 parent 1041309 commit a914bc5
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 139 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Added
- Added InfoResponse structure ([#187](https://github.com/opensearch-project/opensearch-rs/pull/187))
- Added documentation on how to make raw json requests ([#196](https://github.com/opensearch-project/opensearch-rs/pull/196))

### Dependencies
- Bumps `sysinfo` from 0.28.0 to 0.29.0
- Bumps `serde_with` from ~2 to ~3
- Bumps `itertools` from 0.10.0 to 0.11.0
- Bumps `syn` from 1.0 to 2.0
- Bumps `toml` from 0.7.1 to 0.8.0
- Bumps `dialoguer` from 0.10.2 to 0.11.0
- Bumps `aws-*` from >=0.53 to >=0.57 ([#201](https://github.com/opensearch-project/opensearch-rs/pull/201))

### Changed
- Moved @aditjind to Emeritus maintainers ([#170](https://github.com/opensearch-project/opensearch-rs/pull/170))
Expand Down
17 changes: 11 additions & 6 deletions opensearch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]

# AWS SigV4 Auth support
aws-auth = ["aws-credential-types", "aws-sigv4", "aws-types"]
aws-auth = ["aws-credential-types", "aws-sigv4", "aws-smithy-runtime-api", "aws-types"]

[dependencies]
base64 = "0.21"
Expand All @@ -40,22 +40,27 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_with = "3"
void = "1.0.2"
aws-credential-types = { version = ">= 0.53", optional = true }
aws-sigv4 = { version = ">= 0.53", optional = true }
aws-types = { version = ">= 0.53", optional = true }
aws-credential-types = { version = ">= 0.57", optional = true }
aws-sigv4 = { version = ">= 0.57", optional = true }
aws-smithy-runtime-api = { version = ">= 0.57", optional = true, features = ["client"]}
aws-types = { version = ">= 0.57", optional = true }

[dev-dependencies]
anyhow = "1.0"
aws-config = ">= 0.53"
aws-config = ">= 0.57"
aws-smithy-async = ">= 0.57"
chrono = { version = "0.4", features = ["serde"] }
clap = "2"
futures = "0.3.1"
http = "0.2"
hyper = { version = "0.14", default-features = false, features = ["tcp", "stream", "server"] }
regex="1.4"
sysinfo = "0.29.0"
test-case = "3"
textwrap = "0.16"
tokio = { version = "1.0", default-features = false, features = ["macros", "net", "time", "rt-multi-thread"] }
tokio = { version = "1.0", default-features = false, features = ["macros", "net", "time", "rt-multi-thread", "sync"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
xml-rs = "0.8"

[build-dependencies]
Expand Down
28 changes: 20 additions & 8 deletions opensearch/examples/advanced_index_actions.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
use opensearch::auth::Credentials;
use opensearch::indices::{
IndicesAddBlockParts, IndicesClearCacheParts, IndicesCloneParts, IndicesCloseParts,
IndicesCreateParts, IndicesDeleteParts, IndicesFlushParts, IndicesForcemergeParts,
IndicesOpenParts, IndicesPutSettingsParts, IndicesRefreshParts, IndicesSplitParts,
};
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

use opensearch::{
cert::CertificateValidation, http::transport::SingleNodeConnectionPool,
http::transport::TransportBuilder, OpenSearch,
auth::Credentials,
cert::CertificateValidation,
http::transport::{SingleNodeConnectionPool, TransportBuilder},
indices::{
IndicesAddBlockParts, IndicesClearCacheParts, IndicesCloneParts, IndicesCloseParts,
IndicesCreateParts, IndicesDeleteParts, IndicesFlushParts, IndicesForcemergeParts,
IndicesOpenParts, IndicesPutSettingsParts, IndicesRefreshParts, IndicesSplitParts,
},
OpenSearch,
};
use serde_json::json;
use url::Url;
Expand Down
20 changes: 15 additions & 5 deletions opensearch/examples/index_lifecycle.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
use opensearch::auth::Credentials;
use opensearch::cert::CertificateValidation;
use opensearch::http::transport::{SingleNodeConnectionPool, TransportBuilder};
use opensearch::OpenSearch;
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

use opensearch::{
auth::Credentials,
cert::CertificateValidation,
http::transport::{SingleNodeConnectionPool, TransportBuilder},
indices::{
IndicesCreateParts, IndicesDeleteParts, IndicesExistsParts, IndicesGetParts,
IndicesPutMappingParts, IndicesPutSettingsParts,
},
IndexParts,
IndexParts, OpenSearch,
};
use serde_json::json;
use url::Url;
Expand Down
27 changes: 19 additions & 8 deletions opensearch/examples/index_template.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
use opensearch::auth::Credentials;
use opensearch::cluster::{ClusterDeleteComponentTemplateParts, ClusterPutComponentTemplateParts};
use opensearch::indices::{
IndicesCreateParts, IndicesDeleteIndexTemplateParts, IndicesDeleteParts,
IndicesGetIndexTemplateParts, IndicesGetParts, IndicesPutIndexTemplateParts,
};
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
use opensearch::{
cert::CertificateValidation, http::transport::SingleNodeConnectionPool,
http::transport::TransportBuilder, OpenSearch,
auth::Credentials,
cert::CertificateValidation,
cluster::{ClusterDeleteComponentTemplateParts, ClusterPutComponentTemplateParts},
http::transport::{SingleNodeConnectionPool, TransportBuilder},
indices::{
IndicesCreateParts, IndicesDeleteIndexTemplateParts, IndicesDeleteParts,
IndicesGetIndexTemplateParts, IndicesGetParts, IndicesPutIndexTemplateParts,
},
OpenSearch,
};
use serde_json::json;
use url::Url;
Expand Down
61 changes: 37 additions & 24 deletions opensearch/examples/json.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

use opensearch::{
auth::Credentials,
cert::CertificateValidation,
http::{
headers::HeaderMap,
request::JsonBody,
transport::{SingleNodeConnectionPool, TransportBuilder},
Method, Url,
},
OpenSearch,
};
use serde_json::{json, Value};

use opensearch::auth::Credentials;
use opensearch::cert::CertificateValidation;
use opensearch::http::headers::HeaderMap;
use opensearch::http::transport::{SingleNodeConnectionPool, TransportBuilder};
use opensearch::http::{Method, Url};
use opensearch::http::request::JsonBody;
use opensearch::OpenSearch;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let url = Url::parse("https://localhost:9200")?;
Expand All @@ -22,14 +36,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let document_id = "1";

let info: Value = client
.send::<(), ()>(
Method::Get,
"/",
HeaderMap::new(),
None,
None,
None,
)
.send::<(), ()>(Method::Get, "/", HeaderMap::new(), None, None, None)
.await?
.json()
.await?;
Expand All @@ -40,13 +47,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
);

// Create an index
let index_body : JsonBody<_> = json!({
let index_body: JsonBody<_> = json!({
"settings": {
"index": {
"number_of_shards" : 4
}
}
}).into();
})
.into();

let create_index_response = client
.send(
Expand All @@ -66,7 +74,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
"title": "Moneyball",
"director": "Bennett Miller",
"year": "2011"
}).into();
})
.into();
let create_document_response = client
.send(
Method::Put,
Expand All @@ -82,15 +91,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

// Search for a document
let q = "miller";
let query : JsonBody<_> = json!({
let query: JsonBody<_> = json!({
"size": 5,
"query": {
"multi_match": {
"query": q,
"fields": ["title^2", "director"]
}
}
}).into();
})
.into();

let search_response = client
.send(
Expand All @@ -105,11 +115,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

assert_eq!(search_response.status_code(), 200);
let search_result = search_response.json::<Value>().await?;
println!("Hits: {:#?}", search_result["hits"]["hits"].as_array().unwrap());
println!(
"Hits: {:#?}",
search_result["hits"]["hits"].as_array().unwrap()
);

// Delete the document
let delete_document_response = client
.send::<(),()>(
.send::<(), ()>(
Method::Delete,
&format!("/{index_name}/_doc/{document_id}"),
HeaderMap::new(),
Expand All @@ -123,7 +136,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

// Delete the index
let delete_response = client
.send::<(),()>(
.send::<(), ()>(
Method::Delete,
&format!("/{index_name}"),
HeaderMap::new(),
Expand Down
Loading

0 comments on commit a914bc5

Please sign in to comment.