diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-10-10 10:55:46 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-10-10 10:55:46 +0200 |
commit | 39ba8a202f4010286b99c3ac34003ffa329153c5 (patch) | |
tree | 41fb65be3fe77bbb97e59db86f9a43f03b8bb50b | |
parent | 9f8c3e2d3bcf9ddda42592bc51803754828e3151 (diff) | |
download | haketilo-hydrilla-39ba8a202f4010286b99c3ac34003ffa329153c5.tar.gz haketilo-hydrilla-39ba8a202f4010286b99c3ac34003ffa329153c5.zip |
[proxy] load console_scripts entry instead of launching mitmproxy with os.subprocess
-rw-r--r-- | src/hydrilla/mitmproxy_launcher/launch.py | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/hydrilla/mitmproxy_launcher/launch.py b/src/hydrilla/mitmproxy_launcher/launch.py index 8133413..e197ad5 100644 --- a/src/hydrilla/mitmproxy_launcher/launch.py +++ b/src/hydrilla/mitmproxy_launcher/launch.py @@ -37,12 +37,18 @@ import os import subprocess as sp from pathlib import Path +# The following import requires at least Python 3.8. There is no point adding +# a workaround for Python 3.7 because mitmproxy itself (which we're loading +# here) relies on Python 3.9+. This does not affect the Hydrilla server and +# builder which continue to work under Python 3.7. +from importlib.metadata import distribution import click from .. import _version from ..translations import smart_gettext as _ + addon_script_text = ''' from hydrilla.proxy.addon import HaketiloAddon @@ -70,12 +76,19 @@ def launch(port: int, directory: str): script_path.write_text(addon_script_text) - code = sp.call(['mitmdump', - '-p', str(port), - '--set', f'confdir={directory_path / "mitmproxy"}', - '--set', 'upstream_cert=false', - '--set', 'connection_strategy=lazy', - '--set', f'haketilo_dir={directory_path}', - '--scripts', str(script_path)]) + sys.argv = [ + 'mitmdump', + '-p', str(port), + '--set', f'confdir={directory_path / "mitmproxy"}', + '--set', 'upstream_cert=false', + '--set', 'connection_strategy=lazy', + '--set', f'haketilo_dir={directory_path}', + '--scripts', str(script_path) + ] + + for entry_point in distribution('mitmproxy').entry_points: + if entry_point.group == 'console_scripts' and \ + entry_point.name == 'mitmdump': + sys.exit(entry_point.load()()) - sys.exit(code) + sys.exit(1) |