|
| 1 | +"""Example 001: Validate webhook message using HMAC. """ |
| 2 | + |
| 3 | +from docusign_monitor.client.api_exception import ApiException |
| 4 | +from flask import Blueprint, render_template, session |
| 5 | + |
| 6 | +from app.docusign import authenticate, ensure_manifest, get_example_by_number |
| 7 | +from app.error_handlers import process_error |
| 8 | +from ..examples.eg001_validate_webhook_message import Eg001ValidateWebhookMessageController |
| 9 | +from ...ds_config import DS_CONFIG |
| 10 | +from ...consts import API_TYPE |
| 11 | + |
| 12 | +example_number = 1 |
| 13 | +api = API_TYPE["CONNECT"] |
| 14 | +eg = f"cneg00{example_number}" # Reference (and URL) for this example |
| 15 | +cneg001 = Blueprint(eg, __name__) |
| 16 | + |
| 17 | +@cneg001.route(f"/{eg}", methods=["POST"]) |
| 18 | +@ensure_manifest(manifest_url=DS_CONFIG["example_manifest_url"]) |
| 19 | +def get_monitoring_data(): |
| 20 | + """ |
| 21 | + 1. Get required arguments |
| 22 | + 2. Call the worker method |
| 23 | + 3. Render the response |
| 24 | + """ |
| 25 | + example = get_example_by_number(session["manifest"], example_number, api) |
| 26 | + |
| 27 | + # 1. Get required arguments |
| 28 | + args = Eg001ValidateWebhookMessageController.get_args() |
| 29 | + try: |
| 30 | + # 2. Call the worker method to compute hash |
| 31 | + results = Eg001ValidateWebhookMessageController.worker(args) |
| 32 | + except ApiException as err: |
| 33 | + return process_error(err) |
| 34 | + |
| 35 | + return render_template( |
| 36 | + "example_done.html", |
| 37 | + title=example["ExampleName"], |
| 38 | + message=example["ResultsPageText"].format(results) |
| 39 | + ) |
| 40 | + |
| 41 | +@cneg001.route(f"/{eg}", methods=["GET"]) |
| 42 | +@ensure_manifest(manifest_url=DS_CONFIG["example_manifest_url"]) |
| 43 | +def get_view(): |
| 44 | + """ Responds with the form for the example""" |
| 45 | + example = get_example_by_number(session["manifest"], example_number, api) |
| 46 | + |
| 47 | + return render_template( |
| 48 | + "connect/eg001_validate_webhook_message.html", |
| 49 | + title=example["ExampleName"], |
| 50 | + example=example, |
| 51 | + source_file= "eg001_validate_webhook_message.py", |
| 52 | + source_url=DS_CONFIG["monitor_github_url"] + "eg001_validate_webhook_message.py", |
| 53 | + documentation=DS_CONFIG["documentation"] + eg, |
| 54 | + ) |
| 55 | + |
0 commit comments