|
16 | 16 | import ipaddress
|
17 | 17 | import collections
|
18 | 18 | import multiprocessing
|
| 19 | +from typing import Any, List, Optional, cast |
19 | 20 |
|
20 |
| -from typing import Optional, List, Any, cast |
21 |
| - |
22 |
| -from .plugins import Plugins |
23 | 21 | from .types import IpAddress
|
24 | 22 | from .utils import bytes_, is_py2, is_threadless, set_open_file_limit
|
25 |
| -from .constants import COMMA, DEFAULT_DATA_DIRECTORY_PATH, DEFAULT_NUM_ACCEPTORS, DEFAULT_NUM_WORKERS |
26 |
| -from .constants import DEFAULT_DEVTOOLS_WS_PATH, DEFAULT_DISABLE_HEADERS, PY2_DEPRECATION_MESSAGE |
27 |
| -from .constants import PLUGIN_DASHBOARD, PLUGIN_DEVTOOLS_PROTOCOL, DEFAULT_MIN_COMPRESSION_LIMIT |
28 |
| -from .constants import PLUGIN_HTTP_PROXY, PLUGIN_INSPECT_TRAFFIC, PLUGIN_PAC_FILE |
29 |
| -from .constants import PLUGIN_WEB_SERVER, PLUGIN_PROXY_AUTH, IS_WINDOWS, PLUGIN_WEBSOCKET_TRANSPORT |
30 | 23 | from .logger import Logger
|
31 |
| - |
| 24 | +from .plugins import Plugins |
32 | 25 | from .version import __version__
|
| 26 | +from .constants import ( |
| 27 | + COMMA, IS_WINDOWS, PLUGIN_PAC_FILE, PLUGIN_DASHBOARD, PLUGIN_HTTP_PROXY, |
| 28 | + PLUGIN_PROXY_AUTH, PLUGIN_WEB_SERVER, DEFAULT_NUM_WORKERS, |
| 29 | + DEFAULT_NUM_ACCEPTORS, PLUGIN_INSPECT_TRAFFIC, DEFAULT_DISABLE_HEADERS, |
| 30 | + PY2_DEPRECATION_MESSAGE, DEFAULT_DEVTOOLS_WS_PATH, |
| 31 | + PLUGIN_DEVTOOLS_PROTOCOL, PLUGIN_WEBSOCKET_TRANSPORT, |
| 32 | + DEFAULT_DATA_DIRECTORY_PATH, DEFAULT_MIN_COMPRESSION_LIMIT, |
| 33 | +) |
| 34 | + |
33 | 35 |
|
34 | 36 | __homepage__ = 'https://github.com/abhinavsingh/proxy.py'
|
35 | 37 |
|
@@ -96,13 +98,17 @@ def initialize(
|
96 | 98 | print(PY2_DEPRECATION_MESSAGE)
|
97 | 99 | sys.exit(1)
|
98 | 100 |
|
| 101 | + # Dirty hack to always discover --basic-auth flag |
| 102 | + # defined by proxy auth plugin. |
| 103 | + in_args = input_args + ['--plugin', PLUGIN_PROXY_AUTH] |
| 104 | + |
99 | 105 | # Discover flags from requested plugin.
|
100 | 106 | # This will also surface external plugin flags
|
101 | 107 | # under --help.
|
102 |
| - Plugins.discover(input_args) |
| 108 | + Plugins.discover(in_args) |
103 | 109 |
|
104 | 110 | # Parse flags
|
105 |
| - args = flags.parse_args(input_args) |
| 111 | + args = flags.parse_args(in_args) |
106 | 112 |
|
107 | 113 | # Print version and exit
|
108 | 114 | if args.version:
|
@@ -135,9 +141,11 @@ def initialize(
|
135 | 141 | if isinstance(work_klass, str) \
|
136 | 142 | else work_klass
|
137 | 143 |
|
| 144 | + # TODO: Plugin flag initialization logic must be moved within plugins. |
| 145 | + # |
138 | 146 | # Generate auth_code required for basic authentication if enabled
|
139 | 147 | auth_code = None
|
140 |
| - basic_auth = opts.get('basic_auth', args.basic_auth) |
| 148 | + basic_auth = opts.get('basic_auth', getattr(args, 'basic_auth', None)) |
141 | 149 | # Destroy passed credentials via flags or options
|
142 | 150 | args.basic_auth = None
|
143 | 151 | if 'basic_auth' in opts:
|
|
0 commit comments