Skip to content

Commit ef80699

Browse files
committed
Remove skipped bandit check B113 and fixed issues for "[B113:request_without_timeout] Call to requests without timeout Severity: Medium Confidence: Low"
1 parent 282a570 commit ef80699

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ repos:
3434
rev: 1.8.6
3535
hooks:
3636
- id: bandit
37-
args: ["-ll", "--skip=B608,B113"]
37+
args: ["-ll", "--skip=B608"]
3838
files: .py$
3939
- repo: https://github.com/sqlfluff/sqlfluff
4040
rev: 3.0.6

airflow/dags/dags.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ def log_failure_to_slack(context):
3939
4040
<{ti.log_url}| Check Log >
4141
""" # noqa: E221, E222
42-
requests.post(slack_url, json={"text": message})
42+
requests.post(slack_url, json={"text": message}, timeout=5)
4343

4444
# This is very broad but we want to try to log _any_ exception to slack
4545
except Exception as e:
46-
requests.post(slack_url, json={"text": f"failed to log {type(e)} to slack"})
46+
requests.post(
47+
slack_url, json={"text": f"failed to log {type(e)} to slack"}, timeout=5
48+
)
4749

4850

4951
for dag_directory in dag_directories:

airflow/plugins/operators/scrape_state_geoportal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _make_api_request(self, url: str, params: Dict[str, Any], offset: int) -> Di
5757
"""Make API request with proper error handling."""
5858
try:
5959
params["resultOffset"] = offset
60-
response = requests.get(url, params=params)
60+
response = requests.get(url, params=params, timeout=5)
6161
response.raise_for_status()
6262
return response.json()
6363
except requests.exceptions.HTTPError as e:

apps/maps/calitp_map_utils/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def validate_geojson(
8181
is_compressed = path.endswith(".gz")
8282

8383
if path.startswith("https://"):
84-
resp = requests.get(path)
84+
resp = requests.get(path, timeout=5)
8585
resp.raise_for_status()
8686
d = json.loads(
8787
gzip.decompress(resp.content).decode() if is_compressed else resp.text
@@ -155,7 +155,7 @@ def validate_layers(
155155
typer.secho(
156156
f"Checking that {typer.style(layer.url, fg=typer.colors.CYAN)} exists..."
157157
)
158-
resp = requests.head(layer.url)
158+
resp = requests.head(layer.url, timeout=5)
159159

160160
try:
161161
resp.raise_for_status()

packages/calitp-data-analysis/calitp_data_analysis/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ def upload_file_to_github(
267267
f"{BASE}/repos/{repo}/contents/{os.path.dirname(path)}",
268268
params={"ref": branch},
269269
headers={"Authorization": f"token {token}"},
270+
timeout=5,
270271
)
271272
r.raise_for_status()
272273
item = next(i for i in r.json() if i["path"] == path)
@@ -286,6 +287,7 @@ def upload_file_to_github(
286287
"sha": sha,
287288
"content": base64.b64encode(contents).decode("utf-8"),
288289
},
290+
timeout=5,
289291
)
290292
r.raise_for_status()
291293
return

warehouse/scripts/publish.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def ckan_request(action: str, data: Dict) -> Response:
176176
f"{url}/api/action/{action}",
177177
data=encoder,
178178
headers={"Content-Type": encoder.content_type, "X-CKAN-API-Key": API_KEY}, # type: ignore
179+
timeout=5,
179180
)
180181

181182
if fsize <= CHUNK_SIZE:
@@ -185,6 +186,7 @@ def ckan_request(action: str, data: Dict) -> Response:
185186
data={"id": resource_id},
186187
headers={"Authorization": API_KEY}, # type: ignore
187188
files={"upload": file},
189+
timeout=5,
188190
)
189191
try:
190192
response.raise_for_status()

0 commit comments

Comments
 (0)