-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor/webhooks tokens #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
c7e437e
feat: Add Slack webhook notifications for temperature alerts
fakebizprez 8450b0c
refactor: Remove auto-generate token feature
fakebizprez aaec873
docs: Update documentation for webhook feature
fakebizprez f53e8c9
feat: Integrate Flask-RESTX for webhook management API
fakebizprez a424d75
fix: Update webhook configuration model and API security settings
fakebizprez ac95667
Update .claude/skills/flask-restx-webhooks/SKILL.md
fakebizprez 197e569
Update temp_monitor.py
fakebizprez 3d75232
test: Add integration tests for webhook API endpoints
fakebizprez dfe75a7
fix: Use webhooks_ns.abort() for proper error responses
fakebizprez 09f3251
fix: Validate URL requirement for partial webhook config updates
fakebizprez 23ec9f4
Merge pull request #25 from freightCognition/hotfix/restx
fakebizprez b1524a4
fix: Remove validate=True to preserve backward-compatible error format
fakebizprez 2c240b8
Merge pull request #26 from freightCognition/hotfix/restx
fakebizprez f8d905e
Update .claude/skills/flask-restx-webhooks/examples/basic-webhook.py
fakebizprez 9633ab6
Update .claude/skills/flask-restx-webhooks/examples/test_webhook.py
fakebizprez 2b72780
Update .claude/skills/flask-restx-webhooks/examples/webhook-with-sign…
fakebizprez 7975449
feat: Add server-side validation for webhook config integer fields
fakebizprez 62132af
Remove CLAUDE.md, WEBHOOK_QUICKSTART.md, and WEBHOOKS.md files as par…
fakebizprez 50ffd7d
feat: Introduce comprehensive documentation for the Temperature Monit…
fakebizprez d898f21
fix: Add error correlation IDs and prevent internal error detail leakage
fakebizprez 5a78d15
feat: Implement webhook URL masking for enhanced security
fakebizprez f9c5bf8
Update temp_monitor.log and temp_monitor.py for improved error handli…
fakebizprez 7ec2336
Update test_webhook.py
fakebizprez cd6c463
Update temp_monitor.py
fakebizprez b6b2cea
Update temp_monitor.py
fakebizprez 76eaf46
fix: require BEARER_TOKEN at startup, exit if missing
fakebizprez 8bddbca
Rewrite webhook tests with proper mocking and payload assertions
fakebizprez 56845bd
Remove deprecated agent files and documentation for codebase analysis…
fakebizprez 33394f0
gitignore
fakebizprez 7e51804
feat: Add comprehensive AGENTS.md documentation for Temperature Monit…
fakebizprez 5ec4fba
Update temp_monitor.py
fakebizprez c8a9525
chore: Update subproject reference in exception-details
fakebizprez fd71045
Merge hotfix/exception-details into refactor/webhooks-tokens
fakebizprez 753e9c8
refactor: Revise README for clarity and completeness
fakebizprez 1a571f4
chore: Update Docker commands in documentation for consistency
fakebizprez aafccd6
feat: Add Cloudflare Tunnel support and update documentation
fakebizprez ab22fe9
feat: Enable manual workflow deployment from any branch for testing
fakebizprez c28089d
chore: Update configuration and documentation for webhook features
fakebizprez 71589af
chore: Enable status updates in CI workflow
fakebizprez b193846
Update .github/workflows/ci.yml
fakebizprez b02d4e0
chore: Remove environment input from CI workflow
fakebizprez 07bf4b6
chore: Enhance CI workflow for environment variable validation and .e…
fakebizprez 7dd0763
Merge pull request #34 from freightCognition/feature/lhlai-236-setup-…
fakebizprez 1674925
chore: Simplify .env file creation in CI workflow
fakebizprez c2edb32
chore: Refactor CI workflow to remove unnecessary deployment input
fakebizprez 422f72a
.
fakebizprez 6f09f2a
chore: Remove memory reservation from docker-compose.yml
fakebizprez d810f84
chore: Remove memory limit from docker-compose.yml
fakebizprez a71545b
chore: Remove test.yml file and maintain docker-compose.yml formatting
fakebizprez 2e059df
Merge pull request #35 from freightCognition/test
fakebizprez 5a96295
fix: Update repository URL in README.md
fakebizprez 0db8988
Update temp_monitor.py
fakebizprez 6e570ea
Update test_webhook.py
fakebizprez 81e2e3d
Enhance webhook URL validation and update tests
fakebizprez bed4d74
Update webhook_service.py
fakebizprez ba21706
Enhance logging and thread safety in temp_monitor
fakebizprez cb9ef19
Update temp_monitor.py
fakebizprez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,56 @@ | ||
| # Bearer token for API authentication | ||
| # Leave this blank or commented out on first run - a secure token will be auto-generated | ||
| # and saved to .env. Only set this if you want to use a specific token. | ||
| # BEARER_TOKEN= | ||
| # Bearer token for API authentication (REQUIRED) | ||
| # Generate a secure token with: python3 -c "import secrets; print(secrets.token_hex(32))" | ||
| # Then paste it here: | ||
| BEARER_TOKEN= | ||
|
|
||
| # Log file path (defaults to temp_monitor.log in current directory) | ||
| # Can be absolute or relative path | ||
| LOG_FILE=temp_monitor.log | ||
|
|
||
| # ===== CLOUDFLARED TUNNEL ===== | ||
| # Cloudflare Tunnel token from Zero Trust dashboard | ||
| # Used by docker-compose cloudflared service | ||
| CLOUDFLARED_TOKEN= | ||
|
|
||
| # ===== WEBHOOK CONFIGURATION ===== | ||
| # Slack incoming webhook URL for alerts and notifications (optional - required for webhook features) | ||
| # Get this from: https://api.slack.com/messaging/webhooks | ||
| SLACK_WEBHOOK_URL= | ||
|
|
||
| # Enable or disable webhook notifications (default: true) | ||
| WEBHOOK_ENABLED=true | ||
|
|
||
| # Webhook retry configuration | ||
| WEBHOOK_RETRY_COUNT=3 | ||
| WEBHOOK_RETRY_DELAY=5 | ||
| WEBHOOK_TIMEOUT=10 | ||
|
|
||
| # ===== ALERT THRESHOLDS ===== | ||
| # Temperature thresholds in Celsius (set to empty to disable) | ||
| # Default: 15°C (59°F) min, 27°C (80.6°F) max | ||
| ALERT_TEMP_MIN_C=15.0 | ||
| ALERT_TEMP_MAX_C=27.0 | ||
|
|
||
| # Humidity thresholds in percentage (set to empty to disable) | ||
| # Default: 30% min, 70% max | ||
| ALERT_HUMIDITY_MIN=30.0 | ||
| ALERT_HUMIDITY_MAX=70.0 | ||
|
|
||
| # ===== PERIODIC STATUS UPDATES ===== | ||
| # Enable periodic status updates via webhook (default: false) | ||
| # Set to 'true' to receive regular status reports at specified intervals | ||
| STATUS_UPDATE_ENABLED=false | ||
|
|
||
| # Interval for status updates in seconds (default: 3600 = 1 hour) | ||
| # Common values: | ||
| # - 1800 = 30 minutes | ||
| # - 3600 = 1 hour (recommended) | ||
| # - 7200 = 2 hours | ||
| # - 14400 = 4 hours | ||
| # - 86400 = 24 hours (daily) | ||
| # Note: Cannot be less than 60 seconds (sampling interval) | ||
| STATUS_UPDATE_INTERVAL=3600 | ||
|
|
||
| # Send status update immediately on startup (default: false) | ||
| # Useful for confirming service is running after deployment | ||
| STATUS_UPDATE_ON_STARTUP=false | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: ["main", "master"] | ||
| pull_request: | ||
| branches: ["main", "master"] | ||
| release: | ||
| types: [published] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| tests: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| strategy: | ||
| matrix: | ||
| python-version: ["3.9"] | ||
| env: | ||
| BEARER_TOKEN: test_token_ci | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| cache: pip | ||
| cache-dependency-path: requirements.txt | ||
|
|
||
| - name: Install dependencies (exclude Sense HAT) | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| grep -v '^sense-hat' requirements.txt | grep -v '^#' | grep -v '^$' | xargs pip install | ||
|
|
||
| - name: Run tests | ||
| run: | | ||
| python test_webhook_api.py | ||
| python test_webhook.py | ||
| python test_periodic_updates.py | ||
| python test_api_models.py | ||
|
|
||
| deploy: | ||
| runs-on: self-hosted | ||
| needs: tests | ||
| timeout-minutes: 20 | ||
| # SECURITY: Only deploy from trusted sources (requires write access to repo) | ||
| # - Manual trigger (workflow_dispatch) - requires write access | ||
| # - Release published - requires write access | ||
| # - Push to main/master - requires write access | ||
| # NEVER runs on pull_request events (untrusted forks could execute malicious code) | ||
| if: | | ||
| github.event_name == 'workflow_dispatch' || | ||
| github.event_name == 'release' || | ||
| (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) | ||
| environment: | ||
| name: production | ||
| url: http://raspberrypi.local:8080 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Create .env from GitHub Secrets | ||
| run: | | ||
| # Validate required secrets (BEARER_TOKEN is required for API auth) | ||
| if [ -z "${BEARER_TOKEN}" ]; then | ||
| echo "Missing required secret: BEARER_TOKEN" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Create .env file with required configuration | ||
| echo "BEARER_TOKEN=${BEARER_TOKEN}" > .env | ||
|
|
||
| # Add optional Cloudflare Tunnel token if configured | ||
| if [ -n "${CLOUDFLARED_TOKEN}" ]; then | ||
| echo "CLOUDFLARED_TOKEN=${CLOUDFLARED_TOKEN}" >> .env | ||
| fi | ||
|
|
||
| # Add optional Slack webhook if configured (enables alerts/status updates) | ||
| if [ -n "${SLACK_WEBHOOK_URL}" ]; then | ||
| echo "SLACK_WEBHOOK_URL=${SLACK_WEBHOOK_URL}" >> .env | ||
| echo "WEBHOOK_ENABLED=true" >> .env | ||
| fi | ||
|
|
||
| # Production monitoring defaults (intentionally enabled for production, | ||
| # differs from local development defaults in .env.example) | ||
| echo "ALERT_TEMP_MIN_C=15.0" >> .env | ||
| echo "ALERT_TEMP_MAX_C=27.0" >> .env | ||
| echo "ALERT_HUMIDITY_MIN=30.0" >> .env | ||
| echo "ALERT_HUMIDITY_MAX=70.0" >> .env | ||
| echo "STATUS_UPDATE_ENABLED=true" >> .env | ||
| echo "STATUS_UPDATE_INTERVAL=3600" >> .env | ||
| echo "STATUS_UPDATE_ON_STARTUP=true" >> .env | ||
|
|
||
| chmod 600 .env | ||
| env: | ||
| BEARER_TOKEN: ${{ secrets.BEARER_TOKEN }} | ||
| CLOUDFLARED_TOKEN: ${{ secrets.CLOUDFLARED_TOKEN }} | ||
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
|
|
||
| - name: Ensure logs directory | ||
| run: mkdir -p logs | ||
|
|
||
| - name: Deploy with Docker Compose | ||
| run: docker compose -p temp-monitor up -d --build --remove-orphans |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,4 +10,6 @@ __pycache__/ | |
| *.py[cod] | ||
| *$py.class | ||
|
|
||
| .DS_Store | ||
| .DS_Store | ||
|
|
||
| .claude/ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.