Skip to content

Commit

Permalink
Defines default API client settings
Browse files Browse the repository at this point in the history
  • Loading branch information
djperrefort committed Jun 8, 2024
1 parent a964fe7 commit f1f2da7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions apps/utils/keystone.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@

import requests

# Custom types
ResponseContentType = Literal['json', 'text', 'content']
ParsedResponseContent = Union[Dict[str, Any], str, bytes]

# Default API configuratipn
KEYSTONE_URL = "https://keystone.crc.pitt.edu"
KEYSTONE_AUTH_ENDPOINT = 'authentication/new'

CLUSTERS = {1: 'MPI', 2: 'SMP', 3: 'HTC', 4: 'GPU'}
RAWUSAGE_RESET_DATE = date.fromisoformat('2024-05-07')

ResponseContentType = Literal['json', 'text', 'content']
ParsedResponseContent = Union[Dict[str, Any], str, bytes]


class KeystoneApi:
"""API client for submitting requests to the Keystone API"""

def __init__(self, base_url: str) -> None:
def __init__(self, base_url: str = KEYSTONE_URL) -> None:
"""Initializes the KeystoneApi class with the base URL of the API.
Args:
Expand All @@ -26,7 +30,7 @@ def __init__(self, base_url: str) -> None:
self.base_url = base_url
self._token: Optional[str] = None

def login(self, username: str, password: str, endpoint: str = 'authentication/new') -> None:
def login(self, username: str, password: str, endpoint: str = KEYSTONE_AUTH_ENDPOINT) -> None:
"""Logs in to the Keystone API and caches the JWT token.
Args:
Expand Down

0 comments on commit f1f2da7

Please sign in to comment.