-
Notifications
You must be signed in to change notification settings - Fork 37
Add --tag option to download command #249
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
base: master
Are you sure you want to change the base?
Changes from all commits
10396c5
d387674
f06ea01
831ac02
628c873
90cf467
7daa3bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,50 @@ def resolve_auth( | |
| return session, headers, auth_source | ||
|
|
||
|
|
||
| def _matches_tag_filter(pkg: Dict, tag_filter: str) -> bool: | ||
| """ | ||
| Check if a package matches the tag filter. | ||
|
|
||
| Args: | ||
| pkg: Package dictionary | ||
| tag_filter: Tag to match against | ||
|
|
||
| Returns: | ||
| True if package matches the tag filter | ||
| """ | ||
| # Check actual tags field (info, version, etc.) | ||
| pkg_tags = pkg.get("tags", {}) | ||
| for tag_category in pkg_tags.values(): | ||
| if isinstance(tag_category, list) and tag_filter in tag_category: | ||
| return True | ||
|
|
||
| # Check other metadata fields that appear as tags in the UI (case-sensitive) | ||
| # Check format, architectures, and deb component | ||
| if ( | ||
| pkg.get("format") == tag_filter | ||
| or any(arch.get("name") == tag_filter for arch in pkg.get("architectures", [])) | ||
| or pkg.get("identifiers", {}).get("deb_component") == tag_filter | ||
| ): | ||
| return True | ||
|
|
||
| # Check distro-related fields | ||
| distro_name_raw = pkg.get("distro", {}).get("name") | ||
| distro_version_raw = pkg.get("distro_version", {}).get("name") | ||
| distro_combo = "" | ||
| if distro_name_raw and distro_version_raw: | ||
| # Only build combined tag when both parts are present | ||
| distro_combo = f"{distro_name_raw}/{distro_version_raw}" | ||
|
|
||
| if ( | ||
| tag_filter == distro_name_raw | ||
| or tag_filter == distro_version_raw | ||
| or (distro_combo and tag_filter == distro_combo) | ||
| ): | ||
| return True | ||
|
Comment on lines
+75
to
+95
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Any reason why this is also checking format, arch and distro-related things for what's only supposed to be a tag filter? Why should the user use this instead of the other existing flags for these use cases?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great question! The reason I included format, arch, and distro fields in the tag filter is that Cloudsmith UI presents all of these as “tags” on the package details page. I wanted the I agree it might be clearer and more consistent to have |
||
|
|
||
| return False | ||
|
|
||
|
|
||
| def resolve_package( | ||
| owner: str, | ||
| repo: str, | ||
|
|
@@ -62,6 +106,7 @@ def resolve_package( | |
| format_filter: Optional[str] = None, | ||
| os_filter: Optional[str] = None, | ||
| arch_filter: Optional[str] = None, | ||
| tag_filter: Optional[str] = None, | ||
| yes: bool = False, | ||
| ) -> Dict: | ||
| """ | ||
|
|
@@ -75,6 +120,7 @@ def resolve_package( | |
| format_filter: Optional format filter | ||
| os_filter: Optional OS filter | ||
| arch_filter: Optional architecture filter | ||
| tag_filter: Optional tag filter | ||
| yes: If True, automatically select best match when multiple found | ||
|
|
||
| Returns: | ||
|
|
@@ -125,6 +171,9 @@ def resolve_package( | |
| # Apply architecture filter | ||
| if arch_filter and pkg.get("architecture") != arch_filter: | ||
| continue | ||
| # Apply tag filter | ||
| if tag_filter and not _matches_tag_filter(pkg, tag_filter): | ||
| continue | ||
| filtered_packages.append(pkg) | ||
| packages = filtered_packages | ||
|
|
||
|
|
||
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.
Might be worthwhile double-checking if Cloudsmith Tags are actually case-sensitive in the API
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.
They are. Just retested by adding some and the API returned:
"tags": { "info": [ "RANJAN", "RanJan", "Ranjan", "trivy", "upstream" ] }