Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 26
fix(plugin-config): handle missing type key in oneOf/anyOf schema fields#344
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1ac6499
fix(web-ui): dedup registry fetches, surface reconciliation warnings,…
4838fbd
fix(plugin-config): handle missing `type` key in schema fields using …
1b10211
fix(security): harden check-update, reconciliation status endpoint, a…
bd5d80d
fix: reconciliation status errors return graceful not-done instead of…
dba2f33
fix(bandit): replace hardcoded /tmp paths with tempfile.gettempdir() …
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
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
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 |
|---|---|---|
| @@ -2,14 +2,17 @@ | ||
| import json | ||
| import os | ||
| import re | ||
| import stat | ||
| import sys | ||
| import subprocess | ||
| import tempfile | ||
| import time | ||
| import hashlib | ||
| import uuid | ||
| import logging | ||
| from datetime import datetime | ||
| from pathlib import Path | ||
| from typing import Dict, Any | ||
| logger = logging.getLogger(__name__) | ||
| @@ -1384,6 +1387,59 @@ def get_system_version(): | ||
| except Exception as e: | ||
| return jsonify({'status': 'error', 'message': str(e)}), 500 | ||
| _update_check_cache: Dict[str, Any] = {'result': None, 'ts': 0.0} | ||
| _UPDATE_CHECK_TTL = 300 # 5 minutes — avoids a git fetch on every page load | ||
| @api_v3.route('/system/check-update', methods=['GET']) | ||
| def check_for_update(): | ||
| """Check whether a newer LEDMatrix commit is available on origin/main.""" | ||
| now = time.time() | ||
| if _update_check_cache['result'] and now - _update_check_cache['ts'] < _UPDATE_CHECK_TTL: | ||
| return jsonify(_update_check_cache['result']) | ||
| _safe: Dict[str, Any] = {'update_available': False, 'remote_sha': 'unknown', 'commits_behind': 0} | ||
| try: | ||
| cwd = str(PROJECT_ROOT) | ||
| fetch_result = subprocess.run( | ||
| ['git', 'fetch', 'origin', 'main', '--quiet'], | ||
| capture_output=True, timeout=10, cwd=cwd, | ||
| ) | ||
| if fetch_result.returncode != 0: | ||
| logger.warning("check-update: git fetch failed (rc=%d): %s", | ||
| fetch_result.returncode, | ||
| fetch_result.stderr.decode(errors='replace').strip()) | ||
| _update_check_cache['result'] = _safe | ||
| _update_check_cache['ts'] = now | ||
| return jsonify(_safe) | ||
| local = subprocess.run( | ||
| ['git', 'rev-parse', 'HEAD'], | ||
| capture_output=True, text=True, timeout=5, cwd=cwd, | ||
| ).stdout.strip() | ||
| remote = subprocess.run( | ||
| ['git', 'rev-parse', 'origin/main'], | ||
| capture_output=True, text=True, timeout=5, cwd=cwd, | ||
| ).stdout.strip() | ||
| if not local or not remote: | ||
| return jsonify(_safe) | ||
| if local == remote: | ||
| result: Dict[str, Any] = {'update_available': False, 'remote_sha': remote, 'commits_behind': 0} | ||
| else: | ||
| count_str = subprocess.run( | ||
| ['git', 'rev-list', 'HEAD..origin/main', '--count'], | ||
| capture_output=True, text=True, timeout=5, cwd=cwd, | ||
| ).stdout.strip() | ||
| count = int(count_str) if count_str.isdigit() else 0 | ||
| result = {'update_available': count > 0, 'remote_sha': remote, 'commits_behind': count} | ||
| _update_check_cache['result'] = result | ||
| _update_check_cache['ts'] = now | ||
| return jsonify(result) | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| except Exception as e: | ||
| logger.warning("check-update failed: %s", e) | ||
| return jsonify(_safe) | ||
| @api_v3.route('/system/action', methods=['POST']) | ||
| def execute_system_action(): | ||
| """Execute system actions (start/stop/reboot/etc)""" | ||
| @@ -2433,6 +2489,28 @@ def reconcile_plugin_state(): | ||
| status_code=500 | ||
| ) | ||
| @api_v3.route('/plugins/reconciliation-status', methods=['GET']) | ||
| def get_reconciliation_status(): | ||
| """Return the result of the last startup reconciliation from /tmp status file.""" | ||
| _recon_path = os.path.join(tempfile.gettempdir(), "ledmatrix_reconciliation.json") | ||
| try: | ||
| st = os.lstat(_recon_path) | ||
| except FileNotFoundError: | ||
| return jsonify({'status': 'success', 'data': {'done': False, 'unresolved': []}}) | ||
| if stat.S_ISLNK(st.st_mode) or not stat.S_ISREG(st.st_mode): | ||
| logger.warning("[Reconciliation] Status file is not a regular file: %s", _recon_path) | ||
| return jsonify({'status': 'success', 'data': {'done': False, 'unresolved': []}}) | ||
| try: | ||
| with open(_recon_path) as _f: | ||
| data = json.load(_f) | ||
| return jsonify({'status': 'success', 'data': data}) | ||
| except json.JSONDecodeError: | ||
| logger.exception("[Reconciliation] Failed to parse status file: %s", _recon_path) | ||
| return jsonify({'status': 'success', 'data': {'done': False, 'unresolved': []}}) | ||
| except PermissionError: | ||
| logger.exception("[Reconciliation] Permission denied reading status file: %s", _recon_path) | ||
| return jsonify({'status': 'success', 'data': {'done': False, 'unresolved': []}}) | ||
| @api_v3.route('/plugins/config', methods=['GET']) | ||
| def get_plugin_config(): | ||
| """Get plugin configuration""" | ||
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
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
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.