Skip to content

Commit 1546775

Browse files
authored
Add ruff rules for bandit (#555)
* Add ruff rules for bandit * Changes following review
1 parent 9efa3a3 commit 1546775

File tree

27 files changed

+108
-49
lines changed

27 files changed

+108
-49
lines changed

docker/examples/basic/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ def hello():
3232

3333
# Execute the application
3434
if __name__ == "__main__":
35-
app.run(port=8080, host="0.0.0.0")
35+
app.run(port=8080)

docker/examples/multistage/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ def hello():
3232

3333
# Execute the application
3434
if __name__ == "__main__":
35-
app.run(port=8080, host="0.0.0.0")
35+
app.run(port=8080)

docs/modules/examples/pages/langchain-unstructured-astra.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ load_dotenv()
8686
url = "https://raw.githubusercontent.com/datastax/ragstack-ai/48bc55e7dc4de6a8b79fcebcedd242dc1254dd63/examples/notebooks/resources/attention_pages_9_10.pdf"
8787
file_path = "./attention_pages_9_10.pdf"
8888
89-
response = requests.get(url)
89+
response = requests.get(url, timeout=30)
9090
if response.status_code == 200:
9191
with open(file_path, "wb") as file:
9292
file.write(response.content)
@@ -264,7 +264,7 @@ load_dotenv()
264264
url = "https://raw.githubusercontent.com/datastax/ragstack-ai/48bc55e7dc4de6a8b79fcebcedd242dc1254dd63/examples/notebooks/resources/attention_pages_9_10.pdf"
265265
file_path = "./attention_pages_9_10.pdf"
266266
267-
response = requests.get(url)
267+
response = requests.get(url, timeout=30)
268268
if response.status_code == 200:
269269
with open(file_path, "wb") as file:
270270
file.write(response.content)

docs/modules/examples/pages/langchain_multimodal_gemini.adoc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ Let's see if Gemini Pro Vision can identify a part to an espresso machine and te
4747
----
4848
import requests
4949
50-
source_img_data = requests.get('https://drive.google.com/uc?export=view&id=15ddcn-AIxpvRdWcFGvIr77XLWdo4Maof').content
50+
source_img_data = requests.get(
51+
'https://drive.google.com/uc?export=view&id=15ddcn-AIxpvRdWcFGvIr77XLWdo4Maof',
52+
timeout=30,
53+
).content
5154
with open('coffee_maker_part.png', 'wb') as handler:
5255
handler.write(source_img_data)
5356
----
@@ -162,7 +165,7 @@ for i in range(len(df)):
162165
163166
# Download this product's image and save it to the Colab filesystem.
164167
# In a production system this binary data would be stored in Google Cloud Storage
165-
img_data = requests.get(image).content
168+
img_data = requests.get(image, timeout=30).content
166169
with open(f'{name}.png', 'wb') as handler:
167170
handler.write(img_data)
168171
@@ -303,7 +306,10 @@ from langchain.schema.messages import HumanMessage
303306
from vertexai.preview.vision_models import MultiModalEmbeddingModel, Image
304307
from astrapy.db import AstraDB
305308
306-
source_img_data = requests.get('https://drive.google.com/uc?export=view&id=15ddcn-AIxpvRdWcFGvIr77XLWdo4Maof').content
309+
source_img_data = requests.get(
310+
'https://drive.google.com/uc?export=view&id=15ddcn-AIxpvRdWcFGvIr77XLWdo4Maof',
311+
timeout=30,
312+
).content
307313
with open('coffee_maker_part.png', 'wb') as handler:
308314
handler.write(source_img_data)
309315
@@ -343,7 +349,7 @@ for i in range(len(df)):
343349
344350
# Download this product's image and save it to your local filesystem.
345351
# In a production system this binary data would be stored in Google Cloud Storage
346-
img_data = requests.get(image).content
352+
img_data = requests.get(image, timeout=30).content
347353
with open(f'{name}.png', 'wb') as handler:
348354
handler.write(img_data)
349355

docs/modules/examples/pages/llama-parse-astra.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Settings.embed_model = OpenAIEmbedding(
8383
url = "https://arxiv.org/pdf/1706.03762.pdf"
8484
file_path = "./attention.pdf"
8585
86-
response = requests.get(url)
86+
response = requests.get(url, timeout=30)
8787
if response.status_code == 200:
8888
with open(file_path, "wb") as file:
8989
file.write(response.content)

docs/modules/examples/partials/llama-parse.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Settings.embed_model = OpenAIEmbedding(
3131
# Download a PDF for indexing
3232
url = "https://arxiv.org/pdf/1706.03762.pdf"
3333
file_path = "./attention.pdf"
34-
response = requests.get(url)
34+
response = requests.get(url, timeout=30)
3535
if response.status_code == 200:
3636
with open(file_path, "wb") as file:
3737
file.write(response.content)

examples/evaluation/tru_dashboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import tru_shared
22

33
tru = tru_shared.init_tru()
4-
tru.run_dashboard(address="0.0.0.0", port=8501, force=True)
4+
tru.run_dashboard(force=True)

examples/notebooks/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
import tempfile
34
import time
45

56
from astrapy.db import AstraDB
@@ -16,9 +17,11 @@ def get_required_env(name) -> str:
1617

1718
# vertex-ai
1819
if "GOOGLE_APPLICATION_CREDENTIALS" not in os.environ:
19-
with open("/tmp/gcloud-account-key.json", "w") as f:
20+
with tempfile.NamedTemporaryFile(
21+
prefix="gcloud-account-key", suffix=".json", mode="w", delete=False
22+
) as f:
2023
f.write(os.getenv("GCLOUD_ACCOUNT_KEY_JSON", ""))
21-
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/tmp/gcloud-account-key.json"
24+
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = f.name
2225

2326
client = AstraDB(
2427
token=get_required_env("ASTRA_DB_APPLICATION_TOKEN"),

examples/notebooks/langchain-unstructured-astra.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"import requests\n",
7070
"\n",
7171
"url = \"https://raw.githubusercontent.com/datastax/ragstack-ai/main/examples/notebooks/resources/attention_pages_9_10.pdf\"\n",
72-
"response = requests.get(url)\n",
72+
"response = requests.get(url, timeout=30)\n",
7373
"with open(\"attention_pages_9_10.pdf\", \"wb\") as file:\n",
7474
" file.write(response.content)"
7575
]

examples/notebooks/langchain_multimodal_gemini.ipynb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,15 @@
146146
" auth.authenticate_user()\n",
147147
"except ImportError:\n",
148148
" import os\n",
149+
" import tempfile\n",
149150
"\n",
150151
" if \"GOOGLE_APPLICATION_CREDENTIALS\" not in os.environ:\n",
151152
" credentials = getpass(\"Enter Google JSON credentials file: \")\n",
152-
" with open(\"/tmp/gcloud-account-key.json\", \"w\") as f:\n",
153+
" with tempfile.NamedTemporaryFile(\n",
154+
" prefix=\"gcloud-account-key\", suffix=\".json\", delete=False\n",
155+
" ) as f:\n",
153156
" f.write(credentials)\n",
154-
" os.environ[\"GOOGLE_APPLICATION_CREDENTIALS\"] = \"/tmp/gcloud-account-key.json\""
157+
" os.environ[\"GOOGLE_APPLICATION_CREDENTIALS\"] = f.name"
155158
]
156159
},
157160
{
@@ -194,7 +197,8 @@
194197
"import requests\n",
195198
"\n",
196199
"source_img_data = requests.get(\n",
197-
" \"https://drive.google.com/uc?export=view&id=15ddcn-AIxpvRdWcFGvIr77XLWdo4Maof\"\n",
200+
" \"https://drive.google.com/uc?export=view&id=15ddcn-AIxpvRdWcFGvIr77XLWdo4Maof\",\n",
201+
" timeout=30,\n",
198202
").content\n",
199203
"with open(\"coffee_maker_part.png\", \"wb\") as handler:\n",
200204
" handler.write(source_img_data)"
@@ -607,7 +611,7 @@
607611
"\n",
608612
" # Download this product's image and save it to the Colab filesystem.\n",
609613
" # In a production system this binary data would be stored in Google Cloud Storage\n",
610-
" img_data = requests.get(image).content\n",
614+
" img_data = requests.get(image, timeout=30).content\n",
611615
" with open(f\"{name}.png\", \"wb\") as handler:\n",
612616
" handler.write(img_data)\n",
613617
"\n",

0 commit comments

Comments
 (0)