Skip to content

Commit 0953344

Browse files
author
Shriyansh Agnihotri
authored
Changes in readme, setup helper script (#10)
### Summary 📝 Adding email id as feedback so that security patches can be informed, updated readme, and added setup helper script.
1 parent 016333e commit 0953344

File tree

4 files changed

+103
-7
lines changed

4 files changed

+103
-7
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,22 @@ For the hardcore enthusiasts, you can use Hercules via the source code to get a
300300

301301
## 📝 Configuration Details
302302

303+
### Disabling Telemetry
304+
305+
To disable telemetry, set the `TELEMETRY_ENABLED` environment variable to `0`:
306+
307+
```bash
308+
export TELEMETRY_ENABLED=0
309+
```
310+
311+
### Auto Mode
312+
313+
If `AUTO_MODE` is set to `1`, Hercules will not request an email during the run:
314+
315+
```bash
316+
export AUTO_MODE=1
317+
```
318+
303319
### Understanding the Environment File (`.env`)
304320

305321
To configure Hercules in detail:

entrypoint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ if [ ! -d "/testzeus-hercules/opt" ]; then
2222
touch /testzeus-hercules/opt/test_data/td.txt
2323
fi
2424

25+
export AUTO_MODE=1
26+
2527
# Execute the main application
2628
exec poetry run python testzeus_hercules

helper_scripts/hercules_setup.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11
4+
5+
# Create a new Python virtual environment named 'test'
6+
python3 -m venv test
7+
8+
# Activate the virtual environment
9+
source test/bin/activate
10+
11+
# Upgrade the 'testzeus-hercules' package
12+
pip install --upgrade testzeus-hercules
13+
playwright install --with-deps
14+
15+
#Set Headless as false
16+
export HEADLESS=false
17+
18+
# create a new directory named 'opt'
19+
mkdir -p opt/input opt/output opt/test_data
20+
21+
# create a intput/test.feature file
22+
echo "Feature: Open Google homepage\nScenario: User opens Google homepage\n Given I have a web browser open\n When I navigate to https://www.google.com\n Then I should see the Google homepage" > opt/input/test.feature
23+
24+
# get gpt-4o model API key by asking user
25+
echo "Enter your GPT-4o model API key:"
26+
read -s GPT_4O_API_KEY
27+
28+
# Run the 'testzeus-hercules' command with the specified parameters
29+
testzeus-hercules \
30+
--input-file opt/input/test.feature \
31+
--output-path opt/output \
32+
--test-data-path opt/test_data \
33+
--llm-model gpt-4o \
34+
--llm-model-api-key $GPT_4O_API_KEY

testzeus_hercules/telemetry.py

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pydantic import BaseModel
1212
from sentry_sdk.scrubber import DEFAULT_DENYLIST, DEFAULT_PII_DENYLIST, EventScrubber
1313
from sentry_sdk.types import Event, Hint
14+
import json
1415

1516
DSN = "https://d14d2ee82f26a3585b2a892fab7fffaa@o4508256143540224.ingest.us.sentry.io/4508256153042944"
1617

@@ -79,24 +80,66 @@ def my_before_send(event: Event, hint: Hint) -> Event | None:
7980
sentry_sdk.set_user(None)
8081

8182

82-
def get_installation_id(file_path="installation_id.txt") -> str:
83-
"""Generate or load a unique installation ID."""
83+
def get_installation_id(
84+
file_path: str = "installation_id.txt", is_manual_run: bool = True
85+
) -> Dict[str, Any]:
86+
"""Generate or load installation data.
87+
88+
If the file exists and contains a dict, return it.
89+
If the file exists and contains only the installation ID, return a dict with default values.
90+
If the file does not exist:
91+
- If triggered manually by the user (is_manual_run is True), prompt for user_email.
92+
- Generate a new installation ID and save all data as a dict.
93+
- If not triggered manually, use default values for user_email.
94+
"""
8495
if os.path.exists(file_path):
96+
data = {
97+
"user_email": "old_email@example.com",
98+
}
99+
rewrite_data = False
85100
with open(file_path, "r") as file:
86-
return file.read().strip()
101+
content = file.read().strip()
102+
installation_id = content
103+
data["installation_id"] = installation_id
104+
try:
105+
data = json.loads(content)
106+
if isinstance(data, dict) and "installation_id" in data:
107+
return data
108+
except json.JSONDecodeError:
109+
rewrite_data = True
110+
if rewrite_data:
111+
with open(file_path, "w") as file:
112+
json.dump(data, file)
87113
else:
88114
installation_id = str(uuid.uuid4())
115+
user_email = "new_email@example.com"
116+
if is_manual_run:
117+
print(
118+
"We need your email to inform you about any urgent security patches or issues detected in testzeus-hercules."
119+
)
120+
n_user_email = input(
121+
"Please provide your email (or press Enter to skip with empty email): "
122+
)
123+
user_email = n_user_email if n_user_email else user_email
124+
125+
data = {
126+
"user_email": user_email,
127+
"installation_id": installation_id,
128+
}
89129
with open(file_path, "w") as file:
90-
file.write(installation_id)
91-
return installation_id
130+
json.dump(data, file)
131+
return data
92132

93133

94134
# Initialize the installation_id
95-
installation_id = get_installation_id()
135+
installation_data = get_installation_id(
136+
is_manual_run=os.environ.get("AUTO_MODE", "0") == "0"
137+
)
96138

97139
# Global event collector with event_type buckets
98140
event_collector = {
99-
"installation_id": installation_id,
141+
"installation_id": installation_data["installation_id"],
142+
"user_email": installation_data["user_email"],
100143
"buckets": {},
101144
"start_time": datetime.now().isoformat(),
102145
}
@@ -144,6 +187,7 @@ def build_final_message() -> Dict[str, Any]:
144187
"""
145188
message = {
146189
"installation_id": event_collector["installation_id"],
190+
"user_email": event_collector["user_email"],
147191
"session_start": event_collector["start_time"],
148192
"buckets": {
149193
event_type_s: events

0 commit comments

Comments
 (0)