Source code for beaker.services.account
from typing import List
from ..data_model import *
from ..exceptions import *
from ..util import cached_property
from .service_client import ServiceClient
[docs]class AccountClient(ServiceClient):
"""
Accessed via :data:`Beaker.account <beaker.Beaker.account>`.
"""
@cached_property(ttl=3 * 60)
def name(self) -> str:
"""
A convenience property to get username of your Beaker account.
"""
return self.whoami().name
[docs] def whoami(self) -> Account:
"""
Check who you are authenticated as.
:raises BeakerError: Any other :class:`~beaker.exceptions.BeakerError` type that can occur.
:raises RequestException: Any other exception that can occur when contacting the
Beaker server.
"""
return Account.from_json(self.request("user").json())
[docs] def list_organizations(self) -> List[Organization]:
"""
List all organizations you are a member of.
:raises BeakerError: Any other :class:`~beaker.exceptions.BeakerError` type that can occur.
:raises RequestException: Any other exception that can occur when contacting the
Beaker server.
"""
return [Organization.from_json(d) for d in self.request("user/orgs").json()["data"]]
[docs] def get(self, account: str) -> Account:
"""
Get information about an account.
:param account: The account name or ID.
:raises AccountNotFound: If the account doesn't exist.
:raises BeakerError: Any other :class:`~beaker.exceptions.BeakerError` type that can occur.
:raises RequestException: Any other exception that can occur when contacting the
Beaker server.
"""
return Account.from_json(
self.request(
f"users/{self.url_quote(account)}",
method="GET",
exceptions_for_status={404: AccountNotFound(account)},
).json()
)