Skip to content

Commit

Permalink
fixup! Remove global API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkisemils committed Dec 19, 2024
1 parent a7808d2 commit 89e1b45
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
9 changes: 7 additions & 2 deletions mullvad-api/src/bin/relay_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
5 changes: 2 additions & 3 deletions mullvad-api/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 2 additions & 14 deletions mullvad-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<mpsc::Sender<SocketBypassRequest>>,
Expand Down Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion test/test-manager/src/tests/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub async fn new_device_client() -> anyhow::Result<DevicesProxy> {
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))
Expand Down

0 comments on commit 89e1b45

Please sign in to comment.