Skip to content

Commit fd738ac

Browse files
Merge pull request #15 from mozilla/iss-7
PR to handle Issue #7 and #12
2 parents 8badff2 + 80bb0cd commit fd738ac

File tree

13 files changed

+56
-38
lines changed

13 files changed

+56
-38
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repos:
55
name: pylint
66
entry: poetry run pylint
77
language: system
8-
exclude: ^migrations/
8+
exclude: ^tests/
99
types: [python]
1010
- repo: https://github.com/pre-commit/pre-commit-hooks
1111
rev: v2.1.0
@@ -20,6 +20,7 @@ repos:
2020
'--indent', '4',
2121
'--no-sort-keys',
2222
]
23+
exclude: "infra/k8s/secret.json"
2324
- id: trailing-whitespace
2425
- repo: local
2526
hooks:

infra/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ RUN bandit -lll --recursive src --exclude "src/poetry.lock,src/.venv,src/.mypy,s
8787
RUN mypy src
8888
RUN black --config ./pyproject.toml --check src tests
8989
RUN isort --recursive --settings-path ./pyproject.toml --check-only src
90-
RUN pylint src tests/unit
90+
RUN pylint src tests
9191
RUN yamllint -d "{extends: default, rules: {key-duplicates: enable, key-ordering: enable}}" ./config
9292
CMD ./infra/detect_secrets_helper.sh
9393

infra/gunicorn_conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@
7373
}
7474

7575

76-
def child_exit(server, worker):
76+
def child_exit(server, worker): # pylint: disable=missing-function-docstring
7777
multiprocess.mark_process_dead(worker.pid)

pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ testpaths = [
4545
[tool.pylint]
4646
[tool.pylint.'MESSAGES CONTROL']
4747
disable = [
48-
# "C0114", #missing-module-docstring
49-
"C0115", #missing-class-docstring
50-
"C0116", #missing-function-docstring
5148
"C0301", #line-too-long
5249
"R0903", #too-few-public-methods
5350
"W0613", #unused-argument
@@ -57,7 +54,7 @@ testpaths = [
5754
[tool.pylint.MASTER]
5855
load-plugins='pylint_pytest'
5956
ignore='third_party'
60-
57+
ignore-patterns = "tests/*"
6158

6259
[tool.isort]
6360
profile = "black"

src/app/api.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,13 @@
3030

3131
@app.get("/", include_in_schema=False)
3232
def root(request: Request):
33-
"""GET via root redirects to /docs.
34-
- Args:
35-
- Returns:
36-
- **redirect**: Redirects call to ./docs
37-
"""
33+
"""GET via root redirects to /docs."""
3834
return RedirectResponse(url="./docs")
3935

4036

4137
@app.middleware("http")
4238
async def request_summary(request: Request, call_next):
39+
"""Middleware to log request info"""
4340
summary_logger = logging.getLogger("request.summary")
4441
previous_time = time.time()
4542

@@ -66,6 +63,7 @@ async def request_summary(request: Request, call_next):
6663

6764
@app.on_event("startup")
6865
def startup_event():
66+
"""On app startup perform these setup operations"""
6967
configure_logging()
7068

7169

src/app/environment.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
Module dedicated to interacting with the environment (variables, version.json)
33
"""
44
import json
5-
import os
65
from functools import lru_cache
6+
from pathlib import Path
77

88
from pydantic import BaseSettings
99

1010

1111
class Settings(BaseSettings):
12+
"""The Settings object extracts environment variables for convenience."""
13+
1214
host: str = "0.0.0.0"
1315
port: str = "80"
1416
app_reload: bool = True
@@ -29,19 +31,15 @@ class Settings(BaseSettings):
2931

3032
@lru_cache()
3133
def get_settings() -> Settings:
34+
"""Return the Settings object; use cache"""
3235
return Settings()
3336

3437

3538
@lru_cache()
3639
def get_version():
37-
"""
38-
Return contents of version.json.
39-
This has generic data in repo, but gets the build details in CI.
40-
"""
41-
_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
42-
version_path = os.path.join(_root, "version.json")
40+
"""Return contents of version.json. This has generic data in repo, but gets the build details in CI."""
4341
info = {}
44-
if os.path.exists(version_path):
45-
with open(version_path, "r", encoding="utf8") as version_file:
46-
info = json.load(version_file)
42+
version_path = Path(__file__).parents[2] / "version.json"
43+
if version_path.exists():
44+
info = json.loads(version_path.read_text(encoding="utf8"))
4745
return info

src/app/log.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
def configure_logging():
14+
"""Configure logging; mozlog format for Dockerflow"""
1415
logging_config = {
1516
"version": 1,
1617
"formatters": {

src/app/monitor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def get_heartbeat(
2828
request: Request,
2929
settings: environment.Settings = Depends(environment.get_settings),
3030
):
31+
"""Dockerflow API for heartbeat: GET"""
3132
return heartbeat(request, settings)
3233

3334

@@ -36,6 +37,7 @@ def head_heartbeat(
3637
request: Request,
3738
settings: environment.Settings = Depends(environment.get_settings),
3839
):
40+
"""Dockerflow API for heartbeat: HEAD"""
3941
return heartbeat(request, settings)
4042

4143

@@ -46,11 +48,13 @@ def lbheartbeat(request: Request):
4648

4749
@api_router.get("/__lbheartbeat__")
4850
def get_lbheartbeat(request: Request):
51+
"""Dockerflow API for lbheartbeat: GET"""
4952
return lbheartbeat(request)
5053

5154

5255
@api_router.head("/__lbheartbeat__")
5356
def head_lbheartbeat(request: Request):
57+
"""Dockerflow API for lbheartbeat: HEAD"""
5458
return lbheartbeat(request)
5559

5660

src/jbi/configuration.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Parsing and validating the YAML configuration occurs within this module
3-
"""
1+
"""Parsing and validating the YAML configuration occurs within this module"""
42
import importlib
53
import logging
64
from inspect import signature
@@ -17,16 +15,17 @@
1715

1816

1917
class ConfigError(Exception):
20-
pass
18+
"""Errors used to determine when the Configuration is invalid"""
2119

2220

2321
class ProcessError(Exception):
24-
pass
22+
"""Error when an exception occurs during processing"""
2523

2624

2725
def get_yaml_configurations(
2826
jbi_config_file: str = f"config/config.{settings.env}.yaml",
2927
) -> Dict[str, Dict]:
28+
"""Convert and validate YAML configuration to python dict"""
3029

3130
with open(jbi_config_file, encoding="utf-8") as file:
3231
try:
@@ -42,6 +41,7 @@ def get_yaml_configurations(
4241

4342

4443
def process_actions(action_configuration) -> Dict[str, Dict]:
44+
"""Validate `actions` section of the YAML config"""
4545
requested_actions = {}
4646
for yaml_action_key, inner_action_dict in action_configuration.items():
4747
inner_action_dict.setdefault("action", "src.jbi.whiteboard_actions.default")
@@ -56,7 +56,7 @@ def process_actions(action_configuration) -> Dict[str, Dict]:
5656

5757

5858
def validate_action_yaml_jbi_naming(yaml_action_key, action_dict):
59-
# Validate yaml_action_key == parameters.whiteboard_tag
59+
"""Validate yaml_action_key == parameters.whiteboard_tag"""
6060
wb_tag = action_dict["parameters"].get("whiteboard_tag")
6161
if yaml_action_key != wb_tag:
6262
raise ConfigError(
@@ -66,7 +66,7 @@ def validate_action_yaml_jbi_naming(yaml_action_key, action_dict):
6666

6767

6868
def validate_action_yaml_module(action_dict: Dict[str, Any]):
69-
# Validate action: exists, has init function, and has expected params
69+
"""Validate action: exists, has init function, and has expected params"""
7070
try:
7171
action: str = action_dict.get("action") # type: ignore
7272
action_parameters: Optional[Dict[str, Any]] = action_dict.get("parameters")

src/jbi/router.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,23 @@
1919

2020

2121
def execute_request(request, settings):
22-
# Is request valid?
23-
# Is whiteboard known?
24-
# Execute desired action -- based on whiteboard config
25-
pass
22+
"""Execute action"""
2623

2724

2825
@api_router.post("/bugzilla_webhook")
2926
def bugzilla_webhook(
3027
request: Request,
3128
settings: environment.Settings = Depends(environment.get_settings),
3229
):
30+
"""API endpoint that Bugzilla Webhook Events request"""
3331
return execute_request(request, settings)
3432

3533

3634
@api_router.get("/whiteboard_tags/")
3735
def get_whiteboard_tag(
3836
whiteboard_tag: Optional[str] = None,
3937
):
38+
"""API for viewing whiteboard_tags"""
4039
data = configuration.get_yaml_configurations()
4140
if whiteboard_tag:
4241
wb_val = data.get(whiteboard_tag)
@@ -47,6 +46,7 @@ def get_whiteboard_tag(
4746

4847
@api_router.get("/actions/")
4948
def get_actions_by_type(action_type: Optional[str] = None):
49+
"""API for viewing actions"""
5050
configured_actions = configuration.get_yaml_configurations()
5151
if action_type:
5252
data = [
@@ -61,6 +61,7 @@ def get_actions_by_type(action_type: Optional[str] = None):
6161

6262
@api_router.get("/powered_by_jbi", response_class=HTMLResponse)
6363
def powered_by_jbi(request: Request, enabled: Optional[bool] = None):
64+
"""API for `Powered By` endpoint"""
6465
data = configuration.get_yaml_configurations()
6566
context = {
6667
"request": request,

0 commit comments

Comments
 (0)