Commit 1e15d9ca authored by Hinrikus Wolf's avatar Hinrikus Wolf
Browse files

Initial Commit

parents
config.toml
# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# 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
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
pytestdebug.log
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
doc/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# End of https://www.toptal.com/developers/gitignore/api/python
[upstream]
url = "https://pad.example.com"
api_key = "foobar"
[[api_keys]]
orga = "FSMPI"
api_key = "123456789"
[[api_keys]]
orga = "AStA"
api_key = "987654321"
\ No newline at end of file
#!/usr/bin/env python3
import toml
import etherpad_lite
from flask import Flask, request, jsonify
with open("config.toml", 'r') as fd:
config = toml.load(fd)
app = Flask(__name__)
ep = etherpad_lite.EtherpadLiteClient(base_params={"apikey": config["upstream"]["api_key"]}, base_url=config["upstream"]["url"] + "/api", api_version="1.2.14")
apikeys = {}
for apikey in config["api_keys"]:
apikeys[apikey["api_key"]] = apikey["orga"]
@app.route('/api/<version>/createPad', methods=["GET", "POST"])
def createPad(version):
if version != "1.2.14":
return jsonify({"code": 1, "message": "Wrong Etherpad Version"}), 200
apikey = request.form.get("apikey") or request.args.get("apikey")
padID = request.form.get("padID") or request.args.get("padID")
text = request.form.get("text") or request.args.get("text")
if apikey in apikeys:
try:
ep.createPad(padID=padID, text=text)
print(f"{apikeys[apikey]} created pad {padID}.")
return jsonify({"code": 0, "message": "ok"})
except etherpad_lite.EtherpadException as e:
print(f"{apikeys[apikey]} failed to create pad {padID}, because {e}.")
return jsonify({"code": 1, "message": str(e)}), 200
return jsonify({"code": 1, "message": "Unauthorized"}), 200
@app.route('/api/<version>/setText', methods=["GET", "POST"])
def setText(version):
if version != "1.2.14":
return jsonify({"code": 1, "message": "Wrong Etherpad Version"}), 200
apikey = request.form.get("apikey") or request.args.get("apikey")
padID = request.form.get("padID") or request.args.get("padID")
text = request.form.get("text") or request.args.get("text")
if apikey in apikeys:
try:
ep.setText(padID=padID, text=text)
print(f"{apikeys[apikey]} set text in pad {padID}.")
return jsonify({"code": 0, "message": "ok"})
except etherpad_lite.EtherpadException as e:
print(f"{apikeys[apikey]} failed to set text in pad {padID}, because {e}.")
return jsonify({"code": 1, "message": str(e)}), 200
return jsonify({"code": 1, "message": "Unauthorized"}), 200
@app.route('/api/<version>/getText', methods=["GET", "POST"])
def getText(version):
if version != "1.2.14":
return jsonify({"code": 1, "message": "Wrong Etherpad Version"}), 200
apikey = request.form.get("apikey") or request.args.get("apikey")
padID = request.form.get("padID") or request.args.get("padID")
if apikey in apikeys:
try:
res = ep.getText(padID=padID)
print(f"{apikeys[apikey]} read pad {padID}.")
return jsonify({"code": 0, "message": "ok", "data": str(res)})
except etherpad_lite.EtherpadException as e:
print(f"{apikeys[apikey]} failed to read pad {padID}, because {e}.")
return jsonify({"code": 1, "message": str(e)}), 200
return jsonify({"code": 1, "message": "Unauthorized"}), 200
\ No newline at end of file
# Etherpad Api Proxy
A Proxy for Ethepad-lite's API for multi tenant purpose.
The following api requests are supported:
* `createPad`
* `getText`
* `setText`
Supports Markdown
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