Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/services/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,23 +287,24 @@ pub struct LoginParams {

#[derive(Clone)]
pub struct AccountClient {
pub account: AccountUuid,
token: SecretString,
pub account: Option<AccountUuid>,
token: Option<SecretString>,
base: Url,
http: HttpClient,
}

impl PartialEq for AccountClient {
fn eq(&self, other: &Self) -> bool {
self.account == other.account
&& self.token.expose_secret() == other.token.expose_secret()
&& self.token.as_ref().map(SecretString::expose_secret)
== other.token.as_ref().map(SecretString::expose_secret)
&& self.base == other.base
}
}

impl super::TokenProvider for &AccountClient {
fn provide_token(&self) -> Option<&str> {
Some(self.token.expose_secret())
self.token.as_ref().map(SecretString::expose_secret)
}
}

Expand All @@ -324,17 +325,27 @@ impl AccountClient {
Ok(Self {
http,
base: base.ok_or(Error::Other("NoAccountService"))?,
account,
token: token.into(),
account: Some(account),
token: Some(token.into()),
})
}

pub fn without_user(config: &Config, http: HttpClient) -> Result<Self> {
let base = config.account_service.clone();
Ok(Self {
http,
base: base.ok_or(Error::Other("NoAccountService"))?,
account: None,
token: None,
})
}

#[deprecated(note = "use ServiceFactory")]
pub fn assume_claims(&self, claims: &Claims, secret: &SecretString) -> Result<Self> {
let account = claims.account;
let account = Some(claims.account);
let base = self.base.clone();
let http = self.http.clone();
let token = claims.encode(secret)?;
let token = Some(claims.encode(secret)?);

Ok(Self {
http,
Expand All @@ -354,7 +365,7 @@ impl AccountClient {
http,
base,
account,
token: token.as_ref().into(),
token: Some(token.as_ref().into()),
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ impl ServiceFactory {
AccountClient::new(&self.config, self.account_http.clone(), account, token)
}

pub fn new_account_client_without_user(&self) -> Result<AccountClient> {
AccountClient::without_user(&self.config, self.account_http.clone())
}

pub fn new_kvs_client(&self, namespace: &str, claims: &Claims) -> Result<KvsClient> {
KvsClient::new(
&self.config,
Expand Down
Loading