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

Commit

Permalink
refactor: AutopushSettings -> AutopushConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
pjenvey committed Jul 31, 2017
1 parent ce11f84 commit 7ef7d73
Show file tree
Hide file tree
Showing 24 changed files with 77 additions and 77 deletions.
4 changes: 2 additions & 2 deletions autopush/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
if TYPE_CHECKING: # pragma: nocover
from autopush.db import DatabaseManager # noqa
from autopush.metrics import IMetrics # noqa
from autopush.settings import AutopushSettings # noqa
from autopush.settings import AutopushConfig # noqa


class BaseHandler(cyclone.web.RequestHandler):
Expand All @@ -23,7 +23,7 @@ def initialize(self):

@property
def ap_settings(self):
# type: () -> AutopushSettings
# type: () -> AutopushConfig
return self.application.ap_settings

@property
Expand Down
4 changes: 2 additions & 2 deletions autopush/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
)

if TYPE_CHECKING: # pragma: nocover
from autopush.settings import AutopushSettings, DDBTableConfig # noqa
from autopush.settings import AutopushConfig, DDBTableConfig # noqa


# Typing
Expand Down Expand Up @@ -886,7 +886,7 @@ def __attrs_post_init__(self):

@classmethod
def from_settings(cls, settings, **kwargs):
# type: (AutopushSettings, **Any) -> DatabaseManager
# type: (AutopushConfig, **Any) -> DatabaseManager
"""Create a DatabaseManager from the given settings"""
metrics = autopush.metrics.from_settings(settings)
return cls(
Expand Down
4 changes: 2 additions & 2 deletions autopush/diagnostic_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from autopush.db import DatabaseManager
from autopush.main import AutopushMultiService
from autopush.main_argparse import add_shared_args
from autopush.settings import AutopushSettings
from autopush.settings import AutopushConfig


PUSH_RE = re.compile(r"push/(?:(?P<api_ver>v\d+)/)?(?P<token>[^/]+)")
Expand All @@ -20,7 +20,7 @@ class EndpointDiagnosticCLI(object):

def __init__(self, sysargs, use_files=True):
ns = self._load_args(sysargs, use_files)
self._settings = settings = AutopushSettings.from_argparse(ns)
self._settings = settings = AutopushConfig.from_argparse(ns)
settings.statsd_host = None
self.db = DatabaseManager.from_settings(settings)
self.db.setup(settings.preflight_uaid)
Expand Down
2 changes: 1 addition & 1 deletion autopush/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ class LogCheckError(Exception):


class InvalidSettings(Exception):
"""Error in initialization of AutopushSettings"""
"""Error in initialization of AutopushConfig"""
14 changes: 7 additions & 7 deletions autopush/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from autopush.db import DatabaseManager
from autopush.router import routers_from_settings
from autopush.router.interface import IRouter # noqa
from autopush.settings import AutopushSettings # noqa
from autopush.settings import AutopushConfig # noqa
from autopush.ssl import AutopushSSLContextFactory # noqa
from autopush.web.health import (
HealthHandler,
Expand Down Expand Up @@ -65,7 +65,7 @@ class BaseHTTPFactory(cyclone.web.Application):
)

def __init__(self,
ap_settings, # type: AutopushSettings
ap_settings, # type: AutopushConfig
db, # type: DatabaseManager
handlers=None, # type: APHandlers
log_function=skip_request_logging, # type: CycloneLogger
Expand Down Expand Up @@ -95,7 +95,7 @@ def _hostname(self):
@classmethod
def for_handler(cls,
handler_cls, # Type[BaseHTTPFactory]
ap_settings, # type: AutopushSettings
ap_settings, # type: AutopushConfig
db=None, # type: Optional[DatabaseManager]
**kwargs):
# type: (...) -> BaseHTTPFactory
Expand Down Expand Up @@ -125,7 +125,7 @@ def for_handler(cls,

@classmethod
def _for_handler(cls, ap_settings, **kwargs):
# type: (AutopushSettings, **Any) -> BaseHTTPFactory
# type: (AutopushConfig, **Any) -> BaseHTTPFactory
"""Create an instance w/ default kwargs for for_handler"""
raise NotImplementedError # pragma: nocover

Expand Down Expand Up @@ -153,7 +153,7 @@ class EndpointHTTPFactory(BaseHTTPFactory):
protocol = LimitedHTTPConnection

def __init__(self,
ap_settings, # type: AutopushSettings
ap_settings, # type: AutopushConfig
db, # type: DatabaseManager
routers, # type: Dict[str, IRouter]
**kwargs):
Expand Down Expand Up @@ -197,7 +197,7 @@ class InternalRouterHTTPFactory(BaseHTTPFactory):
)

def __init__(self,
ap_settings, # type: AutopushSettings
ap_settings, # type: AutopushConfig
db, # type: DatabaseManager
clients, # type: Dict[str, PushServerProtocol]
**kwargs):
Expand Down Expand Up @@ -239,7 +239,7 @@ class QuietClientFactory(_HTTP11ClientFactory):


def agent_from_settings(settings):
# type: (AutopushSettings) -> Agent
# type: (AutopushConfig) -> Agent
"""Create a twisted.web.client Agent from settings"""
# Use a persistent connection pool for HTTP requests.
pool = HTTPConnectionPool(reactor)
Expand Down
10 changes: 5 additions & 5 deletions autopush/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from autopush.logging import PushLogger
from autopush.main_argparse import parse_connection, parse_endpoint
from autopush.router import routers_from_settings
from autopush.settings import AutopushSettings
from autopush.settings import AutopushConfig
from autopush.websocket import (
ConnectionWSSite,
PushServerFactory,
Expand All @@ -59,7 +59,7 @@ class AutopushMultiService(MultiService):
THREAD_POOL_SIZE = 50

def __init__(self, settings):
# type: (AutopushSettings) -> None
# type: (AutopushConfig) -> None
super(AutopushMultiService, self).__init__()
self.settings = settings
self.db = DatabaseManager.from_settings(settings)
Expand Down Expand Up @@ -112,7 +112,7 @@ def _from_argparse(cls, ns, **kwargs):
"""Create an instance from argparse/additional kwargs"""
# Add some entropy to prevent potential conflicts.
postfix = os.urandom(4).encode('hex').ljust(8, '0')
settings = AutopushSettings.from_argparse(
settings = AutopushConfig.from_argparse(
ns,
debug=ns.debug,
preflight_uaid="deadbeef000000000deadbeef" + postfix,
Expand Down Expand Up @@ -165,7 +165,7 @@ class EndpointApplication(AutopushMultiService):
endpoint_factory = EndpointHTTPFactory

def __init__(self, settings):
# type: (AutopushSettings) -> None
# type: (AutopushConfig) -> None
super(EndpointApplication, self).__init__(settings)
self.routers = routers_from_settings(settings, self.db, self.agent)

Expand Down Expand Up @@ -231,7 +231,7 @@ class ConnectionApplication(AutopushMultiService):
websocket_site_factory = ConnectionWSSite

def __init__(self, settings):
# type: (AutopushSettings) -> None
# type: (AutopushConfig) -> None
super(ConnectionApplication, self).__init__(settings)
self.clients = {} # type: Dict[str, PushServerProtocol]

Expand Down
4 changes: 2 additions & 2 deletions autopush/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from autopush.utils import get_ec2_instance_id

if TYPE_CHECKING: # pragma: nocover
from autopush.settings import AutopushSettings # noqa
from autopush.settings import AutopushConfig # noqa


class IMetrics(object):
Expand Down Expand Up @@ -115,7 +115,7 @@ def timing(self, name, duration, **kwargs):


def from_settings(settings):
# type: (AutopushSettings) -> IMetrics
# type: (AutopushConfig) -> IMetrics
"""Create an IMetrics from the given settings"""
if settings.datadog_api_key:
return DatadogMetrics(
Expand Down
4 changes: 2 additions & 2 deletions autopush/router/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
from autopush.router.simple import SimpleRouter
from autopush.router.webpush import WebPushRouter
from autopush.router.fcm import FCMRouter
from autopush.settings import AutopushSettings # noqa
from autopush.settings import AutopushConfig # noqa

__all__ = ["APNSRouter", "FCMRouter", "GCMRouter", "WebPushRouter",
"SimpleRouter"]


def routers_from_settings(settings, db, agent):
# type: (AutopushSettings, DatabaseManager, Agent) -> Dict[str, IRouter]
# type: (AutopushConfig, DatabaseManager, Agent) -> Dict[str, IRouter]
"""Create a dict of IRouters for the given settings"""
router_conf = settings.router_conf
routers = dict(
Expand Down
2 changes: 1 addition & 1 deletion autopush/router/apnsrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, ap_settings, router_conf, metrics,
"""Create a new APNS router and connect to APNS
:param ap_settings: Configuration settings
:type ap_settings: autopush.settings.AutopushSettings
:type ap_settings: autopush.settings.AutopushConfig
:param router_conf: Router specific configuration
:type router_conf: dict
:param load_connections: (used for testing)
Expand Down
4 changes: 2 additions & 2 deletions autopush/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class DDBTableConfig(object):


@attrs
class AutopushSettings(object):
class AutopushConfig(object):
"""Main Autopush Settings Object"""

debug = attrib(default=False) # type: bool
Expand Down Expand Up @@ -216,7 +216,7 @@ def enable_tls_auth(self):

@classmethod
def from_argparse(cls, ns, **kwargs):
# type: (Namespace, **Any) -> AutopushSettings
# type: (Namespace, **Any) -> AutopushConfig
"""Create an instance from argparse/additional kwargs"""
router_conf = {}
if ns.key_hash:
Expand Down
2 changes: 1 addition & 1 deletion autopush/tests/test_diagnostic_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_bad_endpoint(self):
returncode = cli.run()
ok_(returncode not in (None, 0))

@patch("autopush.diagnostic_cli.AutopushSettings")
@patch("autopush.diagnostic_cli.AutopushConfig")
@patch("autopush.diagnostic_cli.DatabaseManager.from_settings")
def test_successfull_lookup(self, mock_db_cstr, mock_settings_class):
from autopush.diagnostic_cli import run_endpoint_diagnostic_cli
Expand Down
10 changes: 5 additions & 5 deletions autopush/tests/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from autopush.metrics import SinkMetrics
from autopush.router import routers_from_settings
from autopush.router.interface import IRouter
from autopush.settings import AutopushSettings
from autopush.settings import AutopushConfig
from autopush.tests.client import Client
from autopush.tests.test_db import make_webpush_notification
from autopush.tests.support import test_db
Expand All @@ -47,7 +47,7 @@ def write(self, data):
class MessageTestCase(unittest.TestCase):
def setUp(self):
twisted.internet.base.DelayedCall.debug = True
settings = AutopushSettings(
settings = AutopushConfig(
hostname="localhost",
statsd_host=None,
crypto_key='AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=',
Expand Down Expand Up @@ -135,7 +135,7 @@ class RegistrationTestCase(unittest.TestCase):

def setUp(self):
twisted.internet.base.DelayedCall.debug = True
settings = AutopushSettings(
settings = AutopushConfig(
hostname="localhost",
statsd_host=None,
bear_hash_key='AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB=',
Expand Down Expand Up @@ -208,12 +208,12 @@ def test_init_info(self):

def test_settings_crypto_key(self):
fake = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='
settings = AutopushSettings(crypto_key=fake)
settings = AutopushConfig(crypto_key=fake)
eq_(settings.fernet._fernets[0]._encryption_key,
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')

fake2 = 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB='
settings = AutopushSettings(crypto_key=[fake, fake2])
settings = AutopushConfig(crypto_key=[fake, fake2])
eq_(settings.fernet._fernets[0]._encryption_key,
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
eq_(settings.fernet._fernets[1]._encryption_key,
Expand Down
6 changes: 3 additions & 3 deletions autopush/tests/test_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from autopush.exceptions import MissingTableException
from autopush.http import EndpointHTTPFactory
from autopush.logging import begin_or_register
from autopush.settings import AutopushSettings
from autopush.settings import AutopushConfig
from autopush.tests.client import Client
from autopush.tests.support import TestingLogObserver
from autopush.web.health import HealthHandler, StatusHandler
Expand All @@ -24,7 +24,7 @@ def setUp(self):
self.timeout = 0.5
twisted.internet.base.DelayedCall.debug = True

settings = AutopushSettings(
settings = AutopushConfig(
hostname="localhost",
statsd_host=None,
)
Expand Down Expand Up @@ -124,7 +124,7 @@ def _assert_reply(self, reply, exception=None):
class StatusTestCase(unittest.TestCase):
def setUp(self):
twisted.internet.base.DelayedCall.debug = True
settings = AutopushSettings(
settings = AutopushConfig(
hostname="localhost",
statsd_host=None,
)
Expand Down
8 changes: 4 additions & 4 deletions autopush/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
)
from autopush.logging import begin_or_register
from autopush.main import ConnectionApplication, EndpointApplication
from autopush.settings import AutopushSettings
from autopush.settings import AutopushConfig
from autopush.utils import base64url_encode
from autopush.metrics import SinkMetrics, DatadogMetrics
from autopush.tests.support import TestingLogObserver
Expand Down Expand Up @@ -295,7 +295,7 @@ def wait_for(self, func):

class IntegrationBase(unittest.TestCase):
track_objects = True
track_objects_excludes = [AutopushSettings, PushServerFactory]
track_objects_excludes = [AutopushConfig, PushServerFactory]

endpoint_port = 9020

Expand Down Expand Up @@ -332,11 +332,11 @@ def setUp(self):
self.addCleanup(globalLogPublisher.removeObserver, self.logs)

crypto_key = Fernet.generate_key()
ep_settings = AutopushSettings(
ep_settings = AutopushConfig(
crypto_key=crypto_key,
**self.endpoint_kwargs()
)
conn_settings = AutopushSettings(
conn_settings = AutopushConfig(
crypto_key=crypto_key,
**self.conn_kwargs()
)
Expand Down
4 changes: 2 additions & 2 deletions autopush/tests/test_log_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from autopush.http import EndpointHTTPFactory
from autopush.logging import begin_or_register
from autopush.settings import AutopushSettings
from autopush.settings import AutopushConfig
from autopush.tests.client import Client
from autopush.tests.support import TestingLogObserver
from autopush.web.log_check import LogCheckHandler
Expand All @@ -19,7 +19,7 @@ class LogCheckTestCase(unittest.TestCase):
def setUp(self):
twisted.internet.base.DelayedCall.debug = True

settings = AutopushSettings(
settings = AutopushConfig(
hostname="localhost",
statsd_host=None,
)
Expand Down
Loading

0 comments on commit 7ef7d73

Please sign in to comment.