This repository has been archived by the owner on Jan 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructures the code base with more object methods
proxy.py Now, Proxy class gets a must conf_path argument, and it creates the inital `conf` attribute from that. Proxy also has default on_save and on_done and err_on_done methods. def handle_response(self) method has a `assert self.res` to mark that res is populated before this call. This is for mypy main.py Mostly has changes from black entrypoint.py No need for fancy dynamic err_call_back, the proxy object will call self.err_call_back if any issue in reading configuration. The test cases now have thier own configuration files to create the proxy object. Also, to do proper dynamic attachment of any method of Proxy class we are using https://docs.python.org/3/library/types.html#types.MethodType so that our own on_save or on_done or err_on_done will be called during tests.
- Loading branch information
Showing
12 changed files
with
548 additions
and
554 deletions.
There are no files selected for viewing
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.