Skip to content

Commit d1aebc0

Browse files
author
Bryan Sieber
committed
Adding 'powered by jbi' endpoint
1 parent 6912fe7 commit d1aebc0

File tree

7 files changed

+153
-9
lines changed

7 files changed

+153
-9
lines changed

poetry.lock

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ python = ">=3.8, <3.11"
1010
fastapi = "^0.73.0"
1111
pydantic = "^1.9.0"
1212
uvicorn = {extras = ["standard"], version = "^0.17.4"}
13+
gunicorn = "^20.1.0"
1314

1415
[tool.poetry.dev-dependencies]
1516
pre-commit = "^2.17.0"

src/app/monitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from src.app import environment
77
from src.jbi.services import jbi_service_health_map
88

9-
api_router = APIRouter(tags=["Platform", "dockerflow"])
9+
api_router = APIRouter(tags=["Monitor"])
1010

1111

1212
def heartbeat(request: Request, settings: environment.Settings):

src/core/actions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from inspect import getmembers, isfunction, ismodule
22
from typing import Dict
33

4-
from src.jbi.configuration import jbi_action_map
5-
64
module_dict: Dict = {}
7-
module_dict.update(jbi_action_map())
5+
# update this dict with additional action contexts
86

97

108
def get_action_context_by_key(key):

src/jbi/configuration.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from src.app import environment
2-
from src.core import configurator
2+
from src.core import actions, configurator
33
from src.jbi import whiteboard_actions
44

55
settings = environment.get_settings()
@@ -29,3 +29,6 @@ def jbi_config_map():
2929

3030
def jbi_action_map():
3131
return {settings.jbi_action_key: whiteboard_actions}
32+
33+
34+
actions.module_dict.update(jbi_action_map())

src/jbi/router.py

Lines changed: 127 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,142 @@
11
from fastapi import APIRouter, Depends, Request
2+
from fastapi.responses import HTMLResponse, JSONResponse
23

34
from src.app import environment
5+
from src.jbi import configuration
46

5-
api_router = APIRouter(tags=["jbi"])
7+
api_router = APIRouter(tags=["JBI"])
68

79

810
def execute_request(request, settings):
911
pass
1012

1113

12-
@api_router.get("/bugzilla_webhook")
14+
@api_router.post("/bugzilla_webhook")
1315
def bugzilla_webhook(
1416
request: Request,
1517
settings: environment.Settings = Depends(environment.get_settings),
1618
):
1719
return execute_request(request, settings)
20+
21+
22+
@api_router.get("/whiteboard_tags")
23+
def get_whiteboard_tags():
24+
data = configuration.jbi_config_map()
25+
status_code = 200
26+
return JSONResponse(content=data, status_code=status_code)
27+
28+
29+
@api_router.get("/whiteboard_tags/{whiteboard_tag}")
30+
def get_whiteboard_tag_or_blank(
31+
whiteboard_tag: str,
32+
):
33+
data = {}
34+
wb_val = configuration.jbi_config_map().get(whiteboard_tag)
35+
status_code = 200
36+
if wb_val:
37+
data = wb_val
38+
return JSONResponse(content=data, status_code=status_code)
39+
40+
41+
@api_router.get("/powered_by_jbi", response_class=HTMLResponse)
42+
def powered_by_jbi():
43+
data = configuration.jbi_config_map()
44+
num_configs = len(data)
45+
html = f"""
46+
<html>
47+
<head>
48+
<title>Powered by JBI</title>
49+
<style>{get_css_style()}
50+
</style>
51+
</head>
52+
<body>
53+
<h1>Powered by JBI</h1>
54+
<p>{num_configs} collections.</p>
55+
<div id="collections"> {create_inner_html_table(data)} </div>
56+
</body>
57+
</html>
58+
"""
59+
return html
60+
61+
62+
def get_css_style():
63+
return """body {
64+
font-family: sans-serif;
65+
}
66+
67+
table {
68+
border-collapse: collapse;
69+
margin: 25px 0;
70+
font-size: 0.9em;
71+
min-width: 400px;
72+
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
73+
}
74+
75+
thead tr {
76+
background-color: #009879;
77+
color: #ffffff;
78+
text-align: left;
79+
}
80+
81+
th, td {
82+
padding: 12px 15px;
83+
}
84+
85+
tbody tr {
86+
border-bottom: 1px solid #dddddd;
87+
}
88+
89+
tbody tr:nth-of-type(even) {
90+
background-color: #f3f3f3;
91+
}
92+
93+
tbody tr:last-of-type {
94+
border-bottom: 2px solid #009879;
95+
}
96+
97+
.sort:after {
98+
content: "▼▲";
99+
padding-left: 10px;
100+
opacity: 0.5;
101+
}
102+
.sort.desc:after {
103+
content: "▲";
104+
opacity: 1;
105+
}
106+
.sort.asc:after {
107+
content: "▼";
108+
opacity: 1;
109+
}
110+
"""
111+
112+
113+
def create_inner_html_table(data):
114+
agg_table = ""
115+
header = """
116+
<tr>
117+
<th>Collection</th>
118+
<th>Action</th>
119+
<th>Enabled</th>
120+
<th>Whiteboard Tag</th>
121+
<th>Jira Project Key</th>
122+
</tr>
123+
"""
124+
for key, value in data.items():
125+
collection = key
126+
per_row = f"""
127+
<tr>
128+
<td class="collection">{collection}</td>
129+
<td class="action">{value.get("action")}</td>
130+
<td class="enabled">{value.get("enabled")}</td>
131+
<td class="whiteboard_tag">{value.get("whiteboard_tag")}</td>
132+
<td class="jira_project_key">{value.get("jira_project_key")}</td>
133+
</tr>"""
134+
agg_table += per_row
135+
136+
html = f"""
137+
<table>
138+
<thead>{header}</thead>
139+
<tbody class="list">{agg_table}</tbody>
140+
</table>
141+
"""
142+
return html
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .default import *
22
from .example import *
33

4-
# Add new action modules here!
4+
# Add new JBI action modules here!

0 commit comments

Comments
 (0)