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

Commit

Permalink
feat: add gcm endpoint configuration argument
Browse files Browse the repository at this point in the history
Closes #1315
  • Loading branch information
bbangert committed Jan 18, 2019
1 parent 409f1ab commit 5fd37e2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
3 changes: 2 additions & 1 deletion autopush/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ def from_argparse(cls, ns, **kwargs):
"dryrun": ns.gcm_dryrun,
"max_data": ns.max_data,
"collapsekey": ns.gcm_collapsekey,
"senderIDs": sender_ids}
"senderIDs": sender_ids,
"endpoint": ns.gcm_endpoint}
client_certs = None
# endpoint only
if getattr(ns, 'client_certs', None):
Expand Down
3 changes: 3 additions & 0 deletions autopush/main_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ def _add_external_router_args(parser):
env_var="GCM_COLLAPSEKEY")
parser.add_argument('--senderid_list', help='GCM SenderIDs/auth keys',
type=str, default="{}", env_var="SENDERID_LIST")
parser.add_argument('--gcm_endpoint', help="%s endpoint to use" % label,
type=str, default="gcm-http.googleapis.com/gcm/send",
env_var="GCM_ENDPOINT")
# FCM
parser.add_argument('--fcm_enabled', help="Enable FCM Bridge",
action="store_true", default=False,
Expand Down
4 changes: 3 additions & 1 deletion autopush/router/gcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ def __init__(self, conf, router_conf, metrics):
timeout = router_conf.get("timeout", DEFAULT_ROUTER_TIMEOUT)
self.gcmclients = {}
self.senderIDs = {}
self.gcm_endpoint = router_conf["endpoint"]
# Flatten the SenderID list from human readable and init gcmclient
if not router_conf.get("senderIDs"):
raise IOError("SenderIDs not configured.")
for sid in router_conf.get("senderIDs"):
auth = router_conf.get("senderIDs").get(sid).get("auth")
self.senderIDs[sid] = auth
self.gcmclients[sid] = gcmclient.GCM(auth, timeout=timeout,
logger=self.log)
logger=self.log,
endpoint=self.gcm_endpoint)
self._base_tags = ["platform:gcm"]
self.log.debug("Starting GCM router...")

Expand Down
14 changes: 5 additions & 9 deletions autopush/tests/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,18 @@
from twisted.internet.defer import inlineCallbacks
from twisted.trial import unittest


import autopush.utils as utils
from autopush.config import AutopushConfig
from autopush.db import (
Message,
ItemNotFound,
has_connected_this_month,
Router
)
from autopush.db import (ItemNotFound, Message, Router,
has_connected_this_month)
from autopush.exceptions import RouterException
from autopush.http import EndpointHTTPFactory
from autopush.metrics import SinkMetrics
from autopush.router import routers_from_config
from autopush.router.interface import IRouter
from autopush.tests.client import Client
from autopush.tests.test_db import make_webpush_notification
from autopush.tests.support import test_db
from autopush.tests.test_db import make_webpush_notification
from autopush.utils import (
generate_hash,
)
Expand Down Expand Up @@ -286,7 +281,8 @@ def test_post_gcm(self):
sids = {"182931248179192": {"auth": "aailsjfilajdflijdsilfjsliaj"}}
gcm = GCMRouter(
self.conf,
{"dryrun": True, "senderIDs": sids},
{"dryrun": True, "senderIDs": sids,
"endpoint": "gcm-http.googleapis.com/gcm/send"},
SinkMetrics()
)
self.routers["gcm"] = gcm
Expand Down
1 change: 1 addition & 0 deletions autopush/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,7 @@ def _add_router(self):
"dryrun": True,
"max_data": 4096,
"collapsekey": "test",
"endpoint": "gcm-http.googleapis.com/gcm/send",
"senderIDs": {self.senderID:
{"auth": "AIzaSyCx9PRtH8ByaJR3Cf"
"Jamz0D2N0uaCgRGiI"}}
Expand Down
44 changes: 19 additions & 25 deletions autopush/tests/test_router.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,37 @@
# -*- coding: utf-8 -*-
from unittest import TestCase
import uuid
import time
import json
import decimal
import json
import socket
import ssl
import time
import uuid
from unittest import TestCase

