-
-
Notifications
You must be signed in to change notification settings - Fork 547
Add update checker management command and documentation #3127
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
Open
lvb05
wants to merge
5
commits into
intelowlproject:develop
Choose a base branch
from
lvb05:feature/update-checker-2876
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+140
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
987765d
Merge pull request #2849 from intelowlproject/develop
drosetti 067ab3a
Add update checker management command, settings, and docs
lvb05 618f293
Format update checker with black and branch update
lvb05 eef5c15
Fix linting issues and improve update checker command output
lvb05 7c59a39
Fix ruff linting issues
lvb05 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
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,98 @@ | ||
| import logging | ||
|
|
||
| import requests | ||
| from django.conf import settings | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def normalize_version(v): | ||
| """ | ||
| Convert '1.2.3' → (1, 2, 3) so versions can be compared. | ||
| Stops at the first non-numeric part. | ||
| """ | ||
| parts = [] | ||
| for x in v.split("."): | ||
| if x.isdigit(): | ||
| parts.append(int(x)) | ||
| else: | ||
| break | ||
| return tuple(parts) | ||
|
|
||
|
|
||
| def fetch_latest_version(): | ||
| """ | ||
| Fetch the latest IntelOwl version string from the update URL. | ||
| Returns a version string without any leading 'v', or None on error. | ||
| """ | ||
| update_url = getattr(settings, "UPDATE_CHECK_URL", None) | ||
|
|
||
| if not update_url: | ||
| return None, "UPDATE_CHECK_URL not configured" | ||
|
|
||
| try: | ||
| resp = requests.get( | ||
| update_url, | ||
| headers={"User-Agent": "IntelOwl-Update-Checker"}, | ||
| timeout=5, | ||
| ) | ||
| resp.raise_for_status() | ||
| except requests.RequestException as exc: | ||
| logger.error(f"update check failed: {exc}") | ||
| return None, "Failed to fetch release information" | ||
|
|
||
| try: | ||
| data = resp.json() | ||
| except ValueError: | ||
| logger.error("invalid JSON in update response") | ||
| return None, "Invalid response from update server" | ||
|
|
||
| tag = data.get("tag_name") | ||
| if not tag: | ||
| return None, "Release response missing tag_name" | ||
|
|
||
| return tag.lstrip("v"), None | ||
|
|
||
|
|
||
| def check_for_update(): | ||
| """ | ||
| Compare the running IntelOwl version with the latest available one. | ||
|
|
||
| Returns: | ||
| (success: bool, message: str) | ||
| """ | ||
| current_version_str = getattr(settings, "INTEL_OWL_VERSION", None) | ||
| if not current_version_str: | ||
| return False, "INTEL_OWL_VERSION setting missing" | ||
|
|
||
| latest_str, error = fetch_latest_version() | ||
| if error: | ||
| return False, error | ||
|
|
||
| current_version_str = str(current_version_str).lstrip("v") | ||
|
|
||
| current = normalize_version(current_version_str) | ||
| latest = normalize_version(latest_str) | ||
|
|
||
| if not current or not latest: | ||
| if latest_str != current_version_str: | ||
| return ( | ||
| True, | ||
| f"Update available: {latest_str} (current: {current_version_str})", | ||
| ) | ||
| return True, f"IntelOwl version up to date ({current_version_str})" | ||
|
|
||
| if latest > current: | ||
| return ( | ||
| True, | ||
| f"New IntelOwl version available: {latest_str} " | ||
| f"(current: {current_version_str})", | ||
| ) | ||
|
|
||
| if latest < current: | ||
| return ( | ||
| True, | ||
| f"Local version ahead of release: " f"{current_version_str} > {latest_str}", | ||
| ) | ||
|
|
||
| return True, f"IntelOwl version up to date ({current_version_str})" |
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,15 @@ | ||
| from django.core.management.base import BaseCommand | ||
|
|
||
| from api_app.core.update_checker import check_for_update | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| help = "Check for newer IntelOwl releases" | ||
|
|
||
| def handle(self, *args, **options): | ||
| success, message = check_for_update() | ||
|
|
||
| if success: | ||
| self.stdout.write(self.style.SUCCESS(message)) | ||
| else: | ||
| self.stdout.write(self.style.ERROR(message)) |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we cannot pollute the ReadMe with this content. Please remove this line and add this instead with a new PR in the Installation section: https://github.com/intelowlproject/docs/blob/main/docs/IntelOwl/installation.md