Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
bhperry committed Jun 10, 2024
1 parent 88116d7 commit ac9cede
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions saturnfs/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from json import JSONDecodeError

from requests import Response


Expand Down
9 changes: 7 additions & 2 deletions saturnfs/session.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from threading import Lock
from typing import Any, Dict, Optional
from urllib.parse import urljoin
import requests

import requests
from saturnfs import settings
from saturnfs.errors import SaturnError
from saturnfs.utils import requests_session


class SaturnSession(requests.Session):
"""
Session wrapper to manage refreshing tokens for the Saturn API
when they expire and retrying the request.
"""

def __init__(self, **kwargs) -> None:
super().__init__()
requests_session(self, **kwargs)
Expand Down Expand Up @@ -65,7 +67,10 @@ def _refresh(self, response: Optional[requests.Response] = None) -> bool:

if settings.SATURN_REFRESH_TOKEN:
url = urljoin(settings.SATURN_BASE_URL, "api/auth/token")
data = {"grant_type": "refresh_token", "refresh_token": settings.SATURN_REFRESH_TOKEN}
data = {
"grant_type": "refresh_token",
"refresh_token": settings.SATURN_REFRESH_TOKEN,
}
# Intentionally not using the current session here
response = requests.post(url, json=data, hooks={})
if response.ok:
Expand Down

0 comments on commit ac9cede

Please sign in to comment.