forked from getsentry/integration-platform-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.py
49 lines (40 loc) · 1.76 KB
/
options.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from __future__ import annotations
from src import app
from src.api.middleware import verify_sentry_signature
from src.models import SentryInstallation, Item, User
from flask import jsonify, request, Response
# These endpoints are used to populate the options for 'Select' FormFields in Sentry.
@app.route("/api/sentry/options/items/", methods=["GET"])
@verify_sentry_signature()
def get_item_options() -> Response:
uuid = request.args.get("installationId")
sentry_installation = SentryInstallation.query.filter(
SentryInstallation.uuid == uuid
).first()
if not sentry_installation:
return Response("", 404)
# We can use the installation data to filter the items we return to Sentry.
items = Item.query.filter(
Item.organization_id == sentry_installation.organization_id
).all()
# Sentry requires the results in this exact format.
result = [{"value": item.id, "label": item.title} for item in items]
app.logger.info("Populating item options in Sentry")
return jsonify(result)
@app.route("/api/sentry/options/users/", methods=["GET"])
@verify_sentry_signature()
def get_user_options() -> Response:
uuid = request.args.get("installationId")
sentry_installation = SentryInstallation.query.filter(
SentryInstallation.uuid == uuid
).first()
if not sentry_installation:
return Response("", 404)
# We can use the installation data to filter the users we return to Sentry.
users = User.query.filter(
User.organization_id == sentry_installation.organization_id
).all()
# Sentry requires the results in this exact format.
result = [{"value": user.id, "label": user.name} for user in users]
app.logger.info("Populating user options in Sentry")
return jsonify(result)