Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Oct 27, 2019
0 parents commit 4a8921a
Show file tree
Hide file tree
Showing 64 changed files with 27,784 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: caronc
custom: ['https://www.paypal.me/lead2gold', 'https://beerpay.io/caronc/apprise']
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/1_bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: 🐛 Bug Report
about: Report any errors and problems
title: ''
labels: 'bug'
assignees: ''

---

:beetle: **Describe the bug**
<!-- A clear and concise description of the problem. -->

:bulb: **Screenshots and Logs**
<!-- If applicable, add screenshots or share logs help explain your problem. -->
<!-- be careful not to reveal anything personal in the logs such as a password or api key. -->

:computer: **Your System Details:**
- OS: [e.g. RedHat v8.0]
- Python Version: [e.g. Python v2.7]

:crystal_ball: **Additional context**
<!-- Is the issue easy to reproduce? if so how? -->
15 changes: 15 additions & 0 deletions .github/ISSUE_TEMPLATE/2_enhancement_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: 💡 Enhancement Request
about: Got a great idea? Let us know!
title: ''
labels: 'enhancement'
assignees: ''

---

:bulb: **The Idea**
<!-- Share your thoughts; try to be detailed if you can -->

:hammer: **Breaking Feature**
<!-- Would your idea disrupt or drastically change the flow
of Apprise or how it currently works? If so explain it here. -->
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/3_question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: ❓ Support Question
about: Ask a question about Apprise
title: ''
labels: 'question'
assignees: ''

---

:question: **Question**
<!-- Go ahead and ask your question here :) -->
9 changes: 9 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Description:
**Related issue (if applicable):** fixes #<!--apprise issue number goes here-->

## Checklist
<!-- The following must be completed or your PR can't be merged -->
* [ ] The code change is tested and works locally.
* [ ] There is no commented out code in this PR.
* [ ] No lint errors (use `flake8`)
* [ ] tests added
70 changes: 70 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# vi swap files
.*.sw?

