33import logging
44import os
55from datetime import timedelta
6- from typing import Optional , Union
76from http .server import BaseHTTPRequestHandler
7+ from typing import Optional , Union
8+
89from http_message_signatures import InvalidSignature
910
1011from dispatch .function import Registry
@@ -27,7 +28,10 @@ class Dispatch:
2728 acts as a factory for DispatchHandler objects, by capturing the variables
2829 that would be shared between all DispatchHandler instances it created."""
2930
30- def __init__ ( self , registry : Registry , verification_key : Optional [Union [Ed25519PublicKey , str , bytes ]] = None ,
31+ def __init__ (
32+ self ,
33+ registry : Registry ,
34+ verification_key : Optional [Union [Ed25519PublicKey , str , bytes ]] = None ,
3135 ):
3236 """Initialize a Dispatch http handler.
3337
@@ -38,16 +42,29 @@ def __init__( self, registry: Registry, verification_k
3842 self .verification_key = parse_verification_key (verification_key )
3943
4044 def __call__ (self , request , client_address , server ):
41- return FunctionService (request , client_address , server , registry = self .registry , verification_key = self .verification_key )
45+ return FunctionService (
46+ request ,
47+ client_address ,
48+ server ,
49+ registry = self .registry ,
50+ verification_key = self .verification_key ,
51+ )
4252
4353
4454class FunctionService (BaseHTTPRequestHandler ):
4555
46- def __init__ (self , request , client_address , server , registry : Registry , verification_key : Optional [Ed25519PublicKey ] = None ):
56+ def __init__ (
57+ self ,
58+ request ,
59+ client_address ,
60+ server ,
61+ registry : Registry ,
62+ verification_key : Optional [Ed25519PublicKey ] = None ,
63+ ):
4764 super ().__init__ (request , client_address , server )
4865 self .registry = registry
4966 self .verification_key = verification_key
50- self .error_content_type = ' application/json'
67+ self .error_content_type = " application/json"
5168
5269 def send_error_response_invalid_argument (self , message : str ):
5370 self .send_error_response (400 , "invalid_argument" , message )
@@ -80,8 +97,8 @@ def do_POST(self):
8097
8198 if self .verification_key is not None :
8299 signed_request = Request (
83- method = ' POST' ,
84- url = self .requestline , # TODO: need full URL
100+ method = " POST" ,
101+ url = self .requestline , # TODO: need full URL
85102 headers = CaseInsensitiveDict (self .headers ),
86103 body = data ,
87104 )
@@ -108,7 +125,9 @@ def do_POST(self):
108125 func = self .registry .functions [req .function ]
109126 except KeyError :
110127 logger .debug ("function '%s' not found" , req .function )
111- self .send_error_response_not_found (f"function '{ req .function } ' does not exist" )
128+ self .send_error_response_not_found (
129+ f"function '{ req .function } ' does not exist"
130+ )
112131 return
113132
114133 logger .info ("running function '%s'" , req .function )
0 commit comments