Skip to content

Commit

Permalink
Make auth usage less error-ful and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
mattprintz committed Jan 30, 2024
1 parent 326a78c commit d58ed77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "askem-beaker"
version = "1.0.0"
version = "1.0.1"
description = ""
readme = "README.md"
requires-python = ">=3.10"
Expand All @@ -22,7 +22,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"beaker-kernel>=1.2.0",
"beaker-kernel>=1.2.7",
"pandas==1.3.3",
"matplotlib~=3.7.1",
"xarray==0.19.0",
Expand Down
21 changes: 11 additions & 10 deletions src/askem_beaker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ class TerariumAuth:
password: str

def __init__(self) -> None:
username = os.environ.get("AUTH_USERNAME", None)
password = os.environ.get("AUTH_PASSWORD", None)
if username and password:
self.username = username
self.password = password
else:
raise ValueError("Authentication details not provided")
self.username = os.environ.get("AUTH_USERNAME", None)
self.password = os.environ.get("AUTH_PASSWORD", None)

def auth_header(self) -> dict[str, str]:
token = b64encode(f"{self.username}:{self.password}".encode('utf-8')).decode("ascii")
return {"Authorization": f"Basic {token}"}
if self.username and self.password:
token = b64encode(f"{self.username}:{self.password}".encode('utf-8')).decode("ascii")
return {"Authorization": f"Basic {token}"}
else:
return None

def requests_auth(self) -> HTTPBasicAuth:
return HTTPBasicAuth(self.username, self.password)
if self.username and self.password:
return HTTPBasicAuth(self.username, self.password)
else:
return None


def get_auth() -> TerariumAuth|None:
Expand Down

0 comments on commit d58ed77

Please sign in to comment.