Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Nelson Vides <nelson.vides@erlang-solutions.com>
  • Loading branch information
zofpolkowska and NelsonVides committed Jul 2, 2020
1 parent 337d6ab commit 92ef1bb
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
6 changes: 4 additions & 2 deletions guides/configuration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Configuration

The whole configuration is contained in the config/{prod|dev|test}.exs`file depending on which `MIX_ENV` you will be using. You should use `MIX_ENV=prod` for production installations and `MIX_ENV=dev` for your development. Let's examine `config/dev.exs`.
The whole configuration is contained in the `config/{prod|dev|test}.exs` file, depending on which `MIX_ENV` you will be using. You should use `MIX_ENV=prod` for production installations and `MIX_ENV=dev` for your development.

Let's examine `config/dev.exs`.

## RESTful API configuration

Expand All @@ -14,7 +16,7 @@ config :mongoose_push, MongoosePushWeb.Endpoint,
otp_app: :mongoose_push
]
```
This part of configuration relates only to `HTTPS` endpoints exposed by `MongoosePush`. Here you can set a bind IP address (option: `ip`), port a port and paths to your `HTTPS` `TLS` certificates. You should ignore other options unless you are sure you know what you're doing (to learn more, explore [phoenix documentation](https://hexdocs.pm/phoenix/overview.html)).
This part of the configuration relates only to the `HTTPS` endpoints exposed by `MongoosePush`. Here you can set an IP address (option: `ip`), a port, and paths to your `HTTPS` `TLS` certificates. You should ignore other options unless you are sure you know what you're doing (to learn more, explore [phoenix documentation](https://hexdocs.pm/phoenix/overview.html)).

You may entirely skip the `mongoose_push` config entry to disable the `HTTPS` API and just use this project as an `Elixir` library.

Expand Down
10 changes: 5 additions & 5 deletions guides/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Running from DockerHub

We provide prebuilt MongoosePush images. Configuration requires either an FCM token, APNS certificates or an APNS token. Depending on your usecase, you can have some or all of them in a standalone MongoosePush instance or using a docker container.
For the full configuration you need to set the following directory structure up:
For the full configuration you need to set up the following directory structure:
* priv/
* ssl/
* rest_cert.pem - The HTTP endpoint certificate
Expand All @@ -20,7 +20,7 @@ For the full configuration you need to set the following directory structure up:
If you want to use the `APNS` token authentication you need to provide the token and set both `key_id` and `team_id` environmental variables. To see how to obtain the token and `key_id` read:
https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_token_based_connection_to_apns
To see how to obtain `team_id` read: https://www.mobiloud.com/help/knowledge-base/ios-app-transfer/
`FCM` JSON file can be generated by the Firebase console (https://console.firebase.google.com). Go to your project -> `Project Settings` -> `Service accounts` -> `Generate new private key`
The `FCM` JSON file can be generated by the Firebase console (https://console.firebase.google.com). Go to your project -> `Project Settings` -> `Service accounts` -> `Generate new private key`.
Assuming that you have the `priv` directory with all certificates and the fcm token in the current directory, you may start MongoosePush with the following command:

```bash
Expand All @@ -33,13 +33,13 @@ docker run -v `pwd`/priv:/opt/app/priv \

## Building

Building docker is really easy, just type:
Building a docker image is really easy, just type:

```bash
docker build . -t mpush:latest
```

As a result of this command you get access to `mpush:latest` docker image. You may run it by typing:
As a result of this command you get access to the `mpush:latest` docker image. You may run it by typing:

```bash
docker run -it --rm mpush:latest foreground
Expand All @@ -49,4 +49,4 @@ The docker image that you have just built, exposes the port `8443` for the HTTP

## Configuration (basic)

The docker image of MongoosePush contains common, basic configuration that is generated from `config/prod.exs`. All useful options may be overridden via system environmental variables. Below there's a full list of the variables you may set while running docker (via `docker -e` switch), but if there's something you feel, you need to change other then that, then you need to prepare your own `config/prod.exs` before image build.
The docker image of MongoosePush contains common, basic configuration that is generated from `config/prod.exs`. All useful options may be overridden via environment variables. Below there's a full list of the variables you may set while running docker (via `docker -e`), but if there's something you feel you need to change other then that, then you need to prepare your own `config/prod.exs` before image build.
22 changes: 11 additions & 11 deletions guides/http_api.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# HTTP API

If for some reason you need `Swagger` spec for this `RESTful` service, there is a swagger endpoint available via an `HTTP` path `/swagger.json`
If for some reason you need `Swagger` specs for this `RESTful` service, there is a swagger endpoint available via an `HTTP` path `/swagger.json`

## Request

There is only one endpoint at this moment:
There is only one endpoint at the moment:
* `POST /{version}/notification/{device_id}`

As you can imagine, `{device_id}` should be replaced with a device ID/Token generated by your push notification provider (`FCM` or `APNS`). The notification should be sent as a `JSON` payload of this request. Minimal `JSON` request could be like this:
As you can imagine, `{device_id}` should be replaced with a device ID/Token generated by your push notification provider (`FCM` or `APNS`). The notification should be sent as a `JSON` payload of this request. A minimal `JSON` request could be like this:

```json
{
Expand All @@ -25,17 +25,17 @@ The full list of options contains the following:
* **mode** (*optional*, `prod` (default) or `dev`) - allows for selecting named pool configured in `MongoosePush`
* **priority** (*optional*) - Either `normal` or `high`. Those values are used without changes for FCM. For APNS however, `normal` maps to priority `5`, while `high` maps to priority `10`. Please refer to FCM / APNS documentation for more details on those values. By default `priority` is not set at all, therefore the push notification service decides which value is used by default.
* **time_to_live** (*optional*) - Maximum lifespan of an FCM notification. For more details, please, refer to [the official FCM documentation](https://firebase.google.com/docs/cloud-messaging/concept-options#ttl).
* **mutable_content** (*optional*, `true` / `false` (default)) - Only applicable to APNS. Sets "mutable-content=1" in APNS payload.
* **topic** (*optional*, `APNS` specific) - if APNS certificate configured in `MongoosePush` allows for multiple applications, this field selects the application. Please refer to `APNS` documentation for more details
* **mutable_content** (*optional*, `true` / `false` (default)) - Only applicable to APNS. Sets "mutable-content=1" in the APNS payload.
* **topic** (*optional*, `APNS` specific) - if the APNS certificate configured in `MongoosePush` allows for multiple applications, this field selects the application. Please refer to the `APNS` documentation for more details.
* **tags** (*optional*) - a list of tags used to choose a pool with matching tags. To see how tags work read: https://github.com/esl/sparrow#tags
* **data** (*optional*) - custom JSON structure sent to the target device. For `APNS`, all keys form this structure are merged into highest level APS message (the one that holds 'aps' key), while for `FCM` the whole `data` json structure is sent as FCM's `data payload` along with `notification`.
* **alert** (*optional*) - JSON structure that if provided will send non-silent notification with the following fields:
* **body** (*required*) - text body of notification
* **title** (*required*) - short title of notification
* **click_action** (*optional*) - for `FCM` its `activity` to run when notification is clicked. For `APNS` its `category` to invoke. Please refer to Android/iOS documentation for more details about this action
* **data** (*optional*) - custom JSON structure sent to the target device. For `APNS`, all keys from this structure are merged into the highest level APS message (the one that holds the 'aps' key), while for `FCM` the whole `data` json structure is sent as FCM's `data payload` along with `notification`.
* **alert** (*optional*) - JSON structure that if provided will send a non-silent notification with the following fields:
* **body** (*required*) - text body of the notification
* **title** (*required*) - short title of the notification
* **click_action** (*optional*) - for `FCM` its `activity` to run when notification is clicked. For `APNS` its `category` to invoke. Please refer to the Android/iOS documentation for more details about this action
* **tag** (*optional*, `FCM` specific) - notifications aggregation key
* **badge** (*optional*, `APNS` specific) - unread notifications count
* **sound** (*optional*) - sound that should be play when notification arrives. Please refer to FCM / APNS documentation for more details.
* **sound** (*optional*) - sound that should be play when the notification arrives. Please refer to the FCM / APNS documentation for more details.

Please note that either **alert** and **data** has to be provided (also can be both).
If you only specify **alert**, the request will result in a classic, simple notification.
Expand Down
4 changes: 2 additions & 2 deletions guides/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/esl/MongoosePush.svg?branch=master)](https://travis-ci.org/esl/MongoosePush) [![Coverage Status](https://coveralls.io/repos/github/esl/MongoosePush/badge.svg?branch=master)](https://coveralls.io/github/esl/MongoosePush?branch=master) [![Ebert](https://ebertapp.io/github/esl/MongoosePush.svg)](https://ebertapp.io/github/esl/MongoosePush)

**MongoosePush** is a simple, **RESTful** service written in **Elixir**, providing ability to **send push
**MongoosePush** is a simple, **RESTful** service written in **Elixir**, providing the ability to **send push
notifications** to `FCM` (Firebase Cloud Messaging) and/or
`APNS` (Apple Push Notification Service) via their `HTTP/2` API.

Expand Down Expand Up @@ -45,4 +45,4 @@ docker run -v `pwd`/priv:/opt/app/priv \
> NOTE: Some Erlang/OTP 20.x releases / builds contain TLS bug that prevents connecting to APNS servers.
> When building with this Erlang version, please make sure that MongoosePushRuntimeTest test suite passes.
> It is however highly recommended to build MongoosePush with Erlang/OTP 21.x.
* Rebar3 (just enter ```mix local.rebar```)
* Rebar3 (just enter ```mix local.rebar```)
12 changes: 6 additions & 6 deletions guides/local_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

* Elixir 1.5+ (http://elixir-lang.org/install.html)
* Erlang/OTP 19.3+
> NOTE: Some Erlang/OTP 20.x releases / builds contain TLS bug that prevents connecting to APNS servers.
> When building with this Erlang version, please make sure that MongoosePushRuntimeTest test suite passes.
> NOTE: Some Erlang/OTP 20.x releases / builds contain a TLS bug that prevents connecting to APNS servers.
> When building with this Erlang version, please make sure that the MongoosePushRuntimeTest test suite passes.
> It is however highly recommended to build MongoosePush with Erlang/OTP 21.x.
* Rebar3 (just enter ```mix local.rebar```)



## Production release

The build step is really easy. Just type in root of the repository:
The build step is really easy. Just type in the root of the repository:
```bash
MIX_ENV=prod mix do deps.get, compile, certs.dev, distillery.release
```
Expand All @@ -27,13 +27,13 @@ Yeah, I know... It crashed. Running this service is fast and simple but unfortun

## Development release

The build step is really easy. Just type in root of the repository:
Again, an easy step:
```bash
MIX_ENV=dev mix do deps.get, compile, certs.dev, distillery.release
```

The development release is by default configured to connect to a local APNS / FCM mock. This configuration may be changed as needed
in `config/dev.exs` file.
The development release is by default configured to connect to a local APNS / FCM mock.
This configuration may be changed as needed in the `config/dev.exs` file.
For now, let's just start those mocks so that we can use the default dev configuration:
```bash
docker-compose -f test/docker/docker-compose.mocks.yml up -d
Expand Down
14 changes: 6 additions & 8 deletions guides/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ One thing that you need to do *once* before running any tests is generating fake
mix certs.dev
```

Also, you'll need to have `docker-compose` installed and present in path to run any tests.
Also, you'll need to have `docker-compose` installed and present in your path to run any tests.

## TL;DR

Expand All @@ -29,7 +29,7 @@ mix test.env.up
# Now we can just run tests
mix test

# Optionally we can shut the mocks down. If you want to rerun the tests, you may skip this step do that
# Optionally we can shut the mocks down. If you want to rerun the tests, you may skip this step so that
# you don't need to re-invoke `mix test.env.up`. Mocks are being reset by each test separately,
# so you don't need to worry about their state.
mix test.env.down
Expand All @@ -38,14 +38,14 @@ mix test.env.down
## Integration tests (using production-grade release)

Integration tests can be run in exactly the same way as described above for "basic" tests, with one exception:
All Mix commands need to be invoked in `MIX_ENV=integration` environment:
All Mix commands need to be invoked in the `MIX_ENV=integration` environment:

```bash
# We start the mocks AND MongoosePush docker container.
# This may take a few minutes on the first run, as the MongoosePush docker image needs
# to build from scratch. Subsequent runs should be much faster.
# You need to call each time you make changes in the app code, as MongoosePush
# needs to be rebuilt and redeployed!
# You need to rerun this command each time you make changes in the app code,
# as MongoosePush needs to be rebuilt and redeployed!
MIX_ENV=integration mix test.env.up

# Now we can just run tests
Expand All @@ -57,13 +57,11 @@ MIX_ENV=integration mix test
MIX_ENV=integration mix test.env.down
```

**NOTE**:
You need to call `MIX_ENV=integration mix test.env.up` each time you make changes in the app code, as MongoosePush needs to be built and redeployed before running integrations tests!

## Test environment setup

* `mix test.env.up` - runs `docker-compose up -d --build` with the following compose files:
* for `MIX_ENV=test` and `MIX_ENV=dev`: *test/docker/docker-compose.mocks.yml*
* for `MIX_ENV=integration`: *test/docker/docker-compose.mocks.yml* and *test/docker/docker-compose.mpush.yml*
* `mix test.env.down` - runs `docker-compose down` on the same compose files as `mix test.env.up`
* `mix test.env.wait X` - waits up to X milliseconds for the services from `mix test.env.up` to become available. Prints error if they don't.
* `mix test.env.wait X` - waits up to X milliseconds for the services from `mix test.env.up` to become available. Prints an error if they don't.
4 changes: 2 additions & 2 deletions lib/mongoose_push_web/plugs/cast_and_validate/stub_adapter.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule MongoosePushWeb.Plug.CastAndValidate.StubAdapter do
@moduledoc """
Module which is an almost empty Plug.Conn.Adapter behavior implementation.
It is used by MongoosePushWeb.Plug.CastAndValidate plug
as the part of the workaround this module introduces.
It is used by the MongoosePushWeb.Plug.CastAndValidate plug
as part of the workaround this module introduces.
"""
@behaviour Plug.Conn.Adapter

Expand Down

0 comments on commit 92ef1bb

Please sign in to comment.