Skip to content

Add a dedicated Exemption for auth handlers #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading