From f8906c5575e769dc195a79b4d56a5a3e72d7edef Mon Sep 17 00:00:00 2001 From: toto-xoxo <85445598+toto-xoxo@users.noreply.github.com> Date: Fri, 4 Aug 2023 17:00:22 +0200 Subject: [PATCH] add selection of data region for push --- .env.template | 2 ++ src/api/push.rs | 2 +- src/config.rs | 22 ++++++++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.env.template b/.env.template index 3c177a26..029ab36b 100644 --- a/.env.template +++ b/.env.template @@ -80,8 +80,10 @@ # PUSH_ENABLED=true # PUSH_INSTALLATION_ID=CHANGEME # PUSH_INSTALLATION_KEY=CHANGEME +# PUSH_RELAY_REGION=us ## Don't change this unless you know what you're doing. # PUSH_RELAY_URI=https://push.bitwarden.com +# IDENTITY_URI=https://identity.bitwarden.com ## Controls whether users are allowed to create Bitwarden Sends. ## This setting applies globally to all users. diff --git a/src/api/push.rs b/src/api/push.rs index 3b0a573b..b6c52abb 100644 --- a/src/api/push.rs +++ b/src/api/push.rs @@ -50,7 +50,7 @@ async fn get_auth_push_token() -> ApiResult { ("client_secret", &client_secret), ]; - let res = match get_reqwest_client().post("https://identity.bitwarden.com/connect/token").form(¶ms).send().await + let res = match get_reqwest_client().post(CONFIG.identity_uri()).form(¶ms).send().await { Ok(r) => r, Err(e) => err!(format!("Error getting push token from bitwarden server: {e}")), diff --git a/src/config.rs b/src/config.rs index 041e89a7..758aff83 100644 --- a/src/config.rs +++ b/src/config.rs @@ -380,8 +380,26 @@ make_config! { push { /// Enable push notifications push_enabled: bool, false, def, false; - /// Push relay base uri - push_relay_uri: String, false, def, "https://push.bitwarden.com".to_string(); + /// Push relay region |> The data region from https://bitwarden.com/host + push_relay_region: String, false, def, "us".to_string(); + /// Push relay uri + push_relay_uri: String, false, auto, |c| { + let relay_region = match c.push_relay_region.as_str() { + "us" => "com", + "eu" => "eu", + _ => "com", // Default to US if the region is not recognized + }; + format!("https://push.bitwarden.{}", relay_region) + }; + /// Identity uri + identity_uri: String, false, auto, |c| { + let relay_region = match c.push_relay_region.as_str() { + "us" => "com", + "eu" => "eu", + _ => "com", // Default to US if the region is not recognized + }; + format!("https://identity.bitwarden.{}", relay_region) + }; /// Installation id |> The installation id from https://bitwarden.com/host push_installation_id: Pass, false, def, String::new(); /// Installation key |> The installation key from https://bitwarden.com/host