Relay and transit url conf from env vars
Added the click option to look for relay and transit urls in environment variables. If you're running your own relay/transit servers (such as inside a corporate firewall), this will make client's lives easier.
This commit is contained in:
parent
7ad006950a
commit
b362adf7ca
|
@ -60,11 +60,13 @@ class AliasedGroup(click.Group):
|
||||||
"--appid", default=None, metavar="APPID", help="appid to use")
|
"--appid", default=None, metavar="APPID", help="appid to use")
|
||||||
@click.option(
|
@click.option(
|
||||||
"--relay-url", default=public_relay.RENDEZVOUS_RELAY,
|
"--relay-url", default=public_relay.RENDEZVOUS_RELAY,
|
||||||
|
envvar='WORMHOLE_RELAY_URL',
|
||||||
metavar="URL",
|
metavar="URL",
|
||||||
help="rendezvous relay to use",
|
help="rendezvous relay to use",
|
||||||
)
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--transit-helper", default=public_relay.TRANSIT_RELAY,
|
"--transit-helper", default=public_relay.TRANSIT_RELAY,
|
||||||
|
envvar='WORMHOLE_TRANSIT_HELPER',
|
||||||
metavar="tcp:HOST:PORT",
|
metavar="tcp:HOST:PORT",
|
||||||
help="transit relay to use",
|
help="transit relay to use",
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import mock
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
from ..cli.public_relay import RENDEZVOUS_RELAY, TRANSIT_RELAY
|
from ..cli.public_relay import RENDEZVOUS_RELAY, TRANSIT_RELAY
|
||||||
from .common import config
|
from .common import config
|
||||||
|
@ -71,6 +73,31 @@ class Send(unittest.TestCase):
|
||||||
cfg = config("send", "-0", "fn")
|
cfg = config("send", "-0", "fn")
|
||||||
self.assertEqual(cfg.zeromode, True)
|
self.assertEqual(cfg.zeromode, True)
|
||||||
|
|
||||||
|
def test_relay_env_var(self):
|
||||||
|
relay_url = str(mock.sentinel.relay_url)
|
||||||
|
with mock.patch.dict(os.environ, WORMHOLE_RELAY_URL=relay_url):
|
||||||
|
cfg = config("send")
|
||||||
|
self.assertEqual(cfg.relay_url, relay_url)
|
||||||
|
|
||||||
|
# Make sure cmd line option overrides environment variable
|
||||||
|
relay_url_2 = str(mock.sentinel.relay_url_2)
|
||||||
|
with mock.patch.dict(os.environ, WORMHOLE_RELAY_URL=relay_url):
|
||||||
|
cfg = config("--relay-url", relay_url_2, "send")
|
||||||
|
self.assertEqual(cfg.relay_url, relay_url_2)
|
||||||
|
|
||||||
|
def test_transit_env_var(self):
|
||||||
|
transit_url = str(mock.sentinel.transit_url)
|
||||||
|
with mock.patch.dict(os.environ, WORMHOLE_TRANSIT_HELPER=transit_url):
|
||||||
|
cfg = config("send")
|
||||||
|
self.assertEqual(cfg.transit_helper, transit_url)
|
||||||
|
|
||||||
|
# Make sure cmd line option overrides environment variable
|
||||||
|
transit_url_2 = str(mock.sentinel.transit_url_2)
|
||||||
|
with mock.patch.dict(os.environ, WORMHOLE_TRANSIT_HELPER=transit_url):
|
||||||
|
cfg = config("--transit-helper", transit_url_2, "send")
|
||||||
|
self.assertEqual(cfg.transit_helper, transit_url_2)
|
||||||
|
|
||||||
|
|
||||||
class Receive(unittest.TestCase):
|
class Receive(unittest.TestCase):
|
||||||
def test_baseline(self):
|
def test_baseline(self):
|
||||||
cfg = config("receive")
|
cfg = config("receive")
|
||||||
|
@ -140,6 +167,30 @@ class Receive(unittest.TestCase):
|
||||||
cfg = config("receive", "--output-file", "fn")
|
cfg = config("receive", "--output-file", "fn")
|
||||||
self.assertEqual(cfg.output_file, u"fn")
|
self.assertEqual(cfg.output_file, u"fn")
|
||||||
|
|
||||||
|
def test_relay_env_var(self):
|
||||||
|
relay_url = str(mock.sentinel.relay_url)
|
||||||
|
with mock.patch.dict(os.environ, WORMHOLE_RELAY_URL=relay_url):
|
||||||
|
cfg = config("receive")
|
||||||
|
self.assertEqual(cfg.relay_url, relay_url)
|
||||||
|
|
||||||
|
# Make sure cmd line option overrides environment variable
|
||||||
|
relay_url_2 = str(mock.sentinel.relay_url_2)
|
||||||
|
with mock.patch.dict(os.environ, WORMHOLE_RELAY_URL=relay_url):
|
||||||
|
cfg = config("--relay-url", relay_url_2, "receive")
|
||||||
|
self.assertEqual(cfg.relay_url, relay_url_2)
|
||||||
|
|
||||||
|
def test_transit_env_var(self):
|
||||||
|
transit_url = str(mock.sentinel.transit_url)
|
||||||
|
with mock.patch.dict(os.environ, WORMHOLE_TRANSIT_HELPER=transit_url):
|
||||||
|
cfg = config("receive")
|
||||||
|
self.assertEqual(cfg.transit_helper, transit_url)
|
||||||
|
|
||||||
|
# Make sure cmd line option overrides environment variable
|
||||||
|
transit_url_2 = str(mock.sentinel.transit_url_2)
|
||||||
|
with mock.patch.dict(os.environ, WORMHOLE_TRANSIT_HELPER=transit_url):
|
||||||
|
cfg = config("--transit-helper", transit_url_2, "receive")
|
||||||
|
self.assertEqual(cfg.transit_helper, transit_url_2)
|
||||||
|
|
||||||
class Config(unittest.TestCase):
|
class Config(unittest.TestCase):
|
||||||
def test_send(self):
|
def test_send(self):
|
||||||
cfg = config("send")
|
cfg = config("send")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user