Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions twitcher/adapter/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ def response_hook(self, response: Response, service: ServiceConfig) -> Response:
"""
raise NotImplementedError

def verify_hook(self, request: Request, service: ServiceConfig) -> bool:
"""
Apply additional logic used to verify whether a request should be rejected.

.. versionadded:: 0.11.2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd consider this a 0.12.0.


Return False to indicate that the verify endpoint should return a "forbidden"
response regardless of whether the request is verified.
Comment on lines +84 to +85

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use False quotes

"""
raise NotImplementedError

def send_request(self, request: Request, service: ServiceConfig) -> Response:
"""
Performs the provided request in order to obtain a proxied response.
Expand Down
3 changes: 3 additions & 0 deletions twitcher/adapter/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@ def request_hook(self, request, service):
def response_hook(self, response, service):
return response

def verify_hook(self, request, service):
return True

def send_request(self, request: Request, service: ServiceConfig) -> Response:
return send_request(request, service)
4 changes: 3 additions & 1 deletion twitcher/owsproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ def owsverify_view(request: Request) -> Response:
try:
service_name = request.matchdict.get('service_name')
service = request.owsregistry.get_service_by_name(service_name)
if service and request.is_verified:
adapter = request.adapter
hook_success = adapter.verify_hook(request, service)
if service and hook_success and request.is_verified:
message, status, access = "allowed", 200, True
except Exception as exc:
LOGGER.exception("Security check failed due to unhandled error.", exc_info=exc)
Expand Down
Loading