From 89e1b457d7d9d4ad02133495b26e8e6cf40c55ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Em=C4=ABls?= Date: Thu, 19 Dec 2024 09:09:45 +0100 Subject: [PATCH] fixup! Remove global API endpoint --- mullvad-api/src/bin/relay_list.rs | 9 +++++++-- mullvad-api/src/ffi/mod.rs | 5 ++--- mullvad-api/src/lib.rs | 16 ++-------------- test/test-manager/src/tests/account.rs | 2 +- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/mullvad-api/src/bin/relay_list.rs b/mullvad-api/src/bin/relay_list.rs index f837d82afde9..3ea771cc81ee 100644 --- a/mullvad-api/src/bin/relay_list.rs +++ b/mullvad-api/src/bin/relay_list.rs @@ -2,13 +2,18 @@ //! Used by the installer artifact packer to bundle the latest available //! relay list at the time of creating the installer. -use mullvad_api::{proxy::ApiConnectionMode, rest::Error as RestError, RelayListProxy}; +use mullvad_api::{ + proxy::ApiConnectionMode, rest::Error as RestError, ApiEndpoint, RelayListProxy, +}; use std::process; use talpid_types::ErrorExt; #[tokio::main] async fn main() { - let runtime = mullvad_api::Runtime::new(tokio::runtime::Handle::current()); + let runtime = mullvad_api::Runtime::new( + tokio::runtime::Handle::current(), + &ApiEndpoint::from_env_vars(), + ); let relay_list_request = RelayListProxy::new(runtime.mullvad_rest_handle(ApiConnectionMode::Direct.into_provider())) diff --git a/mullvad-api/src/ffi/mod.rs b/mullvad-api/src/ffi/mod.rs index fb003f18aba9..bd7ec1f294f8 100644 --- a/mullvad-api/src/ffi/mod.rs +++ b/mullvad-api/src/ffi/mod.rs @@ -88,9 +88,8 @@ impl FfiClient { // It is imperative that the REST runtime is created within an async context, otherwise // ApiAvailability panics. - let api_runtime = tokio_runtime.block_on(async { - crate::Runtime::with_custom_endpoint(tokio_runtime.handle().clone(), &endpoint) - }); + let api_runtime = tokio_runtime + .block_on(async { crate::Runtime::new(tokio_runtime.handle().clone(), &endpoint) }); let context = FfiClient { tokio_runtime, diff --git a/mullvad-api/src/lib.rs b/mullvad-api/src/lib.rs index 1d114c20aee2..a47c708b2ef4 100644 --- a/mullvad-api/src/lib.rs +++ b/mullvad-api/src/lib.rs @@ -349,20 +349,8 @@ pub enum Error { } impl Runtime { - /// Create a new `Runtime`. - /// Will either infer the API endpoint from environment variables, if set, otherwise will use - /// the default production endpoint. - pub fn new(handle: tokio::runtime::Handle) -> Self { - Self::with_custom_endpoint( - handle, - &ApiEndpoint::from_env_vars(), - #[cfg(target_os = "android")] - None, - ) - } - /// Will create a new Runtime without a cache with the provided API endpoint. - pub fn with_custom_endpoint( + pub fn new( handle: tokio::runtime::Handle, endpoint: &ApiEndpoint, #[cfg(target_os = "android")] socket_bypass_tx: Option>, @@ -390,7 +378,7 @@ impl Runtime { #[cfg(feature = "api-override")] if endpoint.should_disable_address_cache() { - return Ok(Self::with_custom_endpoint( + return Ok(Self::new( handle, endpoint, #[cfg(target_os = "android")] diff --git a/test/test-manager/src/tests/account.rs b/test/test-manager/src/tests/account.rs index ae275b13011d..7fc3e1ef8190 100644 --- a/test/test-manager/src/tests/account.rs +++ b/test/test-manager/src/tests/account.rs @@ -291,7 +291,7 @@ pub async fn new_device_client() -> anyhow::Result { let endpoint = ApiEndpoint::new(api_host, api_address, false); let api = - mullvad_api::Runtime::with_custom_endpoint(tokio::runtime::Handle::current(), &endpoint); + mullvad_api::Runtime::new(tokio::runtime::Handle::current(), &endpoint); let rest_handle = api.mullvad_rest_handle(ApiConnectionMode::Direct.into_provider()); Ok(DevicesProxy::new(rest_handle))