Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2021-12-15 06:32:32 -08:00
parent afcc5b88c1
commit 5afd7562d4
2 changed files with 21 additions and 0 deletions

View File

@ -46,3 +46,13 @@ class AuthenticatedClient(Client):
def get_headers(self) -> Dict[str, str]:
"""Get headers to be used in authenticated endpoints"""
return {"Authorization": f"Bearer {self.token}", **self.headers}
@attr.s(auto_attribs=True)
class AuthenticatedClientFromEnv(Client):
"""A Client which has been authenticated for use on secured endpoints that uses the KITTYCAD_API_TOKEN environment variable for the authentication token."""
token: str = attr.ib(default=os.getenv('KITTYCAD_API_TOKEN'))
def get_headers(self) -> Dict[str, str]:
"""Get headers to be used in authenticated endpoints"""
return {"Authorization": f"Bearer {self.token}", **self.headers}