Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 17ed181

Browse files
committed
fix: token retrieval error when config is not setup
1 parent e4924ba commit 17ed181

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

codecov_auth/authentication/repo_auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from django.utils import timezone
1010
from jwt import PyJWTError
1111
from rest_framework import authentication, exceptions, serializers
12-
from rest_framework.exceptions import NotAuthenticated
12+
from rest_framework.exceptions import NotAuthenticated, ValidationError
1313
from rest_framework.response import Response
1414
from rest_framework.views import exception_handler
1515
from shared.django_apps.codecov_auth.models import Owner
@@ -200,7 +200,7 @@ def authenticate(
200200
if not using_global_token:
201201
return None # continue to next auth class
202202

203-
service = global_tokens[token]
203+
service = global_tokens.get(token, "")
204204
upload_info = get_upload_info_from_request_path(request)
205205
if upload_info is None:
206206
return None # continue to next auth class
@@ -257,7 +257,7 @@ def authenticate_credentials(
257257

258258
try:
259259
repository = get_repo_with_github_actions_oidc_token(token)
260-
except (ObjectDoesNotExist, PyJWTError):
260+
except (ObjectDoesNotExist, PyJWTError, ValidationError):
261261
return None # continue to next auth class
262262

263263
log.info(

upload/helpers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ def get_repo_with_github_actions_oidc_token(token: str) -> Repository:
243243
else:
244244
service = "github_enterprise"
245245
github_enterprise_url = get_config("github_enterprise", "url")
246+
if not github_enterprise_url:
247+
raise ValidationError(
248+
"GitHub Enterprise URL configuration is not set configuration"
249+
)
246250
# remove trailing slashes if present
247251
github_enterprise_url = re.sub(r"/+$", "", github_enterprise_url)
248252
jwks_url = f"{github_enterprise_url}/_services/token/.well-known/jwks"
@@ -525,7 +529,7 @@ def insert_commit(
525529
return commit
526530

527531

528-
def get_global_tokens() -> Dict[str, Any]:
532+
def get_global_tokens() -> Dict[str | None, Any]:
529533
"""
530534
Enterprise only: check the config to see if global tokens were set for this organization's uploads.
531535

0 commit comments

Comments
 (0)