Eng 12002 cli push time metadata flags#290
Closed
BartoszBlizniak wants to merge 14 commits into
Closed
Conversation
…ng-12001-cli-standalone-metadata-command-group
…sent locally)
Member
Author
|
Gonan take this apart |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds “push-time” metadata attachment to cloudsmith push <format> so SBOM/BuildInfo/generic JSON can be validated and attached in the same command (with shared helpers extracted for reuse).
Changes:
- Add
--metadata-*flags to all push subcommands, with local JSON-object validation, server-side pre-validation, and post-create attachment (with configurable warn vs error behavior). - Refactor shared metadata option/content handling into
cli/metadata_common.py, and updatecloudsmith metadata add/updateto use the shared logic (including JSON-object enforcement). - Expand test coverage for push-time metadata flows and help-text examples; modernize typing annotations across several modules and update pre-commit
pyupgrade.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
cloudsmith_cli/core/pagination.py |
Modernize typing annotations (builtin generics / PEP 604). |
cloudsmith_cli/core/mcp/server.py |
Modernize typing annotations for MCP server helpers. |
cloudsmith_cli/core/mcp/data.py |
Update dataclass typing to builtin generics / PEP 604. |
cloudsmith_cli/core/download.py |
Modernize typing annotations for download helpers. |
cloudsmith_cli/core/api/metadata.py |
Modernize typing annotations for metadata API wrapper functions. |
cloudsmith_cli/core/api/init.py |
Modernize typing annotations (type[T]). |
cloudsmith_cli/cli/commands/push.py |
Implement push-time metadata flag resolution, pre-validation, attachment, retry hints, and JSON surfacing. |
cloudsmith_cli/cli/metadata_common.py |
New shared helpers for resolving/validating metadata content and defaults. |
cloudsmith_cli/cli/commands/metadata.py |
Refactor metadata add/update to use shared resolution logic + enforce JSON-object payloads. |
cloudsmith_cli/cli/exceptions.py |
Include push-time metadata context in JSON error envelopes. |
cloudsmith_cli/cli/tests/test_push.py |
Add comprehensive tests for push-time metadata behavior, warn/error modes, and JSON envelopes/hints. |
cloudsmith_cli/cli/tests/test_metadata_common.py |
New tests for shared metadata resolution/helpers. |
cloudsmith_cli/cli/tests/commands/test_metadata.py |
Update help-text expectations + add tests for rejecting non-object content. |
cloudsmith_cli/cli/saml.py |
Minor string formatting cleanup. |
cloudsmith_cli/cli/commands/mcp.py |
Modernize typing annotations for MCP CLI printing helpers. |
.pre-commit-config.yaml |
Update pyupgrade hook version and enforce --py310-plus. |
.github/.platforms/generate_platforms.py |
Modernize typing import (Callable from collections.abc). |
Comments suppressed due to low confidence (1)
cloudsmith_cli/cli/metadata_common.py:170
validate_metadata_payload_api()appears unused (no references in the codebase). If it’s not intended for near-term use, consider removing it (and the correspondingapi_validate_metadata/exception-handling imports) to avoid dead code; otherwise, update callers to use it so validation behavior stays centralized.
def validate_metadata_payload_api(
*,
ctx,
opts,
content: dict[str, Any],
content_type: str,
context_msg: str,
reraise_on_error: bool = False,
) -> None:
"""Validate metadata content through the metadata validation endpoint."""
with handle_api_exceptions(
ctx,
opts=opts,
context_msg=context_msg,
reraise_on_error=reraise_on_error,
):
with maybe_spinner(opts):
api_validate_metadata(content=content, content_type=content_type)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+117
to
+123
| if not metadata_provided: | ||
| if metadata_content_type or metadata_source_identity: | ||
| raise click.UsageError( | ||
| "Add --metadata-content-file or --metadata-content when using " | ||
| "--metadata-content-type or --metadata-source-identity." | ||
| ) | ||
| return ResolvedMetadata(provided=False, content=None), None |
| # N times) is almost never what the user wants. Force them to | ||
| # push files individually with metadata, or drop the flags. | ||
| metadata_flags_set = any( | ||
| metadata_kwargs.get(k) for k in METADATA_KWARG_NAMES |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Adds push-time metadata flags to
cloudsmith push <format>so SBOM / BuildInfo / generic JSON can be attached in a single command instead of a separatecloudsmith metadata addfollow-up.New flags on every push subcommand:
--metadata-content-file PATH(or-for stdin)--metadata-content JSON--metadata-content-type MIME--metadata-source-identity TEXTFlow:
POST /v2/metadata/validate/before any S3 upload — malformed metadata can no longer leave orphan packages.create_package, attach metadata viaPOST /v2/metadata/.CLOUDSMITH_METADATA_FAILURE_MODE=warn(or0) to downgrade to a warning + copy-paste retry hint.metadata_attachmentin JSON output (success and error envelopes).Also extracts shared metadata helpers into
cli/metadata_common.pyso the standalonecloudsmith metadata add/updatepaths and the new push path share content resolution / JSON-object enforcement / default sourceidentity.
Ships
examples/metadata_demo/with copy-paste-ready CRUD + push commands, sample payload, valid CycloneDX / BuildInfo, and a broken BuildInfo for exercising the failure paths.Type of Change
metadata_common.py)Additional Notes
$CLOUDSMITH_METADATA_FAILURE_MODE=warn.Examples:
Push:
Push with invalid metadata:
Push with invalid metadata and
$CLOUDSMITH_METADATA_FAILURE_MODEset towarn: