Skip to content

Commit 291b874

Browse files
Fixing problems with Sonar + Scorecard
1 parent cd32fb4 commit 291b874

11 files changed

+32
-16
lines changed

docs/core/event_handler/api_gateway.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Each dynamic route you set must be part of your function signature. This allows
198198

199199
=== "dynamic_routes.py"
200200

201-
```python hl_lines="14 16"
201+
```python hl_lines="16 18"
202202
--8<-- "examples/event_handler_rest/src/dynamic_routes.py"
203203
```
204204

@@ -640,7 +640,7 @@ matches one of the allowed values.
640640

641641
=== "setting_cors.py"
642642

643-
```python hl_lines="5 11-12 34"
643+
```python hl_lines="7 14-15 38"
644644
--8<-- "examples/event_handler_rest/src/setting_cors.py"
645645
```
646646

@@ -652,7 +652,7 @@ matches one of the allowed values.
652652

653653
=== "setting_cors_extra_origins.py"
654654

655-
```python hl_lines="5 11-12 34"
655+
```python hl_lines="7 14 15 38"
656656
--8<-- "examples/event_handler_rest/src/setting_cors_extra_origins.py"
657657
```
658658

@@ -943,7 +943,7 @@ You can compress with gzip and base64 encode your responses via `compress` param
943943

944944
=== "compressing_responses_using_route.py"
945945

946-
```python hl_lines="17 27"
946+
```python hl_lines="19 29"
947947
--8<-- "examples/event_handler_rest/src/compressing_responses_using_route.py"
948948
```
949949

