Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tproxy support for script cli args #5

Open
cosminbasca opened this issue Jul 4, 2012 · 0 comments
Open

tproxy support for script cli args #5

cosminbasca opened this issue Jul 4, 2012 · 0 comments

Comments

@cosminbasca
Copy link
Contributor

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):

$ 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:

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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant