Skip to content

Commit 42bdd0a

Browse files
Constrain Action.contact field to email address(es) (#90)
Constrain contact field so that it only accepts an email address or list of email addresses. For now, it also accepts a "tbd" string literal (since many actions have that as their contact at the moment), but this will emit a warning since we want that to be an email address eventually. This commit also: * Adds pydantic email extra for email address validation * Changes bad-config.yaml so that it has a bad contact value Co-authored-by: bsieber-mozilla <[email protected]>
1 parent 12dadd6 commit 42bdd0a

File tree

5 files changed

+93
-49
lines changed

5 files changed

+93
-49
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Below is a full example of an action configuration:
1919
```yaml
2020
action: src.jbi.whiteboard_actions.default
2121
allow_private: false
22-
contact: [[email protected]]
22+
2323
description: example configuration
2424
enabled: true
2525
parameters:
@@ -39,7 +39,7 @@ A bit more about the different fields...
3939
private bugs the bugzilla user that JBI runs as must be in the security groups that are making
4040
the bug private.
4141
- `contact`
42-
- list of strings
42+
- an email address, a list of email addresses, or a literal "tbd" to signify that no contact is available
4343
- If an issue arises with the workflow, communication will be established with these contacts
4444
- Please enter the contact information for one or more stakeholders
4545
- `description`
@@ -76,7 +76,7 @@ This is defined using a mapping on a per-project basis configured in the `status
7676
An example configuration:
7777
```yaml
7878
action: src.jbi.whiteboard_actions.default_with_assignee_and_status
79-
contact: [[email protected]]
79+
8080
description: example configuration
8181
enabled: true
8282
parameters:
@@ -166,7 +166,7 @@ GET /whiteboard_tags/
166166
{
167167
"addons": {
168168
"action": "src.jbi.whiteboard_actions.default",
169-
"contact": "tbd",
169+
"contact": "[email protected]",
170170
"description": "Addons whiteboard tag for AMO Team",
171171
"enabled": true,
172172
"parameters": {

poetry.lock

Lines changed: 75 additions & 38 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "MPL"
88
[tool.poetry.dependencies]
99
python = ">=3.8, <3.11"
1010
fastapi = "^0.73.0"
11-
pydantic = "^1.9.0"
11+
pydantic = {version = "^1.9.1", extras = ["email"]}
1212
uvicorn = {extras = ["standard"], version = "^0.17.4"}
1313
gunicorn = "^20.1.0"
1414
prometheus-client = "^0.13.1"

src/jbi/models.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
"""
44
import functools
55
import importlib
6+
import warnings
67
from inspect import signature
78
from types import ModuleType
8-
from typing import Any, Callable, Dict, Mapping, Optional
9+
from typing import Any, Callable, Dict, List, Literal, Mapping, Optional, Union
910

10-
from pydantic import Extra, root_validator, validator
11+
from pydantic import EmailStr, Extra, root_validator, validator
1112
from pydantic_yaml import YamlModel
1213

1314

@@ -16,7 +17,8 @@ class Action(YamlModel):
1617
Action is the inner model for each action in the configuration file"""
1718

1819
action: str = "src.jbi.whiteboard_actions.default"
19-
contact: str
20+
# TODO: Remove the tbd literal option when all actions have contact info # pylint: disable=fixme
21+
contact: Union[EmailStr, List[EmailStr], Literal["tbd"]]
2022
description: str
2123
enabled: bool = False
2224
allow_private: bool = False
@@ -75,16 +77,21 @@ def get(self, tag: Optional[str]) -> Optional[Action]:
7577
return self.__root__.get(tag.lower()) if tag else None
7678

7779
@validator("__root__")
78-
def validate_action_matches_whiteboard(
80+
def validate_actions(
7981
cls, actions: Mapping[str, Action]
8082
): # pylint: disable=no-self-argument, no-self-use
8183
"""
82-
Validate that the inner actions are named as expected
84+
Inspect action values with the context of the top-level key and:
85+
- Validate that the inner actions are named as expected (key matches
86+
whiteboard tag parameter)
87+
- If the action's contact is "tbd", emit a warning.
8388
"""
8489
if not actions:
8590
raise ValueError("no actions configured")
8691
for name, action in actions.items():
8792
if name.lower() != action.parameters["whiteboard_tag"]:
8893
raise ValueError("action name must match whiteboard tag")
94+
if action.contact == "tbd":
95+
warnings.warn(f"Provide contact data for `{name}` action.")
8996

9097
return actions

tests/unit/app/bad-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Action Config
33
should-be-A:
44
action: src.jbi.whiteboard_actions.default
5-
contact: tbd
5+
contact: foobar
66
description: test config
77
enabled: true
88
parameters:

0 commit comments

Comments
 (0)