Skip to content

Commit

Permalink
Add a dedicated Exemption for auth handlers
Browse files Browse the repository at this point in the history
In 4d248a8 we removed the sys.exit(...) but that now allows for auth failures
to be retried by the decorators. Adding a dedicated Exemption so we don't have
to retry on fatal auth-failures

Signed-off-by: Andrew Woodward <[email protected]>
  • Loading branch information
xarses committed Sep 17, 2024
1 parent 4d248a8 commit d9bdeda
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions oras/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
auth_backends = {"token": TokenAuth, "basic": BasicAuth}


class AuthenticationException(Exception):
"""
An exception to traise with Authentication errors are fatal
"""


def get_auth_backend(name="token", session=None, **kwargs):
backend = auth_backends.get(name)
if not backend:
Expand Down
5 changes: 5 additions & 0 deletions oras/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
from functools import partial, update_wrapper

import oras.auth
from oras.logger import logger


Expand Down Expand Up @@ -52,6 +53,8 @@ def __call__(self, cls, *args, **kwargs):
while attempt < attempts:
try:
return self.func(cls, *args, **kwargs)
except oras.auth.AuthenticationException as e:
raise e
except Exception as e:
sleep = timeout + 3**attempt
logger.info(f"Retrying in {sleep} seconds - error: {e}")
Expand All @@ -71,6 +74,8 @@ def inner(*args, **kwargs):
while attempt < attempts:
try:
return func(*args, **kwargs)
except oras.auth.AuthenticationException as e:
raise e
except Exception as e:
sleep = timeout + 3**attempt
logger.info(f"Retrying in {sleep} seconds - error: {e}")
Expand Down

0 comments on commit d9bdeda

Please sign in to comment.