benoitc / benoitc/tproxy

tproxy support for script cli args

Open
#5 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
269
Forks
33
PR merge metrics
No merged PRs in 30d

Description

extend tproxy such that command line arguments can be passed all the way to the called script.

Current workaround:

assume the following command line (notice the extra --remote argument):

``` bash
$ dproxy.py --daemon --log-file=MyLogFile.log --bind=127.0.0.1:5678 --remote=130.130.130.130:6789 transparent2.py
```

where dproxy.py replaces tproxy by supporting the --remote cli argument as follows:

``` python
from tproxy.app import run
from tproxy.config import *
import os

class RemoteAddress(Setting):
name = "remote"
section = "the address of the remote host"
cli = ["-r", "--remote"]
meta = "REMOTEADDRESS"
default = "127.0.0.1:8080"
validator = validate_string
desc = """\
address of remote host to connect to
"""
run()
```

while transparent2.py would look as follows:

``` python
import argparse

# parse the arguments
parser = argparse.ArgumentParser()
parser.add_argument('--remote', dest='remote', action='store', type=str, default=None)
args, remainder = parser.parse_known_args()

ip, port = args.remote.split(':')

def proxy(data):
return {'remote': (ip, int(port))}
```

although this approach works, it's still nicer if tproxy would provide support for extra cli arguments and possibly facilitate access to them without going through argparse in the called script.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.