Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
refactor: .conf -> .router_conf
Browse files Browse the repository at this point in the history
and standardize on .router_conf within routers (for now anyway)
  • Loading branch information
pjenvey committed Jul 31, 2017
1 parent db44b4a commit fe2259b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions autopush/router/apnsrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _connect(self, rel_channel, load_connections=True):
"""
default_topic = "com.mozilla.org." + rel_channel
cert_info = self._config[rel_channel]
cert_info = self.router_conf[rel_channel]
return APNSClient(
cert_file=cert_info.get("cert"),
key_file=cert_info.get("key"),
Expand All @@ -61,11 +61,11 @@ def __init__(self, ap_settings, router_conf, metrics,
"""
self.ap_settings = ap_settings
self._config = router_conf
self.router_conf = router_conf
self.metrics = metrics
self._base_tags = ["platform:apns"]
self.apns = dict()
for rel_channel in self._config:
for rel_channel in router_conf:
self.apns[rel_channel] = self._connect(rel_channel,
load_connections)
self.ap_settings = ap_settings
Expand Down
4 changes: 2 additions & 2 deletions autopush/router/fcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class FCMRouter(object):
def __init__(self, ap_settings, router_conf, metrics):
"""Create a new FCM router and connect to FCM"""
self.ap_settings = ap_settings
self.config = router_conf
self.router_conf = router_conf
self.metrics = metrics
self.min_ttl = router_conf.get("ttl", 60)
self.dryRun = router_conf.get("dryrun", False)
Expand Down Expand Up @@ -165,7 +165,7 @@ def _route(self, notification, router_data):
# Payload data is optional. The endpoint handler validates that the
# correct encryption headers are included with the data.
if notification.data:
mdata = self.config.get('max_data', 4096)
mdata = self.router_conf.get('max_data', 4096)
if notification.data_length > mdata:
raise self._error("This message is intended for a " +
"constrained device and is limited " +
Expand Down
4 changes: 2 additions & 2 deletions autopush/router/gcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GCMRouter(object):
def __init__(self, ap_settings, router_conf, metrics):
"""Create a new GCM router and connect to GCM"""
self.ap_settings = ap_settings
self.config = router_conf
self.router_conf = router_conf
self.metrics = metrics
self.min_ttl = router_conf.get("ttl", 60)
self.dryRun = router_conf.get("dryrun", False)
Expand Down Expand Up @@ -82,7 +82,7 @@ def _route(self, notification, uaid_data):
# Payload data is optional. The endpoint handler validates that the
# correct encryption headers are included with the data.
if notification.data:
mdata = self.config.get('max_data', 4096)
mdata = self.router_conf.get('max_data', 4096)
if notification.data_length > mdata:
raise self._error("This message is intended for a " +
"constrained device and is limited " +
Expand Down
10 changes: 5 additions & 5 deletions autopush/router/webpush.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class WebPushRouter(object):
def __init__(self, ap_settings, router_conf, db, agent):
"""Create a new Router"""
self.ap_settings = ap_settings
self.conf = router_conf
self.router_conf = router_conf
self.db = db
self.agent = agent
self.waker = None
Expand Down Expand Up @@ -153,15 +153,15 @@ def route_notification(self, notification, uaid_data):
returnValue(self.delivered_response(notification))
else:
ret_val = self.stored_response(notification)
if self.udp is not None and "server" in self.conf:
if self.udp is not None and "server" in self.router_conf:
# Attempt to send off the UDP wake request.
try:
yield deferToThread(
requests.post(
self.conf["server"],
self.router_conf["server"],
data=urlencode(self.udp["data"]),
cert=self.conf.get("cert"),
timeout=self.conf.get("server_timeout", 3)))
cert=self.router_conf.get("cert"),
timeout=self.router_conf.get("server_timeout", 3)))
except Exception as exc:
self.log.debug("Could not send UDP wake request: {exc}",
exc=exc)
Expand Down
6 changes: 3 additions & 3 deletions autopush/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ def test_settings(self, *args):
app = EndpointApplication(settings)
# verify that the hostname is what we said.
eq_(settings.hostname, self.TestArg.hostname)
eq_(app.routers["gcm"].config['collapsekey'], "collapse")
eq_(app.routers["apns"]._config['firefox']['cert'], "cert.file")
eq_(app.routers["apns"]._config['firefox']['key'], "key.file")
eq_(app.routers["gcm"].router_conf['collapsekey'], "collapse")
eq_(app.routers["apns"].router_conf['firefox']['cert'], "cert.file")
eq_(app.routers["apns"].router_conf['firefox']['key'], "key.file")
eq_(settings.wake_timeout, 10)

def test_bad_senders(self):
Expand Down
4 changes: 2 additions & 2 deletions autopush/tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,8 +1128,8 @@ def test_route_udp(self, request_mock):
router_data = dict(node_id="http://somewhere", uaid=dummy_uaid,
udp=udp_data)
self.router_mock.get_uaid.return_value = router_data
self.router.conf = {'server': 'http://example.com',
'idle': 1, 'cert': 'test.pem'}
self.router.router_conf = {'server': 'http://example.com',
'idle': 1, 'cert': 'test.pem'}

d = self.router.route_notification(self.notif, router_data)

Expand Down

0 comments on commit fe2259b

Please sign in to comment.