-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/presign-configuration-version-internal' into 'm…
…ain' fix: Use pre-signed keys for API authentication to upload configuration version Closes #177 and #161 See merge request pub/terra/terrarun!91
- Loading branch information
Showing
5 changed files
with
150 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (C) 2024 Matt Comben - All Rights Reserved | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
|
||
from typing import Tuple | ||
|
||
from flask import request | ||
|
||
from terrarun.logger import get_logger | ||
from terrarun.models.user import User | ||
from terrarun.presign import PresignedRequestValidator, PresignedRequestValidatorError | ||
from terrarun.server.authenticated_endpoint import AuthenticatedEndpoint | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class SignatureAuthenticatedEndpoint(AuthenticatedEndpoint): | ||
"""Authenticated endpoint""" | ||
|
||
def _get_current_user(self) -> Tuple[User | None, None]: | ||
"""Verify the signature and return the effective user""" | ||
|
||
try: | ||
user_id = PresignedRequestValidator().validate(request) | ||
except PresignedRequestValidatorError as e: | ||
logger.warning("Failed to authenticate with signature. Error: %s", e) | ||
return None, None | ||
|
||
effective_user: User | None = User.get_by_id(user_id) | ||
|
||
return effective_user, None |