autopush.router.apnsrouter

APNS Router

class autopush.router.apnsrouter.APNSRouter(conf, router_conf, metrics, load_connections=True)[source]

APNS Router Implementation

_connect(rel_channel, load_connections=True)[source]

Connect to APNS

Parameters:
  • rel_channel (str) – Release channel name (e.g. Firefox. FirefoxBeta,..)
  • load_connections (bool) – (used for testing)
Returns:

APNs to be stored under the proper release channel name.

Return type:

apns.APNs

__init__(conf, router_conf, metrics, load_connections=True)[source]

Create a new APNS router and connect to APNS

Parameters:
register(uaid, router_data, app_id, *args, **kwargs)[source]

Register an endpoint for APNS, on the app_id release channel.

This will validate that an APNs instance token is in the router_data,

Parameters:
  • uaid – User Agent Identifier
  • router_data – Dict containing router specific configuration info
  • app_id – The release channel identifier for cert info lookup
amend_endpoint_response(response, router_data)[source]

Stubbed out for this router

route_notification(notification, uaid_data)[source]

Start the APNS notification routing, returns a deferred

Parameters:
  • notification (autopush.endpoint.Notification) – Notification data to send
  • uaid_data (dict) – User Agent specific data
_route(notification, router_data)[source]

Blocking APNS call to route the notification

Parameters:
  • notification (dict) – Notification data to send
  • router_data (dict) – Pre-initialized data for this connection
class autopush.router.apns2.APNSClient(cert_file, key_file, topic, alt=False, use_sandbox=False, max_connections=20, logger=None, metrics=None, load_connections=True, max_retry=2)[source]
__init__(cert_file, key_file, topic, alt=False, use_sandbox=False, max_connections=20, logger=None, metrics=None, load_connections=True, max_retry=2)[source]

Create the APNS client connector.

The cert_file and key_file can be derived from the exported .p12 Apple Push Services: *bundleID* ** key contained in the **Keychain Access application. To extract the proper PEM formatted data, you can use the following commands:

` openssl pkcs12 -in file.p12 -out apns_cert.pem -clcerts -nokeys openssl pkcs12 -in file.p12 -out apns_key.pem -nocerts -nodes `

The topic is the Bundle ID of the bridge recipient iOS application. Since the cert needs to be tied directly to an application, the topic is usually similar to “com.example.MyApplication”.

Parameters:
  • cert_file (str) – Path to the PEM formatted APNs certification file.
  • key_file (str) – Path to the PEM formatted APNs key file.
  • topic (str) – The Bundle ID that identifies the assoc. iOS app.
  • alt (bool) – Use the alternate APNs publication port (if 443 is blocked)
  • use_sandbox (bool) – Use the development sandbox
  • max_connections (int) – Max number of pooled connections to use
  • logger (logger) – Status logger
  • metrics (autopush.metrics.IMetric) – Metric recorder
  • load_connections (bool) – used for testing
  • max_retry (int) – Number of HTTP2 transmit attempts
send(router_token, payload, apns_id, priority=True, topic=None, exp=None)[source]

Send the dict of values to the remote bridge

This sends the raw data to the remote bridge application using the APNS2 HTTP2 API.

Parameters:
  • router_token (str) – APNs provided hex token identifying recipient
  • payload (dict) – Data to send to recipient
  • priority (bool) – True is high priority, false is low priority
  • topic (str) – BundleID for the recipient application (overides default)
  • exp (timestamp) – Message expiration timestamp