Skip to content

Commit

Permalink
[server] Add server cluster configuration #1046 (#1049)
Browse files Browse the repository at this point in the history
* add cluster test

* add cluster configuration

* fix config

* move params around

* fix coverage

* update ts api
  • Loading branch information
michaelvlach authored Feb 21, 2024
1 parent a6066be commit cb3dc06
Show file tree
Hide file tree
Showing 14 changed files with 1,693 additions and 1,486 deletions.
13 changes: 12 additions & 1 deletion agdb_api/rust/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::api_types::ServerDatabase;
use crate::api_types::UserCredentials;
use crate::http_client::HttpClient;
use crate::ChangePassword;
use crate::ClusterStatus;
use crate::DbAudit;
use crate::DbUser;
use crate::DbUserRole;
Expand Down Expand Up @@ -425,7 +426,17 @@ impl<T: HttpClient> AgdbApi<T> {
}

pub async fn status(&self) -> AgdbApiResult<u16> {
Ok(self.client.get::<()>(&self.url("/status"), &None).await?.0)
Ok(self
.client
.get::<Vec<ClusterStatus>>(&self.url("/status"), &None)
.await?
.0)
}

pub async fn status_cluster(&self) -> AgdbApiResult<(u16, Vec<ClusterStatus>)> {
self.client
.get(&self.url("/status?cluster=true"), &None)
.await
}

pub async fn user_login(&mut self, user: &str, password: &str) -> AgdbApiResult<u16> {
Expand Down
22 changes: 20 additions & 2 deletions agdb_api/rust/src/api_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ pub struct ChangePassword {
pub new_password: String,
}

#[derive(Debug, Deserialize, Serialize, ToSchema, PartialEq)]
pub struct ClusterStatus {
pub address: String,
pub status: bool,
}

#[derive(Deserialize, ToSchema)]
pub struct Queries(pub Vec<QueryType>);

Expand All @@ -67,6 +73,11 @@ pub struct ServerDatabase {
pub backup: u64,
}

#[derive(Debug, Deserialize, ToSchema)]
pub struct StatusParams {
pub cluster: Option<bool>,
}

#[derive(Deserialize, Serialize, ToSchema)]
pub struct UserCredentials {
pub password: String,
Expand Down Expand Up @@ -149,9 +160,8 @@ impl Display for DbUserRole {

#[cfg(test)]
mod tests {
use agdb::SelectIndexesQuery;

use super::*;
use agdb::SelectIndexesQuery;

#[test]
fn derived_from_debug() {
Expand Down Expand Up @@ -189,6 +199,14 @@ mod tests {
}
);
format!("{:?}", DbAudit(vec![]));
format!(
"{:?}",
ClusterStatus {
address: "localhost".to_string(),
status: true
}
);
format!("{:?}", StatusParams { cluster: None });
}

#[test]
Expand Down
6 changes: 1 addition & 5 deletions agdb_api/rust/src/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ impl HttpClient for ReqwestClient {
let response = request.send().await?;
let status = response.status().as_u16();
if response.status().is_success() {
let body = if response.content_length().unwrap_or(0) != 0 {
response.json::<T>().await?
} else {
serde_json::from_value(serde_json::Value::default())?
};
let body = response.json::<T>().await?;
Ok((status, body))
} else {
Err(AgdbApiError {
Expand Down
2 changes: 2 additions & 0 deletions agdb_api/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub use api::AgdbApi;
pub use api_error::AgdbApiError;
pub use api_result::AgdbApiResult;
pub use api_types::ChangePassword;
pub use api_types::ClusterStatus;
pub use api_types::DbAudit;
pub use api_types::DbType;
pub use api_types::DbUser;
Expand All @@ -16,6 +17,7 @@ pub use api_types::Queries;
pub use api_types::QueriesResults;
pub use api_types::QueryAudit;
pub use api_types::ServerDatabase;
pub use api_types::StatusParams;
pub use api_types::UserCredentials;
pub use api_types::UserLogin;
pub use api_types::UserStatus;
Expand Down
Loading

0 comments on commit cb3dc06

Please sign in to comment.