# Distribution / packaging / virtualenv
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib64/
lib/
include/
bin/
parts/
sdist/
pyvenv.cfg
*.egg-info/
.installed.cfg
*.egg
pip-selfcheck.json

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Allow RPM SPEC files despite pyInstaller ignore
!packaging/redhat/*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo

# Django stuff:
*.log

# PyBuilder
target/

#Ipython Notebook
.ipynb_checkpoints

#PyCharm
.idea

# Apprise Gateway Variable/Test Configuration
apprise_gw/var/*
22 changes: 22 additions & 0 deletions Dockerfile-gunicorn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# pull official base image
FROM python:3.8.0-alpine

# set work directory
WORKDIR /opt/apprise

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV APPRISE_CONFIG_DIR /var/apprise/config

# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt etc/requirements.txt
RUN pip install -r etc/requirements.txt \
gunicorn

# copy project
COPY apprise_api/ webapp

EXPOSE 8000
CMD ["gunicorn", "-c", "/opt/apprise/webapp/gunicorn.conf.py", "core.wsgi"]
9 changes: 9 additions & 0 deletions Dockerfile-nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# pull official base image
FROM nginx

# Copy our customized NginX configuration (for container usage)
COPY apprise_api/nginx.conf /etc/nginx/nginx.conf
COPY apprise_api/apprise_api.conf /etc/nginx/conf.d/default.conf

# Copy our static content in place
COPY apprise_api/static /usr/share/nginx/html/s/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Chris Caron <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
150 changes: 150 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Apprise API

Take advantage of [Apprise](https://github.com/caronc/apprise) through your network with a user-friendly API.

- Send notifications to more then 50+ services.
- An incredibly lightweight gateway to Apprise.
- A production ready micro-service at your disposal.

Apprise API was designed easily fit into existing (and new) eco-systems that are looking for a simple notification solution.

[![Paypal](https://img.shields.io/badge/paypal-donate-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MHANV39UZNQ5E)
[![Discord](https://img.shields.io/discord/558793703356104724.svg?colorB=7289DA&label=Discord&logo=Discord&logoColor=7289DA&style=flat-square)](https://discord.gg/MMPeN2D)

## API Details

| Path | Description |
|------------- | ----------- |
| `/add/{KEY}` | Saves Apprise Configuration (or set of URLs) to the persistent store.<br/>*Parameters*<br/>:small_red_triangle: **urls**: Used to define one or more Apprise URL(s). Use a comma and/or space to separate one URL from the next.<br/>:small_red_triangle: **config**: Provide the contents of either a YAML or TEXT based Apprise configuration.<br/>:small_red_triangle: **format**: This field is only required if you've specified the _config_ parameter. Used to tell the server which of the supported (Apprise) configuration types you are passing. Valid options are _text_ and _yaml_.
| `/del/{KEY}` | Removes Apprise Configuration from the persistent store.
| `/get/{KEY}` | Returns the Apprise Configuration from the persistent store. This can be directly used with the *Apprise CLI* and/or the *AppriseConfig()* object ([see here for details](https://github.com/caronc/apprise/wiki/config)).
| `/notify/{KEY}` | Sends a notification based on the Apprise Configuration associated with the specified *{KEY}*.<br/>*Parameters*<br/>:small_red_triangle: **body**: Your message body. This is the *only* required field.<br/>:small_red_triangle: **title**: Optionally define a title to go along with the *body*.<br/>:small_red_triangle: **type**: Defines the message type you want to send as. The valid options are `info`, `success`, `warning`, and `error`. If no *type* is specified then `info` is the default value used.<br/>:small_red_triangle: **tag**: Optionally notify only those tagged accordingly.

### API Notes

- `{KEY}` must be 1-64 alphanumeric characters in length. In addition to this, the underscore (`_`) and dash (`-`) are also accepted.
- You must `POST` to URLs defined above in order for them to respond.
- Specify the `Content-Type` of `application/json` to use the JSON support.
- There is no authentication required to use this API; this is by design. It's intention is to be a lightweight and fast micro-service parked behind the systems designed to handle security.
- There are no persistent store dependencies for the purpose of simplicity. Configuration is hashed and written straight to disk.

### Environment Variables

The use of environment variables allow you to provide over-rides to default settings.

| Variable | Description |
|--------------------- | ----------- |
| `APPRISE_CONFIG_DIR` | Defines the persistent store location of all configuration files saved. By default:<br/> - Content is written to the `apprise_api/var/config` directory when just using the _Django_ `manage runserver` script.
| `SECRET_KEY` | A Django variable acting as a *salt* for most things that require security. This API uses it for the hash sequences when writing the configuration files to disk.
| `ALLOWED_HOSTS` | A list of strings representing the host/domain names that this API can serve. This is a security measure to prevent HTTP Host header attacks, which are possible even under many seemingly-safe web server configurations. By default this is set to `*` allowing any host. Use space to delimit more then one host.
| `DEBUG` | This defaults to `False` however can be set to `True`if defined with a non-zero value (such as `1`).


## Container Support

A `docker-compose.yml` file is already set up to grant you an instant production ready simulated environment:

```bash
# Docker Compose
docker-compose up
```

You can now access the API at: `http://localhost:8000/` from your browser.

## Development Environment

The following should get you a working development environment to test with:

```bash
# Create a virtual environment in the same directory you
# cloned this repository to:
python -m venv .

# Activate it now:
. ./bin/activate

# install dependencies
pip install -r dev-requirements.txt -r requirements.txt

# Run a dev server (debug mode):
./manage.py runserver
```

You can now access the API at: `http://localhost:8000/` from your browser.

Some other useful development notes:

```bash
# Check for any lint errors
flake8 apprise_api

# Run unit tests
pytest apprise_api
```

## Micro-Service Integration

Perhaps you run your own service and the only goal you have is to add notification support to it. Here is an example:
```python
import requests
import os

# Get your URLs from your end users. They just need
# to be a comma/space separated list (if there is more than one).
# Perhaps they're located in an environment variable:
urls = os.environ.get('NOTIFICATION_URLS', 'windows://')
if urls:
# Think of a key that best describes your purpose and/or program.
# Alternatively; you can make the key based on the users so they
# can each store their configuration.
key = 'my-program-name'

# POST our data:
requests.post(
'http://localhost:8000/add/{}'.format(key),
data={'urls': urls},
)
```

Now when you want to trigger a notification (sent from the Apprise API server), just do the following:

```python
# The minimum notify requirements are to have just provided the 'body':
requests.post(
'http://localhost:8000/notify/{}'.format(key),
data={'body': 'test message'},
)
```

## Apprise Integration

### Apprise CLI Pull Example

A scenario where you want to poll the API for your configuration:

```bash
# A simple example of the Apprise CLI
# pulling down previously stored configuration
apprise -body="test message" --config=http://localhost:8000/get/{KEY}
```

### AppriseConfig() Pull Example

Using the Apprise Library through Python, you can easily pull your saved configuration off of the API to use for future notifications.

```python
import apprise

# Point our configuration to this API server:
config = apprise.AppriseConfig()
config.add('http://localhost:8000/get/{KEY}')

# Create our Apprise Instance
a = apprise.Apprise()

# Store our new configuration
a.add(config)

# Send a test message
a.notify('test message')
```
10 changes: 10 additions & 0 deletions apprise_api/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[run]
omit =
*apps.py,
*migrations/*,
*settings*,
*tests/*,
*urls.py,
*wsgi/*,
gunicorn.conf.py,
manage.py
Empty file added apprise_api/api/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions apprise_api/api/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 Chris Caron <[email protected]>
# All rights reserved.
#
# This code is licensed under the MIT License.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files(the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions :
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from django.apps import AppConfig


class ApiConfig(AppConfig):
name = 'api'
Loading

0 comments on commit 4a8921a

Please sign in to comment.