Skip to content
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
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/mithril-aggregator-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator-client"
version = "0.1.1"
version = "0.1.2"
description = "Client to request data from a Mithril Aggregator"
authors.workspace = true
documentation.workspace = true
Expand Down
38 changes: 37 additions & 1 deletion internal/mithril-aggregator-client/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
# Mithril-aggregator-client [![CI workflow](https://github.com/input-output-hk/mithril/actions/workflows/ci.yml/badge.svg)](https://github.com/input-output-hk/mithril/actions/workflows/ci.yml) [![License](https://img.shields.io/badge/license-Apache%202.0-blue?style=flat-square)](https://github.com/input-output-hk/mithril/blob/main/LICENSE) [![Discord](https://img.shields.io/discord/500028886025895936.svg?logo=discord&style=flat-square)](https://discord.gg/5kaErDKDRq)

This crate provides a client to request data from a Mithril Aggregator.
This crate provides a client to request data from a Mithril Aggregator over http.

## Configuration of http features

Reqwest is used as the backend for the http client. Its default features are disabled to let the user control
which [features to enable](https://docs.rs/reqwest/latest/reqwest/#optional-features).

To enable a reqwest feature, add the following to your `Cargo.toml`:

```toml
reqwest = { version = "x.yy", features = ["feature_a", "feature_b"] }
```

for example, if reqwest is a workspace dependency, and you want to enable the `default` feature and the compression features:

```toml
reqwest = { workspace = true, features = [
"default",
"gzip",
"zstd",
"deflate",
"brotli"
] }
```

### Unused dependency warning

You should add the `reqwest` dependency even if you don't use it directly in your code.
If you are using [`cargo machete`](https://github.com/bnjbvr/cargo-machete) to track unused dependencies, it will raise a warning.

To avoid this warning, add the following to your `Cargo.toml`:

```toml
[package.metadata.cargo-machete]
# reqwest: for features configuration, indirect dependency via `mithril-aggregator-client`
ignored = ["reqwest"]
```
22 changes: 13 additions & 9 deletions internal/mithril-aggregator-client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ use anyhow::Context;
use reqwest::{Client, IntoUrl, Proxy, Url};
use slog::{Logger, o};
use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;

use mithril_common::StdResult;
use mithril_common::api_version::APIVersionProvider;

use crate::client::AggregatorClient;
use crate::client::AggregatorHttpClient;

/// A builder of [AggregatorClient]
/// A builder of [AggregatorHttpClient]
pub struct AggregatorClientBuilder {
aggregator_url_result: reqwest::Result<Url>,
api_version_provider: Option<APIVersionProvider>,
api_version_provider: Option<Arc<APIVersionProvider>>,
additional_headers: Option<HashMap<String, String>>,
timeout_duration: Option<Duration>,
relay_endpoint: Option<String>,
Expand Down Expand Up @@ -41,7 +42,10 @@ impl AggregatorClientBuilder {
}

/// Set the [APIVersionProvider] to use.
pub fn with_api_version_provider(mut self, api_version_provider: APIVersionProvider) -> Self {
pub fn with_api_version_provider(
mut self,
api_version_provider: Arc<APIVersionProvider>,
) -> Self {
self.api_version_provider = Some(api_version_provider);
self
}
Expand All @@ -59,13 +63,13 @@ impl AggregatorClientBuilder {
}

/// Set the address of the relay
pub fn with_relay_endpoint(mut self, relay_endpoint: String) -> Self {
self.relay_endpoint = Some(relay_endpoint);
pub fn with_relay_endpoint(mut self, relay_endpoint: Option<String>) -> Self {
self.relay_endpoint = relay_endpoint;
self
}

/// Returns an [AggregatorClient] based on the builder configuration
pub fn build(self) -> StdResult<AggregatorClient> {
/// Returns an [AggregatorHttpClient] based on the builder configuration
pub fn build(self) -> StdResult<AggregatorHttpClient> {
let aggregator_endpoint =
enforce_trailing_slash(self.aggregator_url_result.with_context(
|| "Invalid aggregator endpoint, it must be a correctly formed url",
Expand All @@ -80,7 +84,7 @@ impl AggregatorClientBuilder {
.proxy(Proxy::all(relay_endpoint).with_context(|| "Relay proxy creation failed")?)
}

Ok(AggregatorClient {
Ok(AggregatorHttpClient {
aggregator_endpoint,
api_version_provider,
additional_headers: (&additional_headers)
Expand Down
Loading
Loading