diff options
| author | Emīls <emils@mullvad.net> | 2024-04-30 18:32:04 +0200 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2024-06-10 13:10:20 +0200 |
| commit | e47061ff19e3453875fab5d03fcc8aa6316ee3c2 (patch) | |
| tree | c312b78eeb3257590e4e4d45af38a9b874ff0e6d /mullvad-api/src | |
| parent | 33cdec413e6404d64cc0718b50a25dab2e17661c (diff) | |
| download | mullvadvpn-e47061ff19e3453875fab5d03fcc8aa6316ee3c2.tar.xz mullvadvpn-e47061ff19e3453875fab5d03fcc8aa6316ee3c2.zip | |
Use configured hostname for access token
Diffstat (limited to 'mullvad-api/src')
| -rw-r--r-- | mullvad-api/src/abortable_stream.rs | 4 | ||||
| -rw-r--r-- | mullvad-api/src/access.rs | 10 | ||||
| -rw-r--r-- | mullvad-api/src/ffi/error.rs | 2 | ||||
| -rw-r--r-- | mullvad-api/src/lib.rs | 6 |
4 files changed, 11 insertions, 11 deletions
diff --git a/mullvad-api/src/abortable_stream.rs b/mullvad-api/src/abortable_stream.rs index c848bd9f92..0258a7e650 100644 --- a/mullvad-api/src/abortable_stream.rs +++ b/mullvad-api/src/abortable_stream.rs @@ -1,9 +1,7 @@ //! Wrapper around a stream to make it abortable. This allows in-flight requests to be cancelled //! immediately instead of after the socket times out. -use futures::channel::oneshot; -use futures::future::Fuse; -use futures::FutureExt; +use futures::{channel::oneshot, future::Fuse, FutureExt}; use hyper::client::connect::{Connected, Connection}; use std::{ future::Future, diff --git a/mullvad-api/src/access.rs b/mullvad-api/src/access.rs index 569c01f085..dba9e4befd 100644 --- a/mullvad-api/src/access.rs +++ b/mullvad-api/src/access.rs @@ -1,7 +1,6 @@ use crate::{ rest, rest::{RequestFactory, RequestServiceHandle}, - API, }; use futures::{ channel::{mpsc, oneshot}, @@ -9,7 +8,7 @@ use futures::{ }; use hyper::StatusCode; use mullvad_types::account::{AccessToken, AccessTokenData, AccountToken}; -use std::collections::HashMap; +use std::{borrow::Cow, collections::HashMap}; use tokio::select; pub const AUTH_URL_PREFIX: &str = "auth/v1"; @@ -37,8 +36,11 @@ struct AccountState { } impl AccessTokenStore { - pub(crate) fn new(service: RequestServiceHandle) -> Self { - let factory = rest::RequestFactory::new(API.host(), None); + pub(crate) fn new( + service: RequestServiceHandle, + hostname: impl Into<Cow<'static, str>>, + ) -> Self { + let factory = rest::RequestFactory::new(hostname, None); let (tx, rx) = mpsc::unbounded(); tokio::spawn(Self::service_requests(rx, service, factory)); Self { tx } diff --git a/mullvad-api/src/ffi/error.rs b/mullvad-api/src/ffi/error.rs index 8f3095fee0..539a6c23a0 100644 --- a/mullvad-api/src/ffi/error.rs +++ b/mullvad-api/src/ffi/error.rs @@ -21,7 +21,7 @@ pub struct MullvadApiError { impl MullvadApiError { pub fn new(kind: MullvadApiErrorKind, error: &dyn std::error::Error) -> Self { - let description = CString::new(format!("{error:?}")).unwrap_or_default(); + let description = CString::new(format!("{error:?}: {error}")).unwrap_or_default(); Self { description: description.into_raw(), kind, diff --git a/mullvad-api/src/lib.rs b/mullvad-api/src/lib.rs index 82cabddff0..85214a9fc0 100644 --- a/mullvad-api/src/lib.rs +++ b/mullvad-api/src/lib.rs @@ -434,8 +434,8 @@ impl Runtime { #[cfg(target_os = "android")] self.socket_bypass_tx.clone(), ); - let token_store = access::AccessTokenStore::new(service.clone()); - let factory = rest::RequestFactory::new(API.host(), Some(token_store)); + let token_store = access::AccessTokenStore::new(service.clone(), API.host()); + let factory = rest::RequestFactory::new(API.host().to_owned(), Some(token_store)); rest::MullvadRestHandle::new(service, factory, self.availability_handle()) } @@ -448,7 +448,7 @@ impl Runtime { #[cfg(target_os = "android")] self.socket_bypass_tx.clone(), ); - let token_store = access::AccessTokenStore::new(service.clone()); + let token_store = access::AccessTokenStore::new(service.clone(), hostname.clone()); let factory = rest::RequestFactory::new(hostname, Some(token_store)); rest::MullvadRestHandle::new(service, factory, self.availability_handle()) |
