Add Flask webhook
This commit is contained in:
parent
ed25f0ba2b
commit
8118114551
@ -2,9 +2,10 @@ FROM python:3-alpine
|
|||||||
|
|
||||||
COPY requirements.txt /code/requirements.txt
|
COPY requirements.txt /code/requirements.txt
|
||||||
RUN pip install -r /code/requirements.txt
|
RUN pip install -r /code/requirements.txt
|
||||||
RUN echo '*/5 * * * * python3 /code/main.py' | crontab -
|
RUN echo '0 1,13 * * * python3 /code/main.py' | crontab -
|
||||||
COPY . /code
|
COPY . /code
|
||||||
|
|
||||||
WORKDIR /code
|
WORKDIR /code
|
||||||
|
|
||||||
CMD ["/usr/sbin/crond", "-f", "-d", "0"]
|
EXPOSE 5000
|
||||||
|
ENTRYPOINT ["/code/entrypoint.sh"]
|
||||||
|
3
entrypoint.sh
Executable file
3
entrypoint.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
crond
|
||||||
|
flask --app main run -h 0.0.0.0
|
22
main.py
22
main.py
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from dolibarrpy import Dolibarrpy
|
from dolibarrpy import Dolibarrpy
|
||||||
|
from flask import Flask, abort, request
|
||||||
from ldap3 import ALL, Connection, ObjectDef, Reader, Server, WritableEntry, Writer
|
from ldap3 import ALL, Connection, ObjectDef, Reader, Server, WritableEntry, Writer
|
||||||
|
|
||||||
import config
|
import config
|
||||||
@ -122,5 +123,26 @@ def append_extra_fields_to_ldap_group(ldap_group: WritableEntry, dolibarr_group:
|
|||||||
setattr(ldap_group, ldap_attr, value)
|
setattr(ldap_group, ldap_attr, value)
|
||||||
|
|
||||||
|
|
||||||
|
flask_app = Flask(__name__)
|
||||||
|
|
||||||
|
@flask_app.post('/webhook')
|
||||||
|
def webhook_receiver():
|
||||||
|
data = request.json
|
||||||
|
if 'triggercode' not in data or 'object' not in data:
|
||||||
|
abort(400)
|
||||||
|
triggercode = data['triggercode']
|
||||||
|
obj = data['object']
|
||||||
|
ldap_server = Server(config.LDAP_HOST, config.LDAP_PORT, get_info=ALL)
|
||||||
|
if triggercode.startswith('USER_'):
|
||||||
|
with Connection(ldap_server, config.LDAP_BIND_USER, config.LDAP_BIND_PASSWORD) as ldap_conn:
|
||||||
|
manage_user_extra_fields(ldap_conn, obj)
|
||||||
|
elif triggercode.startswith('GROUP_'):
|
||||||
|
with Connection(ldap_server, config.LDAP_BIND_USER, config.LDAP_BIND_PASSWORD) as ldap_conn:
|
||||||
|
manage_group_extra_fields(ldap_conn, obj)
|
||||||
|
else:
|
||||||
|
abort(400)
|
||||||
|
return "", 204
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
flask
|
||||||
ldap3
|
ldap3
|
||||||
dolibarrpy
|
dolibarrpy
|
||||||
icecream
|
icecream
|
||||||
|
Loading…
x
Reference in New Issue
Block a user