mirror of
https://github.com/FAUSheppy/simple-webhook-handler
synced 2025-12-09 05:28:31 +01:00
improve json handling
This commit is contained in:
@@ -4,7 +4,7 @@ import argparse
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
app = flask.Flask("webhook-listener")
|
app = flask.Flask("webhook-listener")
|
||||||
SECRET_TOKEN_HEADER = "X-Gitlab-Token"
|
TOKEN_HEADER = "X-Gitlab-Token"
|
||||||
PROJECT_IDENTIFIER = "web_url"
|
PROJECT_IDENTIFIER = "web_url"
|
||||||
config = {}
|
config = {}
|
||||||
|
|
||||||
@@ -15,16 +15,16 @@ def rootPage():
|
|||||||
return "Webhook Listener ist running"
|
return "Webhook Listener ist running"
|
||||||
else:
|
else:
|
||||||
data = flask.request.json
|
data = flask.request.json
|
||||||
|
print(json.dumps(flask.request.json, indent=4, sort_keys=True))
|
||||||
|
|
||||||
# check request against configuration #
|
# check request against configuration #
|
||||||
if data[PROJECT_IDENTIFIER] not in config:
|
if data["project"][PROJECT_IDENTIFIER] not in config:
|
||||||
return ("Rejected: project not identified in config", 400)
|
return ("Rejected: project not identified in config", 400)
|
||||||
if SECRET_TOKEN_HEADER not in flask.request.headers:
|
if TOKEN_HEADER not in flask.request.headers:
|
||||||
return ("Rejected: secret token not found in request", 403)
|
return ("Rejected: secret token not found in request", 403)
|
||||||
if config[data[PROJECT_IDENTIFIER]] != flask.request.headers[SECRET_TOKEN_HEADER]:
|
if config[data["project"][PROJECT_IDENTIFIER]] != flask.request.headers[TOKEN_HEADER]:
|
||||||
return ("Rejected: secret token found but is mismatch", 403)
|
return ("Rejected: secret token found but is mismatch", 403)
|
||||||
|
|
||||||
print(json.dumps(flask.request.json))
|
|
||||||
|
|
||||||
def readExecutionConfig():
|
def readExecutionConfig():
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user