-
-
Notifications
You must be signed in to change notification settings - Fork 546
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
6
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.
Open
Changes from 2 commits
Commits
Show all changes
6 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 47ac868
Restore README.md (remove update checker documentation)
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,97 @@ | ||
| 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: | ||
| logger.warning("UPDATE_CHECK_URL not configured") | ||
| return None | ||
|
|
||
| try: | ||
| resp = requests.get( | ||
| update_url, | ||
| headers={"User-Agent": "IntelOwl-Update-Checker"}, | ||
| timeout=5, | ||
| ) | ||
| resp.raise_for_status() | ||
|
|
||
| data = resp.json() | ||
| tag = data.get("tag_name") | ||
| if not tag: | ||
| logger.warning("release response missing tag_name") | ||
| return None | ||
|
|
||
| # remove optional 'v' prefix | ||
| return tag.lstrip("v") | ||
|
|
||
| except requests.RequestException as exc: | ||
| logger.error(f"update check failed: {exc}") | ||
| return None | ||
| except ValueError: | ||
| logger.error("invalid JSON in update response") | ||
| return None | ||
fgibertoni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def check_for_update(): | ||
| """ | ||
| Compare the running IntelOwl version with the latest available one | ||
| and log a warning if a newer version exists. | ||
| """ | ||
| current_version_str = getattr(settings, "INTEL_OWL_VERSION", None) | ||
| latest_str = fetch_latest_version() | ||
|
|
||
| if not current_version_str: | ||
| logger.warning("INTEL_OWL_VERSION setting missing") | ||
| return | ||
|
|
||
| if not latest_str: | ||
| return # fetch logged any errors | ||
|
|
||
| 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: | ||
| # fallback string compare if parsing failed | ||
| if latest_str != current_version_str: | ||
| logger.warning( | ||
| f"Update available: {latest_str} " | ||
| f"(current: {current_version_str})" | ||
| ) | ||
| return | ||
|
|
||
| if latest > current: | ||
| logger.warning( | ||
| f"New IntelOwl version available: {latest_str} " | ||
| f"(current: {current_version_str})" | ||
| ) | ||
| elif latest < current: | ||
| logger.info( | ||
| f"Local version ahead of release: " | ||
| f"{current_version_str} > {latest_str}" | ||
| ) | ||
| else: | ||
| logger.info(f"IntelOwl version up to date ({current_version_str})") | ||
fgibertoni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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,9 @@ | ||
| 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): | ||
| check_for_update() | ||
| self.stdout.write(self.style.SUCCESS("Update check completed")) | ||
fgibertoni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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
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.
Thanks for highlighting this
I’ve restored the README to its original state. I’ll add the Update Checker documentation under the Installation section in the docs repository (as suggested) via a separate PR.