Skip to content

Commit 7a9e1e5

Browse files
committed
rekor: Refactor Session handling in RekorClient
Make every RekorLog have a Session of their own by default. This means RekorClient no longer needs to manage that. Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent 05168c3 commit 7a9e1e5

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

sigstore/_internal/rekor/client.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,20 @@ def from_response(cls, dict_: dict[str, Any]) -> RekorLogInfo:
7373

7474

7575
class _Endpoint(ABC):
76-
def __init__(self, url: str, session: requests.Session) -> None:
76+
def __init__(self, url: str, session: requests.Session | None = None) -> None:
7777
# Note that _Endpoint may not be thread be safe if the same Session is provided
7878
# to an _Endpoint in multiple threads
7979
self.url = url
80+
if session is None:
81+
session = requests.Session()
82+
session.headers.update(
83+
{
84+
"Content-Type": "application/json",
85+
"Accept": "application/json",
86+
"User-Agent": USER_AGENT,
87+
}
88+
)
89+
8090
self.session = session
8191

8292

@@ -213,19 +223,6 @@ def __init__(self, url: str) -> None:
213223
"""
214224
self.url = f"{url}/api/v1"
215225

216-
def _session(self) -> requests.Session:
217-
# We do not use a long living session to avoid potential thread safety issues:
218-
# submitting entries via create_entry() should be thread safe.
219-
session = requests.Session()
220-
session.headers.update(
221-
{
222-
"Content-Type": "application/json",
223-
"Accept": "application/json",
224-
"User-Agent": USER_AGENT,
225-
}
226-
)
227-
return session
228-
229226
@classmethod
230227
def production(cls) -> RekorClient:
231228
"""
@@ -248,9 +245,7 @@ def log(self) -> RekorLog:
248245
Returns a `RekorLog` adapter for making requests to a Rekor log.
249246
"""
250247

251-
# Each RekorLog gets their own session
252-
with self._session() as s:
253-
return RekorLog(f"{self.url}/log", session=s)
248+
return RekorLog(f"{self.url}/log")
254249

255250
def create_entry(self, request: EntryRequestBody) -> LogEntry:
256251
"""

0 commit comments

Comments
 (0)