-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create nym-harbour-master-client crate (#310)
* Create nym-harbour-master-client * Add harbour master client in gateway directory * Formatting * Remove testing code
- Loading branch information
Showing
13 changed files
with
158 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "nym-harbour-master-client" | ||
version = "0.1.0" | ||
authors.workspace = true | ||
repository.workspace = true | ||
homepage.workspace = true | ||
documentation.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
nym-http-api-client.workspace = true | ||
reqwest = { workspace = true, features = ["rustls-tls"] } | ||
serde = { workspace = true, features = ["derive"] } | ||
serde_json.workspace = true | ||
thiserror.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use nym_http_api_client::{ApiClient, HttpClientError, NO_PARAMS}; | ||
|
||
pub use nym_http_api_client::Client; | ||
|
||
use crate::{ | ||
responses::{Gateway, PagedResult}, | ||
routes, | ||
}; | ||
|
||
// This is largely lifted from mix-fetch. The future of harbourmaster is uncertain, but ideally | ||
// these two should be merged so they both can depend on the same crate. | ||
|
||
pub type HarbourMasterApiError = HttpClientError; | ||
|
||
#[allow(async_fn_in_trait)] | ||
pub trait HarbourMasterApiClientExt: ApiClient { | ||
// TODO: paging | ||
async fn get_gateways(&self) -> Result<PagedResult<Gateway>, HarbourMasterApiError> { | ||
self.get_json(&[routes::API_VERSION, routes::GATEWAYS], NO_PARAMS) | ||
.await | ||
} | ||
} | ||
|
||
impl HarbourMasterApiClientExt for Client {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use crate::client::HarbourMasterApiError; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum HarbourMasterError { | ||
#[error("api error: {0}")] | ||
HarbourMasterApiError(#[from] HarbourMasterApiError), | ||
} | ||
|
||
pub type Result<T> = std::result::Result<T, HarbourMasterError>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use crate::{ | ||
error::Result, | ||
responses::{Gateway, PagedResult}, | ||
Client, HarbourMasterApiClientExt, | ||
}; | ||
|
||
const HARBOUR_MASTER: &str = "https://harbourmaster.nymtech.net"; | ||
|
||
pub async fn get_gateways() -> Result<PagedResult<Gateway>> { | ||
let client = Client::new_url(HARBOUR_MASTER, None)?; | ||
Ok(client.get_gateways().await?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
mod client; | ||
mod error; | ||
mod helpers; | ||
mod responses; | ||
mod routes; | ||
|
||
pub use client::{Client, HarbourMasterApiClientExt, HarbourMasterApiError}; | ||
pub use error::HarbourMasterError; | ||
pub use helpers::get_gateways; | ||
pub use responses::{Gateway, PagedResult}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
// TODO: these should have their own crate shared with the harbourmaster service | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
pub struct PagedResult<T> { | ||
pub page: u32, | ||
pub size: u32, | ||
pub total: i32, | ||
pub items: Vec<T>, | ||
} | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
pub struct Gateway { | ||
pub gateway_identity_key: String, | ||
pub self_described: Option<serde_json::Value>, | ||
pub explorer_pretty_bond: Option<serde_json::Value>, | ||
pub last_probe_result: Option<serde_json::Value>, | ||
pub last_probe_log: Option<String>, | ||
pub last_testrun_utc: Option<String>, | ||
pub last_updated_utc: String, | ||
pub routing_score: f32, | ||
pub config_score: u32, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub const API_VERSION: &str = "v2"; | ||
pub const GATEWAYS: &str = "gateways"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters