Enable config file parsing
We support 4 different config files: ~/.mitmproxy/common.conf: Options that are common to all tools ~/.mitmproxy/mitmproxy.conf: Options for mitmproxy ~/.mitmproxy/mitmdump.conf: Options for mitmdump ~/.mitmproxy/mitmweb.conf: Options for mitmweb Options in the tool-specific config files over-ride options in common.conf. If a non-common option is put in common.conf, an error will be raised if a non-supporting tool is used.
This commit is contained in:
parent
6c1dc4522d
commit
09c503563a
|
@ -1,4 +1,5 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import configargparse
|
import configargparse
|
||||||
import argparse
|
import argparse
|
||||||
|
@ -311,7 +312,7 @@ def common_options(parser):
|
||||||
help="Don't start a proxy server."
|
help="Don't start a proxy server."
|
||||||
)
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"-p",
|
"-p", "--port",
|
||||||
action="store", type=int, dest="port", default=8080,
|
action="store", type=int, dest="port", default=8080,
|
||||||
help="Proxy service port."
|
help="Proxy service port."
|
||||||
)
|
)
|
||||||
|
@ -520,7 +521,16 @@ def mitmproxy():
|
||||||
# platforms.
|
# platforms.
|
||||||
from .console import palettes
|
from .console import palettes
|
||||||
|
|
||||||
parser = configargparse.ArgumentParser(usage="%(prog)s [options]")
|
parser = configargparse.ArgumentParser(
|
||||||
|
usage="%(prog)s [options]",
|
||||||
|
args_for_setting_config_path = ["--conf"],
|
||||||
|
default_config_files = [
|
||||||
|
os.path.join(config.CA_DIR, "common.conf"),
|
||||||
|
os.path.join(config.CA_DIR, "mitmproxy.conf")
|
||||||
|
],
|
||||||
|
add_config_file_help = True,
|
||||||
|
add_env_var_help = True
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--version',
|
'--version',
|
||||||
action='version',
|
action='version',
|
||||||
|
@ -551,7 +561,16 @@ def mitmproxy():
|
||||||
|
|
||||||
|
|
||||||
def mitmdump():
|
def mitmdump():
|
||||||
parser = configargparse.ArgumentParser(usage="%(prog)s [options] [filter]")
|
parser = configargparse.ArgumentParser(
|
||||||
|
usage="%(prog)s [options] [filter]",
|
||||||
|
args_for_setting_config_path = ["--conf"],
|
||||||
|
default_config_files = [
|
||||||
|
os.path.join(config.CA_DIR, "common.conf"),
|
||||||
|
os.path.join(config.CA_DIR, "mitmdump.conf")
|
||||||
|
],
|
||||||
|
add_config_file_help = True,
|
||||||
|
add_env_var_help = True
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--version',
|
'--version',
|
||||||
|
@ -577,7 +596,16 @@ def mitmdump():
|
||||||
|
|
||||||
|
|
||||||
def mitmweb():
|
def mitmweb():
|
||||||
parser = configargparse.ArgumentParser(usage="%(prog)s [options]")
|
parser = configargparse.ArgumentParser(
|
||||||
|
usage="%(prog)s [options]",
|
||||||
|
args_for_setting_config_path = ["--conf"],
|
||||||
|
default_config_files = [
|
||||||
|
os.path.join(config.CA_DIR, "common.conf"),
|
||||||
|
os.path.join(config.CA_DIR, "mitmweb.conf")
|
||||||
|
],
|
||||||
|
add_config_file_help = True,
|
||||||
|
add_env_var_help = True
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--version',
|
'--version',
|
||||||
action='version',
|
action='version',
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import argparse
|
import argparse
|
||||||
from libmproxy import cmdline
|
from libmproxy import cmdline
|
||||||
import tutils
|
import tutils
|
||||||
import os.path
|
|
||||||
|
|
||||||
|
|
||||||
def test_parse_replace_hook():
|
def test_parse_replace_hook():
|
||||||
|
@ -51,6 +50,7 @@ def test_parse_setheaders():
|
||||||
x = cmdline.parse_setheader("/foo/bar/voing")
|
x = cmdline.parse_setheader("/foo/bar/voing")
|
||||||
assert x == ("foo", "bar", "voing")
|
assert x == ("foo", "bar", "voing")
|
||||||
|
|
||||||
|
|
||||||
def test_common():
|
def test_common():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
cmdline.common_options(parser)
|
cmdline.common_options(parser)
|
||||||
|
@ -108,3 +108,19 @@ def test_common():
|
||||||
assert len(v) == 1
|
assert len(v) == 1
|
||||||
assert v[0][2].strip() == "replacecontents"
|
assert v[0][2].strip() == "replacecontents"
|
||||||
|
|
||||||
|
|
||||||
|
def test_mitmproxy():
|
||||||
|
ap = cmdline.mitmproxy()
|
||||||
|
assert ap
|
||||||
|
|
||||||
|
|
||||||
|
def test_mitmdump():
|
||||||
|
ap = cmdline.mitmdump()
|
||||||
|
assert ap
|
||||||
|
|
||||||
|
|
||||||
|
def test_mitmweb():
|
||||||
|
ap = cmdline.mitmweb()
|
||||||
|
assert ap
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue