|
1 |
| -[](https://opensource.org/licenses/MPL-2.0) [](https://travis-ci.org/mozilla-services/megaphone) [](https://circleci.com/gh/mozilla-services/megaphone) |
| 1 | +[![License: MPL 2.0][mpl-svg]][mpl] [![Test Status][travis-badge]][travis] [![Build Status][circleci-badge]][circleci] |
2 | 2 |
|
3 | 3 | # Megaphone
|
4 |
| -**A rust based real-time update broadcast server for Firefox** |
5 | 4 |
|
6 |
| -See [API doc](https://docs.google.com/document/d/1Wxqf1a4HDkKgHDIswPmhmdvk8KPoMEh2q6SPhaz4LNE) |
| 5 | +## What is it? |
7 | 6 |
|
| 7 | +Megaphone is an internal Mozilla system providing global broadcasts for Firefox. |
8 | 8 |
|
9 |
| -***NOTE***: This will require: |
| 9 | +Traditionally Firefox has polled (e.g. every 24 hours) various services to check for updates. Megaphone serves as an alternative, delivering updates to user agents in near real time over the [WebPush WebSocket protocol]. |
10 | 10 |
|
11 |
| - * rust nightly. See [rocket.rs Getting |
12 |
| - Started](https://rocket.rs/guide/getting-started/) for additional steps. |
13 |
| - To set nightly as the default for only megaphone, from the |
14 |
| - megaphone directory run: rustup override set nightly |
15 |
| - * mysql |
16 |
| - * libmysqlclient installed (brew install mysql on macOS, apt-get install |
17 |
| - libmysqlclient-dev on Ubuntu) |
| 11 | +This repository provides a Rust based Megaphone Endpoint (API). New Broadcasts are created via the Megaphone Endpoint. The [autopush-rs service] polls the endpoint as the source of truth for the current broadcasts, ultimately delivering them to user agents. |
18 | 12 |
|
19 |
| -Run: |
20 |
| - * export ROCKET_DATABASE_URL=mysql://scott:tiger@mydatabase/megaphone |
21 |
| - * cargo run |
| 13 | +Also see the [API doc]. |
| 14 | + |
| 15 | + |
| 16 | +## Requirements |
| 17 | + |
| 18 | + * Rust nightly as specified in the **rust-toolchain** file (recognized by cargo) in the root of the project (recognized by cargo). |
| 19 | + * MySQL 5.7 (or compatible) |
| 20 | + * libmysqlclient (brew install mysql on macOS, apt-get install libmysqlclient-dev on Ubuntu) |
| 21 | + |
| 22 | + * *For running the docker image locally: docker-compose v1.21.0 or later |
| 23 | + |
| 24 | +## Setting Up |
| 25 | + |
| 26 | +1) [Install Rust] |
| 27 | + |
| 28 | +2) Create a `megaphone` user/database |
| 29 | + |
| 30 | +3) Run: |
| 31 | + |
| 32 | + $ export ROCKET_DATABASE_URL=mysql://scott:tiger@mydatabase/megaphone |
| 33 | + $ cargo run |
| 34 | + |
| 35 | +## Running the Docker Image |
| 36 | + |
| 37 | +1) [Install docker-compose] |
| 38 | + |
| 39 | +2) From a dedicated screen (or tmux window) |
| 40 | + |
| 41 | +$ `docker-compose up` |
| 42 | + |
| 43 | +This will create two intertwined docker images: |
| 44 | + |
| 45 | +***db_1*** - the database image. This image is a local test image. The database can be accessed via `mysql -umegaphone -ptest -h localhost --port 4306 megaphone`. |
| 46 | + |
| 47 | +***app_1*** - the **megaphone** application. This is accessible via port 8000. |
| 48 | + |
| 49 | + |
| 50 | +# API |
| 51 | + |
| 52 | +Megaphone is normally called via a HTTP interface using Authorized calls. Responses are generally JSON objects with appropriate HTTP status codes to indicate success/failure. |
| 53 | + |
| 54 | +## Authorization |
| 55 | + |
| 56 | +All calls to Megaphone (minus the Dockerflow Status Checks) require authorization. Authorization is specified by the `Authorization` header via Bearer tokens specified in the application's configurtion. |
| 57 | + |
| 58 | +e.g. |
| 59 | + |
| 60 | +``` |
| 61 | +export ROCKET_BROADCASTER_AUTH={test="foobar"} |
| 62 | +export ROCKET_READER_AUTH={autopush="quux"} |
| 63 | +``` |
| 64 | + |
| 65 | +The *test* broadcaster would specify: |
| 66 | + |
| 67 | +``` |
| 68 | +Authorization: Bearer foobar |
| 69 | +``` |
| 70 | + |
| 71 | +The *autopush* reader would specify: |
| 72 | + |
| 73 | +``` |
| 74 | +Authorization: Bearer quux |
| 75 | +``` |
| 76 | + |
| 77 | + |
| 78 | +## PUT /v1/broadcasts/< broadcaster_id > /< bchannel_id > |
| 79 | + |
| 80 | +Broadcast a new version. |
| 81 | + |
| 82 | +The body of the PUT request becomes the new version value. |
| 83 | + |
| 84 | +The return value is a JSON structure including the HTTP status of the result: successful results either being a `201` code for newly created broadcasts or `200` for an update to an existing broadcast. |
| 85 | + |
| 86 | +```javascript |
| 87 | +{ |
| 88 | + "code": 200 |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | + |
| 93 | +## GET /v1/broadcasts |
| 94 | + |
| 95 | +Read the current broadcasts. |
| 96 | + |
| 97 | +The return value is a JSON structure including the HTTP status of the result and a `broadcasts` object consisting of broadcastIDs and their current versions. |
| 98 | + |
| 99 | +```javascript |
| 100 | +{ |
| 101 | + "code": 200, |
| 102 | + "broadcasts": { |
| 103 | + "test/broadcast1": "v3", |
| 104 | + "test/broadcast2": "v0" |
| 105 | + } |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +## Dockerflow Status Checks: |
| 110 | + |
| 111 | +## GET /__heartbeat__ |
| 112 | + |
| 113 | +Return the status of the server. |
| 114 | + |
| 115 | +This call is only used for server status checks. |
| 116 | + |
| 117 | + |
| 118 | +## GET /__lbheartbeat__ |
| 119 | + |
| 120 | +Return a light weight status check (200 OK). |
| 121 | + |
| 122 | +This call is only used for the Load Balancer's check. |
| 123 | + |
| 124 | + |
| 125 | +## GET /__version__ |
| 126 | + |
| 127 | +Return a JSON response of the version information of the server. |
| 128 | + |
| 129 | + |
| 130 | +[mpl-svg]: https://img.shields.io/badge/License-MPL%202.0-blue.svg |
| 131 | +[mpl]: https://opensource.org/licenses/MPL-2.0 |
| 132 | +[travis-badge]: https://travis-ci.org/mozilla-services/megaphone.svg?branch=master |
| 133 | +[travis]: https://travis-ci.org/mozilla-services/megaphone |
| 134 | +[circleci-badge]: https://circleci.com/gh/mozilla-services/megaphone.svg?style=shield&circle-token=074ae89011d1a7601378c41a4351e1e03f1e8177 |
| 135 | +[circleci]: https://circleci.com/gh/mozilla-services/megaphone |
| 136 | + |
| 137 | +[WebPush WebSocket protocol]: https://mozilla-push-service.readthedocs.io/en/latest/design/#simplepush-protocol |
| 138 | +[autopush-rs service]: https://github.com/mozilla-services/autopush-rs |
| 139 | +[API doc]: https://docs.google.com/document/d/1Wxqf1a4HDkKgHDIswPmhmdvk8KPoMEh2q6SPhaz4LNE |
| 140 | +[Install Rust]: https://rustup.rs/ |
| 141 | +[Install docker-compose]: https://docs.docker.com/compose/install/ |
0 commit comments