Skip to content

Commit d9bdeda

Browse files
committed
Add a dedicated Exemption for auth handlers
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 <xarses@gmail.com>
1 parent 4d248a8 commit d9bdeda

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

oras/auth/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
auth_backends = {"token": TokenAuth, "basic": BasicAuth}
77

88

9+
class AuthenticationException(Exception):
10+
"""
11+
An exception to traise with Authentication errors are fatal
12+
"""
13+
14+
915
def get_auth_backend(name="token", session=None, **kwargs):
1016
backend = auth_backends.get(name)
1117
if not backend:

oras/decorator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import time
66
from functools import partial, update_wrapper
77

8+
import oras.auth
89
from oras.logger import logger
910

1011

@@ -52,6 +53,8 @@ def __call__(self, cls, *args, **kwargs):
5253
while attempt < attempts:
5354
try:
5455
return self.func(cls, *args, **kwargs)
56+
except oras.auth.AuthenticationException as e:
57+
raise e
5558
except Exception as e:
5659
sleep = timeout + 3**attempt
5760
logger.info(f"Retrying in {sleep} seconds - error: {e}")
@@ -71,6 +74,8 @@ def inner(*args, **kwargs):
7174
while attempt < attempts:
7275
try:
7376
return func(*args, **kwargs)
77+
except oras.auth.AuthenticationException as e:
78+
raise e
7479
except Exception as e:
7580
sleep = timeout + 3**attempt
7681
logger.info(f"Retrying in {sleep} seconds - error: {e}")

0 commit comments

Comments
 (0)