Skip to content

Commit 0f9cf42

Browse files
author
Bryan Sieber
committed
Updating based on reviews. Yamllint update. Config split: dev, prod. JBI powered_by_jbi api updated.
1 parent 1ee3d51 commit 0f9cf42

File tree

10 files changed

+125
-86
lines changed

10 files changed

+125
-86
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,11 @@ repos:
6262
entry: poetry run black
6363
types: [python]
6464
language: system
65+
- repo: local
66+
hooks:
67+
- id: yamllint
68+
name: yamllint
69+
entry: poetry run yamllint
70+
args: ["-c", ".yamllint", 'config/']
71+
types: [file, yaml]
72+
language: system

.yamllint

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22

33
extends: default
44

5+
ignore: |
6+
src/
7+
tests/
8+
infra/
9+
.github/
10+
docker-compose.yaml
11+
.pre-commit-config.yaml
12+
13+
514
rules:
615
key-duplicates: enable
716
key-ordering: enable
817

18+
919
yaml-files:
10-
- 'config.yaml'
20+
- 'config/*.yaml'
1121
- '.yamllint'

config/config.dev.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
3+
# Action Config
4+
actions:
5+
devtest:
6+
contact: tbd
7+
description: DevTest whiteboard tag
8+
parameters:
9+
jira_project_key: OSS
10+
whiteboard_tag: devtest

config.yaml renamed to config/config.prod.yaml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,82 @@
33
# Action Config
44
actions:
55
addons:
6-
action: src.jbi.whiteboard_actions.default
6+
# action: src.jbi.whiteboard_actions.default
77
contact: tbd
88
description: Addons whiteboard tag for AMO Team
9-
enabled: false
9+
# enabled: false
1010
parameters:
1111
jira_project_key: WEBEXT
1212
whiteboard_tag: addons
1313
fidedi:
14-
action: src.jbi.whiteboard_actions.default
14+
# action: src.jbi.whiteboard_actions.default
1515
contact: tbd
1616
description: Firefox Desktop Integration whiteboard tag
1717
enabled: true
1818
parameters:
1919
jira_project_key: FIDEDI
2020
whiteboard_tag: fidedi
2121
fidefe:
22-
action: src.jbi.whiteboard_actions.default
22+
# action: src.jbi.whiteboard_actions.default
2323
contact: tbd
2424
description: Firefox Front End whiteboard tag
25-
enabled: false
25+
# enabled: false
2626
parameters:
2727
jira_project_key: FIDEFE
2828
whiteboard_tag: fidefe
2929
fxatps:
30-
action: src.jbi.whiteboard_actions.default
30+
# action: src.jbi.whiteboard_actions.default
3131
contact: tbd
3232
description: Privacy & Security and Anti-Tracking Team whiteboard tag
33-
enabled: false
33+
# enabled: false
3434
parameters:
3535
jira_project_key: FXATPS
3636
whiteboard_tag: fxatps
3737
fxsync:
38-
action: src.jbi.whiteboard_actions.default
38+
# action: src.jbi.whiteboard_actions.default
3939
contact: tbd
4040
description: Firefox Sync Team whiteboard tag
41-
enabled: false
41+
# enabled: false
4242
parameters:
4343
jira_project_key: SYNC
4444
whiteboard_tag: fxsync
4545
gv:
46-
action: src.jbi.whiteboard_actions.default
46+
# action: src.jbi.whiteboard_actions.default
4747
contact: tbd
4848
description: GeckoView Team whiteboard tag
49-
enabled: false
49+
# enabled: false
5050
parameters:
5151
jira_project_key: ANDP
5252
whiteboard_tag: gv
5353
mr2qa:
54-
action: src.jbi.whiteboard_actions.default
54+
# action: src.jbi.whiteboard_actions.default
5555
contact: tbd
5656
description: MR2 whiteboard tag
57-
enabled: false
57+
# enabled: false
5858
parameters:
5959
jira_project_key: MR2
6060
whiteboard_tag: mr2qa
6161
mv3:
62-
action: src.jbi.whiteboard_actions.default
62+
# action: src.jbi.whiteboard_actions.default
6363
contact: tbd
6464
description: MV3 whiteboard tag
65-
enabled: false
65+
# enabled: false
6666
parameters:
6767
jira_project_key: WEBEXT
6868
whiteboard_tag: mv3
6969
prodtest:
70-
action: src.jbi.whiteboard_actions.default
70+
# action: src.jbi.whiteboard_actions.default
7171
contact: tbd
7272
description: ProdTest tag
73-
enabled: false
73+
# enabled: false
7474
parameters:
7575
jira_project_key: OSS
7676
whiteboard_tag: prodtest
7777
proton:
78-
action: src.jbi.whiteboard_actions.default
78+
# action: src.jbi.whiteboard_actions.default
7979
contact: tbd
8080
description: Proton whiteboard tag for Firefox Frontend
81-
enabled: false
81+
# enabled: false
8282
parameters:
8383
jira_project_key: FIDEFE
8484
whiteboard_tag: proton

