Skip to content

Commit 3f16639

Browse files
author
Bryan Sieber
committed
suggestions from code review; some pre-commit suggestions. Naming updates for consistency.
1 parent 34a33cc commit 3f16639

File tree

6 files changed

+86
-32
lines changed

6 files changed

+86
-32
lines changed

poetry.lock

Lines changed: 59 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ prometheus-client = "^0.13.1"
1515
python-bugzilla = "^3.2.0"
1616
atlassian-python-api = "^3.20.1"
1717
dockerflow = "2022.1.0"
18-
types-PyYAML = "^6.0.4"
1918
Jinja2 = "^3.0.3"
20-
pydantic-yaml = {extras = ["pyyaml"], version = "^0.6.1"}
19+
pydantic-yaml = {extras = ["pyyaml","ruamel"], version = "^0.6.1"}
2120

2221

2322
[tool.poetry.dev-dependencies]

src/jbi/configuration.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class ConfigError(Exception):
1818

1919

2020
@lru_cache
21-
def get_yaml_configurations(
21+
def get_actions(
2222
jbi_config_file: str = f"config/config.{settings.env}.yaml",
2323
) -> Actions:
24-
"""Convert and validate YAML configuration to python dict"""
24+
"""Convert and validate YAML configuration to Action object"""
2525

2626
with open(jbi_config_file, encoding="utf-8") as file:
2727
try:
@@ -31,3 +31,8 @@ def get_yaml_configurations(
3131
except ValidationError as exception:
3232
jbi_logger.exception(exception)
3333
raise ConfigError("Errors exist.") from exception
34+
35+
36+
def get_actions_dict():
37+
"""Returns dict of"""
38+
return get_actions().dict()["actions"]

src/jbi/model.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
from pydantic_yaml import YamlModel
1111

1212

13-
class ActionConfig(YamlModel, extra=Extra.allow):
14-
"""
15-
ActionConfig is the inner model of `actions` in yaml
13+
class Action(YamlModel, extra=Extra.allow):
1614
"""
15+
Action is the inner model for each action in the configuration file"""
1716

1817
action: str = "src.jbi.whiteboard_actions.default"
1918
enabled: bool = False
@@ -43,13 +42,13 @@ def validate_action_config(
4342

4443
class Actions(YamlModel):
4544
"""
46-
Actions is the overall model from parsing the yaml config `actions` sections
45+
Actions is the overall model for the list of `actions` in the configuration file
4746
"""
4847

49-
actions: Dict[str, ActionConfig]
48+
actions: Dict[str, Action]
5049

5150
@validator("actions")
52-
def validate_action_yaml_jbi_naming(
51+
def validate_action_matches_whiteboard(
5352
cls, actions
5453
): # pylint: disable=no-self-argument, no-self-use
5554
"""

src/jbi/router.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,37 @@ def bugzilla_webhook(
3535
def get_whiteboard_tag(
3636
whiteboard_tag: Optional[str] = None,
3737
):
38-
"""API for viewing whiteboard_tags"""
39-
data = configuration.get_yaml_configurations().dict()["actions"]
38+
"""API for viewing whiteboard_tags and associated data"""
39+
actions = configuration.get_actions_dict()
4040
if whiteboard_tag:
41-
wb_val = data.get(whiteboard_tag)
41+
wb_val = actions.get(whiteboard_tag)
4242
if wb_val:
43-
data = wb_val
44-
return data
43+
actions = wb_val
44+
return actions
4545

4646

4747
@api_router.get("/actions/")
4848
def get_actions_by_type(action_type: Optional[str] = None):
49-
"""API for viewing actions"""
50-
configured_actions = configuration.get_yaml_configurations().dict()["actions"]
49+
"""API for viewing actions within the config; `action_type` matched on end of action identifier"""
50+
actions = configuration.get_actions_dict()
5151
if action_type:
5252
data = [
53-
a["action"]
54-
for a in configured_actions.values()
55-
if a["action"].endswith(action_type)
53+
a["action"] for a in actions.values() if a["action"].endswith(action_type)
5654
]
5755
else:
58-
data = [a["action"] for a in configured_actions.values()]
56+
data = [a["action"] for a in actions.values()]
5957
return data
6058

6159

6260
@api_router.get("/powered_by_jbi", response_class=HTMLResponse)
6361
def powered_by_jbi(request: Request, enabled: Optional[bool] = None):
6462
"""API for `Powered By` endpoint"""
65-
data = configuration.get_yaml_configurations().dict()["actions"]
63+
actions = configuration.get_actions_dict()
6664
context = {
6765
"request": request,
6866
"title": "Powered by JBI",
69-
"num_configs": len(data),
70-
"data": data,
67+
"num_configs": len(actions),
68+
"data": actions,
7169
"enable_query": enabled,
7270
}
7371
return templates.TemplateResponse("powered_by_template.html", context)

tests/unit/jbi/test_configuration.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99

1010
def test_mock_jbi_files():
1111
with pytest.raises(configuration.ConfigError):
12-
configuration.get_yaml_configurations(
13-
jbi_config_file="tests/unit/jbi/test-config.yaml"
14-
)
12+
configuration.get_actions(jbi_config_file="tests/unit/jbi/test-config.yaml")
1513

1614

1715
def test_actual_jbi_files():
18-
jbi_map = configuration.get_yaml_configurations()
16+
jbi_map = configuration.get_actions()
1917
assert jbi_map

0 commit comments

Comments
 (0)