Skip to content

Commit

Permalink
feat: Catch auth session between requests
Browse files Browse the repository at this point in the history
The auth module is now cached and reused for folloup registry requests.

Previously each request to registry initialized a new session which lead
to reset the access token and need of establish secret session all over
again. This is now fixed and leads to huge performance improvement when
making multiple queries to a registry.

JIRA: ISV-4429

Signed-off-by: Ales Raszka <araszka@redhat.com>
  • Loading branch information
Allda committed Jan 18, 2024
1 parent 5a48667 commit 337723a
Show file tree
Hide file tree
Showing 2 changed files with 456 additions and 559 deletions.
8 changes: 7 additions & 1 deletion coregio/registry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(
self.proxy = proxy

self.auth_header = None
self._auth_session_cache = {}

@staticmethod
def _normalize_registry_url(url: str) -> str:
Expand Down Expand Up @@ -189,7 +190,12 @@ def _get_session(self, auth_class: Callable[[Any], Any]) -> requests.Session:
"""

auth_token = self._get_auth_token()
self.session.auth = auth_class(auth_token, proxy=self.proxy)
if auth_class not in self._auth_session_cache:
# Create a new auth session and cache it
self._auth_session_cache[auth_class] = auth_class(
auth_token, proxy=self.proxy
)
self.session.auth = self._auth_session_cache[auth_class]
utils.add_session_retries(self.session)

return self.session
Expand Down
Loading

0 comments on commit 337723a

Please sign in to comment.