infra/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ RUN mypy src
8888
RUN black --config ./pyproject.toml --check src tests
8989
RUN isort --recursive --settings-path ./pyproject.toml --check-only src
9090
RUN pylint src tests/unit
91-
RUN yamllint .
91+
RUN yamllint -d "{extends: default, rules: {key-duplicates: enable, key-ordering: enable}}" ./config
9292
CMD ./infra/detect_secrets_helper.sh
9393

9494

src/app/environment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Settings(BaseSettings):
99
host: str = "0.0.0.0"
1010
port: str = "80"
1111
app_reload: bool = True
12+
env: str = "dev"
1213

1314
# Jira
1415
jira_base_url: str = "https://jira.allizom.org/"

src/app/log.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def configure_logging():
2626
},
2727
"loggers": {
2828
"request.summary": {"handlers": ["console"], "level": "INFO"},
29+
"src.jbi": {"handlers": ["console"], "level": "INFO"},
2930
},
3031
}
3132

src/jbi/configuration.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import importlib
2+
import logging
23
from inspect import signature
34
from types import ModuleType
45
from typing import Any, Dict, Optional
@@ -9,6 +10,7 @@
910
from src.app import environment
1011

1112
settings = environment.get_settings()
13+
jbi_logger = logging.getLogger("src.jbi")
1214

1315

1416
class ConfigError(Exception):
@@ -20,35 +22,32 @@ class ProcessError(Exception):
2022

2123

2224
def get_yaml_configurations(
23-
jbi_config_file: str = "config.yaml", process_only_enabled: bool = True
25+
jbi_config_file: str = f"config/config.{settings.env}.yaml",
2426
) -> Dict[str, Dict]:
2527

2628
with open(jbi_config_file, encoding="utf-8") as file:
2729
try:
2830
file_data = file.read()
2931
data = yaml.load(file_data, Loader)
3032
validated_action_dict = process_actions(
31-
action_configuration=data.get("actions"),
32-
process_only_enabled=process_only_enabled,
33+
action_configuration=data.get("actions")
3334
)
3435
return validated_action_dict
3536
except (ValueError, ConfigError, yaml.YAMLError) as exception:
36-
raise ProcessError("PROCESS ERROR: Errors exist.") from exception
37+
jbi_logger.exception(exception)
38+
raise ProcessError("Errors exist.") from exception
3739

3840

39-
def process_actions(
40-
action_configuration, process_only_enabled: bool = True
41-
) -> Dict[str, Dict]:
41+
def process_actions(action_configuration) -> Dict[str, Dict]:
4242
requested_actions = {}
4343
for yaml_action_key, inner_action_dict in action_configuration.items():
44-
# Check enabled state
45-
enabled = inner_action_dict.get("enabled")
46-
if enabled or not process_only_enabled:
47-
validate_action_yaml_jbi_naming(
48-
yaml_action_key=yaml_action_key, action_dict=inner_action_dict
49-
)
50-
validate_action_yaml_module(action_dict=inner_action_dict)
51-
requested_actions[yaml_action_key] = inner_action_dict
44+
inner_action_dict.setdefault("action", "src.jbi.whiteboard_actions.default")
45+
inner_action_dict.setdefault("enabled", False)
46+
validate_action_yaml_jbi_naming(
47+
yaml_action_key=yaml_action_key, action_dict=inner_action_dict
48+
)
49+
validate_action_yaml_module(action_dict=inner_action_dict)
50+
requested_actions[yaml_action_key] = inner_action_dict
5251
return requested_actions
5352

5453

@@ -59,17 +58,19 @@ def validate_action_yaml_jbi_naming(yaml_action_key, action_dict):
5958
wb_tag = action_parameters.get("whiteboard_tag")
6059
if yaml_action_key != wb_tag:
6160
raise ConfigError(
62-
f"CONFIG ERROR: `{yaml_action_key}` setup, but expected '{wb_tag}'"
61+
f"Expected action key '{wb_tag}', found `{yaml_action_key}."
6362
"(from the `parameters.whiteboard_tag` field)."
6463
)
6564
except (TypeError, AttributeError) as exception:
66-
raise ConfigError("CONFIG ERROR: Action is not properly setup.") from exception
65+
raise ConfigError("Action is not properly setup.") from exception
6766

6867

6968
def validate_action_yaml_module(action_dict: Dict[str, Any]):
7069
# Validate action: exists, has init function, and has expected params
7170
try:
7271
action: str = action_dict.get("action") # type: ignore
72+
print(action_dict)
73+
print(action)
7374
action_parameters: Optional[Dict[str, Any]] = action_dict.get("parameters")
7475
action_module: ModuleType = importlib.import_module(action)
7576
if not action_module:
@@ -79,6 +80,6 @@ def validate_action_yaml_module(action_dict: Dict[str, Any]):
7980

8081
signature(action_module.init).bind(**action_parameters) # type: ignore
8182
except ImportError as exception:
82-
raise ConfigError(f"CONFIG ERROR: Unknown action `{action}`.") from exception
83+
raise ConfigError(f"Unknown action `{action}`.") from exception
8384
except (TypeError, AttributeError) as exception:
84-
raise ConfigError("CONFIG ERROR: Action is not properly setup.") from exception
85+
raise ConfigError("Action is not properly setup.") from exception

0 commit comments

Comments
 (0)