Skip to content

Commit

Permalink
Add Settings & Health Checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Proziam committed Sep 27, 2024
1 parent f050b56 commit 80b04bb
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/curl
56 changes: 52 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use reqwest::{
use crate::{
error::Error,
models::{
AuthClient, Provider, RefreshSessionPayload, RequestMagicLinkPayload, ResendParams,
ResetPasswordForEmailPayload, Session, SignInEmailOtpParams,
SignInWithEmailAndPasswordPayload, SignInWithEmailOtpPayload, SignInWithIdTokenCredentials,
SignInWithOAuthOptions, SignInWithPhoneAndPasswordPayload,
AuthClient, AuthServerHealth, AuthServerSettings, Provider, RefreshSessionPayload,
RequestMagicLinkPayload, ResendParams, ResetPasswordForEmailPayload, Session,
SignInEmailOtpParams, SignInWithEmailAndPasswordPayload, SignInWithEmailOtpPayload,
SignInWithIdTokenCredentials, SignInWithOAuthOptions, SignInWithPhoneAndPasswordPayload,
SignUpWithEmailAndPasswordPayload, SignUpWithPhoneAndPasswordPayload, UpdateUserPayload,
User, VerifyOtpParams,
},
Expand Down Expand Up @@ -493,6 +493,54 @@ impl AuthClient {
Ok(serde_json::from_str(&response)?)
}

/// Check the Health Status of the Auth Server
/// # Example
/// ```
/// let health = auth_client
/// .get_health()
/// .await
/// .unwrap();
/// ```
pub async fn get_health(&self) -> Result<AuthServerHealth, Error> {
let mut headers = HeaderMap::new();
headers.insert("apikey", HeaderValue::from_str(&self.api_key)?);

let response = self
.client
.get(&format!("{}/auth/v1/health", self.project_url))
.headers(headers)
.send()
.await?
.text()
.await?;

Ok(serde_json::from_str(&response)?)
}

/// Retrieve the public settings of the server
/// # Example
/// ```
/// let settings = auth_client
/// .get_settings()
/// .await
/// .unwrap();
/// ```
pub async fn get_settings(&self) -> Result<AuthServerSettings, Error> {
let mut headers = HeaderMap::new();
headers.insert("apikey", HeaderValue::from_str(&self.api_key)?);

let response = self
.client
.get(&format!("{}/auth/v1/settings", self.project_url))
.headers(headers)
.send()
.await?
.text()
.await?;

Ok(serde_json::from_str(&response)?)
}

/// Exchange refresh token for a new session
/// # Example
/// ```
Expand Down
51 changes: 51 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,57 @@ impl Display for Channel {
}
}

/// Health status of the Auth Server
#[derive(Debug, Serialize, Deserialize)]
pub struct AuthServerHealth {
/// Version of the service
pub version: String,
/// Name of the service
pub name: String,
/// Description of the service
pub description: String,
}

/// Settings of the Auth Server
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AuthServerSettings {
pub external: External,
pub disable_signup: bool,
pub mailer_autoconfirm: bool,
pub phone_autoconfirm: bool,
pub sms_provider: String,
pub saml_enabled: bool,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct External {
pub anonymous_users: bool,
pub apple: bool,
pub azure: bool,
pub bitbucket: bool,
pub discord: bool,
pub facebook: bool,
pub figma: bool,
pub fly: bool,
pub github: bool,
pub gitlab: bool,
pub google: bool,
pub keycloak: bool,
pub kakao: bool,
pub linkedin: bool,
pub linkedin_oidc: bool,
pub notion: bool,
pub spotify: bool,
pub slack: bool,
pub slack_oidc: bool,
pub workos: bool,
pub twitch: bool,
pub twitter: bool,
pub email: bool,
pub phone: bool,
pub zoom: bool,
}

#[derive(Debug, Serialize, Deserialize)]
pub enum Provider {
Apple,
Expand Down
18 changes: 18 additions & 0 deletions tests/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,21 @@ async fn resend_email_test() {

assert!(response.is_ok() && session.unwrap().user.email == demo_email)
}

#[tokio::test]
async fn get_settings_test() {
let auth_client = create_test_client();

let settings = auth_client.get_settings().await.unwrap();

assert!(settings.external.github == true)
}

#[tokio::test]
async fn get_health_test() {
let auth_client = create_test_client();

let health = auth_client.get_health().await.unwrap();

assert!(health.description != "")
}

0 comments on commit 80b04bb

Please sign in to comment.