Skip to content

Commit

Permalink
fix diagnostic info in parse_verification_key
Browse files Browse the repository at this point in the history
Signed-off-by: Achille Roussel <[email protected]>
  • Loading branch information
achille-roussel committed Apr 22, 2024
1 parent 50377d7 commit 49da99e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/dispatch/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(
"missing FastAPI app as first argument of the Dispatch constructor"
)
super().__init__(endpoint, api_key=api_key, api_url=api_url)
verification_key = parse_verification_key(verification_key, url_scheme=parsed_url.scheme)
verification_key = parse_verification_key(verification_key, endpoint=endpoint)
function_service = _new_app(self, verification_key)
app.mount("/dispatch.sdk.v1.FunctionService", function_service)

Expand Down
11 changes: 10 additions & 1 deletion src/dispatch/signature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from datetime import datetime, timedelta
from typing import Optional, Sequence, Set, Union, cast
from urllib.parse import urlparse

import http_sfv
from cryptography.hazmat.primitives.asymmetric.ed25519 import (
Expand Down Expand Up @@ -129,7 +130,7 @@ def extract_covered_components(result: VerifyResult) -> Set[str]:

def parse_verification_key(
verification_key: Optional[Union[Ed25519PublicKey, str, bytes]],
url_scheme: str | None = None,
endpoint: Optional[str] = None,
) -> Optional[Ed25519PublicKey]:
# This function depends a lot on global context like enviornment variables
# and logging configuration. It's not ideal for testing, but it's useful to
Expand Down Expand Up @@ -175,6 +176,14 @@ def parse_verification_key(
raise ValueError(f"invalid verification key '{verification_key}'")

# Print diagostic information about the key, this is useful for debugging.
url_scheme = ""
if endpoint:
try:
parsed_url = urlparse(endpoint)
url_scheme = parsed_url.scheme
except:
pass

if public_key:
base64_key = base64.b64encode(public_key.public_bytes_raw()).decode()
logger.info("verifying request signatures using key %s", base64_key)
Expand Down

0 comments on commit 49da99e

Please sign in to comment.