import hyper.tls
import pyfcm
import pytest
import treq
from botocore.exceptions import ClientError
from hyper.http20.exceptions import HTTP20Error
from mock import Mock, PropertyMock, patch
from oauth2client.service_account import ServiceAccountCredentials
from twisted.trial import unittest
from twisted.internet.error import (
ConnectionRefusedError,
ConnectError,
TimeoutError,
)
from twisted.internet.defer import inlineCallbacks, Deferred
from twisted.internet.defer import Deferred, inlineCallbacks
from twisted.internet.error import (ConnectError, ConnectionRefusedError,
TimeoutError)
from twisted.python.failure import Failure
from twisted.trial import unittest
from twisted.web.client import Agent
from twisted.web.http_headers import Headers

import hyper.tls
import pyfcm
from hyper.http20.exceptions import HTTP20Error

from autopush.config import AutopushConfig
from autopush.db import (
Message
)
from autopush.exceptions import ItemNotFound, RouterException
from autopush.metrics import SinkMetrics
from autopush.router import (
APNSRouter,
GCMRouter,
WebPushRouter,
FCMRouter,
gcmclient,
FCMv1Router, fcmv1client)
from autopush.router.interface import RouterResponse, IRouter
from autopush.router import (APNSRouter, FCMRouter, FCMv1Router, GCMRouter,
WebPushRouter, fcmv1client, gcmclient)
from autopush.router.interface import IRouter, RouterResponse
from autopush.tests import MockAssist
from autopush.tests.support import test_db
from autopush.utils import WebPushNotification
Expand Down Expand Up @@ -363,7 +354,8 @@ def setUp(self):
self.gcm_config = {'max_data': 32,
'ttl': 60,
'senderIDs': {'test123':
{"auth": "12345678abcdefg"}}}
{"auth": "12345678abcdefg"}},
'endpoint': 'gcm-http.googleapis.com/gcm/send'}
self._m_request = Deferred()
self.response = Mock(spec=treq.response._Response)
self.response.code = 200
Expand Down Expand Up @@ -426,7 +418,9 @@ def test_init(self):
statsd_host=None,
)
with pytest.raises(IOError):
GCMRouter(conf, {"senderIDs": {}}, SinkMetrics())
GCMRouter(conf, {"senderIDs": {},
"endpoint": "gcm-http.googleapis.com/gcm/send"},
SinkMetrics())

def test_register(self):
router_data = {"token": "test123"}
Expand Down
3 changes: 3 additions & 0 deletions autopush/tests/test_z_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ class TestArg(AutopushConfig):
apns_creds = json.dumps({"firefox": {"cert": "cert.file",
"key": "key.file"}})
gcm_enabled = True
gcm_endpoint = "gcm-http.googleapis.com/gcm/send"
# less important stuff
gcm_ttl = 999
gcm_dryrun = False
Expand Down Expand Up @@ -353,6 +354,7 @@ def test_ssl(self):
def test_bad_senderidlist(self):
returncode = endpoint_main([
"--gcm_enabled",
"--gcm_endpoint='gcm-http.googleapis.com/gcm/send'"
"--senderid_list='[Invalid'"
], False)
assert returncode not in (None, 0)
Expand Down Expand Up @@ -456,6 +458,7 @@ def test_bad_fcm_senders(self):
def test_gcm_start(self):
endpoint_main([
"--gcm_enabled",
"--gcm_endpoint='gcm-http.googleapis.com/gcm/send'",
"""--senderid_list={"123":{"auth":"abcd"}}""",
], False, resource=autopush.tests.boto_resource)

Expand Down

0 comments on commit 5fd37e2

Please sign in to comment.