-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from freedomofpress/more_typing
Restructures the code base with more object methods
- Loading branch information
Showing
13 changed files
with
552 additions
and
582 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,44 +1,45 @@ | ||
import json | ||
import logging | ||
from typing import Dict, Any | ||
|
||
from securedrop_proxy import callbacks | ||
from securedrop_proxy import proxy | ||
|
||
|
||
from securedrop_proxy.proxy import Proxy | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def __main__(incoming, p): | ||
''' | ||
def __main__(incoming: str, p: Proxy) -> None: | ||
""" | ||
Deserialize incoming request in order to build and send a proxy request. | ||
''' | ||
logging.debug('Creating request to be sent by proxy') | ||
""" | ||
logging.debug("Creating request to be sent by proxy") | ||
|
||
client_req = None | ||
client_req: Dict[str, Any] = {} | ||
try: | ||
client_req = json.loads(incoming) | ||
except json.decoder.JSONDecodeError as e: | ||
logging.error(e) | ||
p.simple_error(400, 'Invalid JSON in request') | ||
p.on_done(p.res) | ||
p.simple_error(400, "Invalid JSON in request") | ||
p.on_done() | ||
return | ||
|
||
req = proxy.Req() | ||
try: | ||
req.method = client_req['method'] | ||
req.path_query = client_req['path_query'] | ||
req.method = client_req["method"] | ||
req.path_query = client_req["path_query"] | ||
except KeyError as e: | ||
logging.error(e) | ||
p.simple_error(400, 'Missing keys in request') | ||
p.on_done(p.res) | ||
p.simple_error(400, "Missing keys in request") | ||
p.on_done() | ||
|
||
if "headers" in client_req: | ||
req.headers = client_req['headers'] | ||
req.headers = client_req["headers"] | ||
|
||
if "body" in client_req: | ||
req.body = client_req['body'] | ||
req.body = client_req["body"] | ||
|
||
p.req = req | ||
if not p.on_save: | ||
p.on_save = callbacks.on_save | ||
|
||
p.proxy() |
Oops, something went wrong.