@@ -1154,7 +1154,7 @@ Let's assume you have `split_route.py` as your Lambda function entrypoint and ro
11541154
!!! info
11551155
This means all methods, including [middleware](#middleware) will work as usual.
11561156

1157-
```python hl_lines="5 13 16 25 28"
1157+
```python hl_lines="7 10 15 18 27 30"
11581158
--8<-- "examples/event_handler_rest/src/split_route_module.py"
11591159
```
11601160

@@ -1186,7 +1186,7 @@ When necessary, you can set a prefix when including a router object. This means
11861186

11871187
=== "split_route_prefix_module.py"
11881188

1189-
```python hl_lines="13 25"
1189+
```python hl_lines="14 26"
11901190
--8<-- "examples/event_handler_rest/src/split_route_prefix_module.py"
11911191
```
11921192

docs/utilities/middleware_factory.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ You can create your own middleware using `lambda_handler_decorator`. The decorat
3030
### Middleware with before logic
3131

3232
=== "getting_started_middleware_before_logic_function.py"
33-
```python hl_lines="5 26 27 36 37 39 44 45"
33+
```python hl_lines="5 26 27 35 36 38 41 42"
3434
--8<-- "examples/middleware_factory/src/getting_started_middleware_before_logic_function.py"
3535
```
3636

@@ -58,7 +58,7 @@ You can create your own middleware using `lambda_handler_decorator`. The decorat
5858
You can also have your own keyword arguments after the mandatory arguments.
5959

6060
=== "getting_started_middleware_with_params_function.py"
61-
```python hl_lines="6 30 31 41 56 57"
61+
```python hl_lines="6 30 31 41 53 54"
6262
--8<-- "examples/middleware_factory/src/getting_started_middleware_with_params_function.py"
6363
```
6464

examples/event_handler_rest/src/compressing_responses_using_route.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from urllib.parse import quote
2+
13
import requests
24

35
from aws_lambda_powertools import Logger, Tracer
@@ -27,6 +29,7 @@ def get_todos():
2729
@app.get("/todos/<todo_id>", compress=True)
2830
@tracer.capture_method
2931
def get_todo_by_id(todo_id: str): # same example using Response class
32+
todo_id = quote(todo_id, safe="")
3033
todos: requests.Response = requests.get(f"https://jsonplaceholder.typicode.com/todos/{todo_id}")
3134
todos.raise_for_status()
3235

examples/event_handler_rest/src/dynamic_routes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from urllib.parse import quote
2+
13
import requests
24
from requests import Response
35

@@ -14,6 +16,7 @@
1416
@app.get("/todos/<todo_id>")
1517
@tracer.capture_method
1618
def get_todo_by_id(todo_id: str): # value come as str
19+
todo_id = quote(todo_id, safe="")
1720
todos: Response = requests.get(f"https://jsonplaceholder.typicode.com/todos/{todo_id}")
1821
todos.raise_for_status()
1922

examples/event_handler_rest/src/setting_cors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from urllib.parse import quote
2+
13
import requests
24
from requests import Response
35

@@ -26,6 +28,7 @@ def get_todos():
2628
@app.get("/todos/<todo_id>")
2729
@tracer.capture_method
2830
def get_todo_by_id(todo_id: str): # value come as str
31+
todo_id = quote(todo_id, safe="")
2932
todos: Response = requests.get(f"https://jsonplaceholder.typicode.com/todos/{todo_id}")
3033
todos.raise_for_status()
3134

examples/event_handler_rest/src/setting_cors_extra_origins.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from urllib.parse import quote
2+
13
import requests
24
from requests import Response
35

@@ -26,6 +28,7 @@ def get_todos():
2628
@app.get("/todos/<todo_id>")
2729
@tracer.capture_method
2830
def get_todo_by_id(todo_id: str): # value come as str
31+
todo_id = quote(todo_id, safe="")
2932
todos: Response = requests.get(f"https://jsonplaceholder.typicode.com/todos/{todo_id}")
3033
todos.raise_for_status()
3134

examples/event_handler_rest/src/split_route_module.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from urllib.parse import quote
2+
13
import requests
24
from requests import Response
35

@@ -27,6 +29,7 @@ def get_todos():
2729
def get_todo_by_id(todo_id: str): # value come as str
2830
api_key = router.current_event.headers["X-Api-Key"]
2931

32+
todo_id = quote(todo_id, safe="")
3033
todos: Response = requests.get(f"{endpoint}/{todo_id}", headers={"X-Api-Key": api_key})
3134
todos.raise_for_status()
3235

examples/event_handler_rest/src/split_route_prefix_module.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from urllib.parse import quote
2+
13
import requests
24
from requests import Response
35

@@ -27,6 +29,7 @@ def get_todos():
2729
def get_todo_by_id(todo_id: str): # value come as str
2830
api_key = router.current_event.headers["X-Api-Key"]
2931

32+
todo_id = quote(todo_id, safe="")
3033
todos: Response = requests.get(f"{endpoint}/{todo_id}", headers={"X-Api-Key": api_key})
3134
todos.raise_for_status()
3235

examples/middleware_factory/src/combining_powertools_utilities_function.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
from typing import Callable
3+
from urllib.parse import quote
34

45
import boto3
56
import combining_powertools_utilities_schema as schemas
@@ -103,19 +104,20 @@ def get_comments():
103104

104105
return {"comments": comments.json()[:10]}
105106
except Exception as exc:
106-
raise InternalServerError(str(exc))
107+
raise InternalServerError(str(exc)) from exc
107108

108109

109110
@app.get("/comments/<comment_id>")
110111
@tracer.capture_method
111112
def get_comments_by_id(comment_id: str):
112113
try:
114+
comment_id = quote(comment_id, safe="")
113115
comments: requests.Response = requests.get(f"https://jsonplaceholder.typicode.com/comments/{comment_id}")
114116
comments.raise_for_status()
115117

116118
return {"comments": comments.json()}
117119
except Exception as exc:
118-
raise InternalServerError(str(exc))
120+
raise InternalServerError(str(exc)) from exc
119121

120122

121123
@middleware_custom

examples/middleware_factory/src/getting_started_middleware_before_logic_function.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ def middleware_before(
3535
if "status_id" not in detail:
3636
event["detail"]["status_id"] = "pending"
3737

38-
response = handler(event, context)
39-
40-
return response
38+
return handler(event, context)
4139

4240

4341
@middleware_before

0 commit comments

Comments
 (0)