Skip to content

Commit

Permalink
Remove AuthenticationManager::from_custom_service_account() in favor …
Browse files Browse the repository at this point in the history
…of documentation
  • Loading branch information
djc committed Feb 1, 2022
1 parent 232c313 commit a3edad5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/authentication_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@ pub(crate) trait ServiceAccount: Send + Sync {

/// Authentication manager is responsible for caching and obtaing credentials for the required scope
///
/// Cacheing for the full life time is ensured
/// Construct the authentication manager with [`AuthenticationManager::new()`] or by creating
/// a [`CustomServiceAccount`], then converting it into an `AuthenticationManager` using the `From`
/// impl.
pub struct AuthenticationManager {
pub(crate) client: HyperClient,
pub(crate) service_account: Box<dyn ServiceAccount>,
refresh_mutex: Mutex<()>,
}

impl AuthenticationManager {
/// Create an `AuthenticationManager` directly from a custom service account
pub fn from_custom_service_account(service_account: CustomServiceAccount) -> Self {
Self::build(types::client(), service_account)
}

/// Finds a service account provider to get authentication tokens from
///
/// Tries the following approaches, in order:
Expand All @@ -46,7 +43,7 @@ impl AuthenticationManager {
pub async fn new() -> Result<Self, Error> {
tracing::debug!("Initializing gcp_auth");
if let Some(service_account) = CustomServiceAccount::from_env()? {
return Ok(Self::from_custom_service_account(service_account));
return Ok(service_account.into());
}

let client = types::client();
Expand Down Expand Up @@ -121,6 +118,6 @@ impl AuthenticationManager {

impl From<CustomServiceAccount> for AuthenticationManager {
fn from(service_account: CustomServiceAccount) -> Self {
Self::from_custom_service_account(service_account)
Self::build(types::client(), service_account)
}
}
3 changes: 3 additions & 0 deletions src/custom_service_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use crate::types::{HyperClient, Signer, Token};
use crate::util::HyperExt;

/// A custom service account containing credentials
///
/// Once initialized, a [`CustomServiceAccount`] can be converted into an [`AuthenticationManager`]
/// using the applicable `From` implementation.
#[derive(Debug)]
pub struct CustomServiceAccount {
credentials: ApplicationCredentials,
Expand Down

0 comments on commit a3edad5

Please sign in to comment.