Skip to content

Commit

Permalink
Changes in readme, setup helper script (#10)
Browse files Browse the repository at this point in the history
### Summary 📝
Adding email id as feedback so that security patches can be informed, updated readme, and added setup helper script.
  • Loading branch information
shriyanshagnihotri authored Dec 5, 2024
1 parent 016333e commit 0953344
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 7 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,22 @@ For the hardcore enthusiasts, you can use Hercules via the source code to get a

## 📝 Configuration Details

### Disabling Telemetry

To disable telemetry, set the `TELEMETRY_ENABLED` environment variable to `0`:

```bash
export TELEMETRY_ENABLED=0
```

### Auto Mode

If `AUTO_MODE` is set to `1`, Hercules will not request an email during the run:

```bash
export AUTO_MODE=1
```

### Understanding the Environment File (`.env`)

To configure Hercules in detail:
Expand Down
2 changes: 2 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ if [ ! -d "/testzeus-hercules/opt" ]; then
touch /testzeus-hercules/opt/test_data/td.txt
fi

export AUTO_MODE=1

# Execute the main application
exec poetry run python testzeus_hercules
34 changes: 34 additions & 0 deletions helper_scripts/hercules_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11

# Create a new Python virtual environment named 'test'
python3 -m venv test

# Activate the virtual environment
source test/bin/activate

# Upgrade the 'testzeus-hercules' package
pip install --upgrade testzeus-hercules
playwright install --with-deps

#Set Headless as false
export HEADLESS=false

# create a new directory named 'opt'
mkdir -p opt/input opt/output opt/test_data

# create a intput/test.feature file
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

# get gpt-4o model API key by asking user
echo "Enter your GPT-4o model API key:"
read -s GPT_4O_API_KEY

# Run the 'testzeus-hercules' command with the specified parameters
testzeus-hercules \
--input-file opt/input/test.feature \
--output-path opt/output \
--test-data-path opt/test_data \
--llm-model gpt-4o \
--llm-model-api-key $GPT_4O_API_KEY
58 changes: 51 additions & 7 deletions testzeus_hercules/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pydantic import BaseModel
from sentry_sdk.scrubber import DEFAULT_DENYLIST, DEFAULT_PII_DENYLIST, EventScrubber
from sentry_sdk.types import Event, Hint
import json

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

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


def get_installation_id(file_path="installation_id.txt") -> str:
"""Generate or load a unique installation ID."""
def get_installation_id(
file_path: str = "installation_id.txt", is_manual_run: bool = True
) -> Dict[str, Any]:
"""Generate or load installation data.
If the file exists and contains a dict, return it.
If the file exists and contains only the installation ID, return a dict with default values.
If the file does not exist:
- If triggered manually by the user (is_manual_run is True), prompt for user_email.
- Generate a new installation ID and save all data as a dict.
- If not triggered manually, use default values for user_email.
"""
if os.path.exists(file_path):
data = {
"user_email": "[email protected]",
}
rewrite_data = False
with open(file_path, "r") as file:
return file.read().strip()
content = file.read().strip()
installation_id = content
data["installation_id"] = installation_id
try:
data = json.loads(content)
if isinstance(data, dict) and "installation_id" in data:
return data
except json.JSONDecodeError:
rewrite_data = True
if rewrite_data:
with open(file_path, "w") as file:
json.dump(data, file)
else:
installation_id = str(uuid.uuid4())
user_email = "[email protected]"
if is_manual_run:
print(
"We need your email to inform you about any urgent security patches or issues detected in testzeus-hercules."
)
n_user_email = input(
"Please provide your email (or press Enter to skip with empty email): "
)
user_email = n_user_email if n_user_email else user_email

data = {
"user_email": user_email,
"installation_id": installation_id,
}
with open(file_path, "w") as file:
file.write(installation_id)
return installation_id
json.dump(data, file)
return data


# Initialize the installation_id
installation_id = get_installation_id()
installation_data = get_installation_id(
is_manual_run=os.environ.get("AUTO_MODE", "0") == "0"
)

# Global event collector with event_type buckets
event_collector = {
"installation_id": installation_id,
"installation_id": installation_data["installation_id"],
"user_email": installation_data["user_email"],
"buckets": {},
"start_time": datetime.now().isoformat(),
}
Expand Down Expand Up @@ -144,6 +187,7 @@ def build_final_message() -> Dict[str, Any]:
"""
message = {
"installation_id": event_collector["installation_id"],
"user_email": event_collector["user_email"],
"session_start": event_collector["start_time"],
"buckets": {
event_type_s: events
Expand Down

0 comments on commit 0953344

Please sign in to comment.