Skip to content

Commit 742d75c

Browse files
committed
feat: improve the README
Closes #59
1 parent 3381e68 commit 742d75c

File tree

1 file changed

+136
-14
lines changed

1 file changed

+136
-14
lines changed

README.md

Lines changed: 136 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,143 @@
1-
[![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-blue.svg)](https://opensource.org/licenses/MPL-2.0) [![Test Status](https://travis-ci.org/mozilla-services/megaphone.svg?branch=master)](https://travis-ci.org/mozilla-services/megaphone) [![Build Status](https://circleci.com/gh/mozilla-services/megaphone.svg?style=shield&circle-token=074ae89011d1a7601378c41a4351e1e03f1e8177)](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]
22

33
# Megaphone
4-
**A rust based real-time update broadcast server for Firefox**
54

6-
See [API doc](https://docs.google.com/document/d/1Wxqf1a4HDkKgHDIswPmhmdvk8KPoMEh2q6SPhaz4LNE)
5+
## What is it?
76

7+
Megaphone is an internal Mozilla system providing global broadcasts for Firefox.
88

9-
***NOTE***: This will require:
9+
Traditionally Firefox has polled multiple services at different frequencies (e.g. every 24 hours) to check for updates. Megaphone serves as an alternative, delivering updates to user agents in near real time over the [WebPush WebSocket protocol].
1010

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.
1812

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+
A special version value of "____NOP____" (the string "NOP" prefixed and suffixed by four underscores) signals a "No Operation" to clients: that no action should take place, effectively overwriting and cancelling any pending version update.
85+
86+
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.
87+
88+
```javascript
89+
{
90+
"code": 200
91+
}
92+
```
93+
94+
95+
## GET /v1/broadcasts
96+
97+
Read the current broadcasts.
98+
99+
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.
100+
101+
```javascript
102+
{
103+
"code": 200,
104+
"broadcasts": {
105+
"test/broadcast1": "v3",
106+
"test/broadcast2": "v0"
107+
}
108+
}
109+
```
110+
111+
## Dockerflow Status Checks:
112+
113+
## GET /\_\_heartbeat__
114+
115+
Return the status of the server.
116+
117+
This call is only used for server status checks.
118+
119+
120+
## GET /\_\_lbheartbeat__
121+
122+
Return a light weight status check (200 OK).
123+
124+
This call is only used for the Load Balancer's check.
125+
126+
127+
## GET /\_\_version__
128+
129+
Return a JSON response of the version information of the server.
130+
131+
132+
[mpl-svg]: https://img.shields.io/badge/License-MPL%202.0-blue.svg
133+
[mpl]: https://opensource.org/licenses/MPL-2.0
134+
[travis-badge]: https://travis-ci.org/mozilla-services/megaphone.svg?branch=master
135+
[travis]: https://travis-ci.org/mozilla-services/megaphone
136+
[circleci-badge]: https://circleci.com/gh/mozilla-services/megaphone.svg?style=shield&circle-token=074ae89011d1a7601378c41a4351e1e03f1e8177
137+
[circleci]: https://circleci.com/gh/mozilla-services/megaphone
138+
139+
[WebPush WebSocket protocol]: https://mozilla-push-service.readthedocs.io/en/latest/design/#simplepush-protocol
140+
[autopush-rs service]: https://github.com/mozilla-services/autopush-rs
141+
[API doc]: https://docs.google.com/document/d/1Wxqf1a4HDkKgHDIswPmhmdvk8KPoMEh2q6SPhaz4LNE
142+
[Install Rust]: https://rustup.rs/
143+
[Install docker-compose]: https://docs.docker.com/compose/install/

0 commit comments

Comments
 (0)