Coverage for hookee/plugins/blueprint_default.py: 100.00%

1 from flask import Blueprint, request

2

3 from hookee.pluginmanager import BLUEPRINT_PLUGIN, PluginManager

4 from hookee.util import PrintUtil

5

6 __author__ = "Alex Laird"

7 __copyright__ = "Copyright 2023, Alex Laird"

8 __version__ = "2.0.7"

9

10 blueprint = Blueprint("default", __name__)

11 plugin_type = BLUEPRINT_PLUGIN

12 description = "Mount required management endpoints along with the default `/webhook` endpoint that processes incoming " \

13 "requests with enabled plugins."

14

15 plugin_manager = None # type: PluginManager

16 print_util = None # type: PrintUtil

17

18

19 def setup(hookee_manager):

20 global plugin_manager, print_util

21

22 plugin_manager = hookee_manager.plugin_manager

23 print_util = hookee_manager.print_util

24

25

26@blueprint.route("/webhook",

27 methods=["GET", "HEAD", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "TRACE", "CONNECT"])

28 def webhook():

29 print_util.print_close_header(delimiter="=", color=print_util.request_color)

30

31 print_util.print_open_header("Request", delimiter="-", color=print_util.request_color)

32

33 plugin_manager.run_request_plugins(request)

34

35 print_util.print_open_header("Response", color=print_util.request_color)

36

37 response = plugin_manager.run_response_plugins(request)

38

39 print_util.print_close_header("=", color=print_util.request_color)

40 print_util.print_basic()

41

42 return response

43

44

45@blueprint.route("/status")

46 def status():

47 return "", 200

48

49

50@blueprint.route("/shutdown", methods=["POST"])

51 def shutdown():

52 request.environ.get("werkzeug.server.shutdown")()

53

54 return "", 204