Commit ef0dd13c authored by flynn's avatar flynn

Add base routes and docker

parent 31c2146e
FROM python:3.7-alpine
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
EXPOSE 5000
COPY . .
CMD ["flask", "run"]
import mattermost
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
import configparser
import config
from pprint import pprint
# Read in the config
config = configparser.ConfigParser()
config.read('config.ini')
# Setup Mattermost connection
mm = mattermost.MMApi(config["mattermost"]["url"])
mm.login(bearer=config["mattermost"]["token"])
user = mm.get_user()
def requires_token(token_name):
'''Decorator to require a correct Mattermost token'''
def decorator(f):
@wraps(f)
def decorated_function(*args, **kwargs):
expected_token = config.tokens[token_name]
token = request.values.get('token')
if expected_token != token:
return abort(401)
return f(*args, **kwargs)
return decorated_function
return decorator
@app.route("/troll_increase_points", methods=["POST"])
@requires_token('troll_increase_points')
def change():
# Get the channel, the user and the victim
channel = request.form['channel_id']
channel_name = request.form["channel_name"]
caller = request.form['user_id']
caller_name = request.form['user_name']
victim_name = request.form['user'].strip()
print("Received data")
pprint(request.form)
@app.route('/troll_list_points')
@requires_token('troll_list_points')
def list_points():
pass
#!/usr/bin/env python3
tokens = {
'troll_increase_points': 'abc',
'troll_list_points': 'def'
}
version: '3.8'
services:
app:
build: .
ports:
- "5000:5000"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment