Skip to content

NMV-1073: S1 — Migrate Python SDK's update_secrets_collection onto the partial-update endpoint - #375

Merged
racquesta merged 4 commits into
developfrom
feature/NMV-1073/s1-migrate-python-sdks-update-secrets-collection
Oct 19, 2026
Merged

racquesta merged 4 commits into
developfrom
feature/NMV-1073/s1-migrate-python-sdks-update-secrets-collection

Conversation

@racquesta

@racquesta racquesta commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • update_secrets_collection() used to GET the collection and PUT it back. Metadata-only calls therefore resent the fetched secrets. Once masking (W2) ships, that would overwrite every real secret value with "***************".
  • update_secrets_collection() now goes through the new PATCH /v1/applications/{app_id}/secrets/{collection_id} endpoint (C2). Previously fetched values are never sent back.
  • Adds an opt-in keep_existing argument (SDK) and --keep-existing / -k flag (CLI) to add or update secrets without deleting the ones not provided.
  • Backwards compatible: existing calls keep working with the same full-replace meaning for secrets=. The new argument and flag default to off. See Behavior changes below for the edge cases that differ.
  • Design: Hide Secret Values from the Front-End (see "Rollout Sequencing")

Changes

  • SDK update_secrets_collection(): PUT is removed.
    • Metadata-only calls (name and/or description) send a single PATCH with no operations, and no GET first. The collection's secrets are left untouched.
    • secrets= still replaces everything by default. The SDK reads the existing secret keys only (type and location; values are ignored), then sends one PATCH that updates matching secrets, creates new ones and deletes the rest.
    • New keep_existing: bool = False keyword argument. When True, the delete operations are skipped, so existing secrets that aren't provided are kept. It has no effect without secrets.
    • Raises ValueError before any request if there is nothing to update, or if a secret is not a Secret or dict.
    • Docstring updated to describe this, and the examples now use the correct Secret(secret_type=..., location=..., value=...) fields.
  • CLI nextmv cloud secrets update: new --keep-existing / -k flag passed through to the SDK. It errors if used without --secrets. Help text and examples updated.
  • MCP: no code changes. It calls the SDK method, so it gets the PATCH behavior automatically. It doesn't expose keep_existing.

Behavior changes

None of these change the documented contract, but SDK users may notice them:

  • Calling with nothing to update now raises ValueError. update_secrets_collection("id") with no name, description or secrets used to PUT the collection back unchanged. The CLI already rejected this case.
  • secrets=[] is now treated the same as secrets=None. It's a name/description-only update that leaves secrets untouched. Before, it re-sent the fetched secrets, which would write masked values back once W2 ships.
  • Metadata-only updates no longer send secrets at all. This is the main fix.
  • Dict secrets are now validated client-side through Secret.from_dict, so a malformed dict fails before any request instead of at the server.

Test plan

  • uv run ruff check .: passes
  • uv run pytest --ignore=tests/integration: 829 passed
  • New tests/cloud/test_secrets.py:
    • metadata-only updates (including secrets=[]) send a PATCH with no operations and no GET
    • calling with nothing to update raises without any request
    • a full replace becomes the right update/create/delete operations, with no masked value in the payload
    • keep_existing=True sends only update/create operations, with no deletes
    • PUT is never used
    • an invalid secret raises before any request

Notes

  • Merge gate: this depends on C2. The PATCH endpoint must be live in core (on every environment the SDK targets) before this is released. Against an environment without it, update_secrets_collection() will fail.
  • Old SDK versions: this only protects people who upgrade. Older SDK/CLI versions still do the fetch-then-PUT round trip, the PUT, CREATE, and PATCH endpoints in the UI return error messaging on submission of masked values to protect against unexpected overwrites.
  • Changelog: suggest listing the keep_existing / --keep-existing addition and the behavior changes above in the release notes.
  • Small race on full replace: a secret added by someone else between the key read and the PATCH survives instead of being deleted. Nothing is lost or overwritten by it.

Screenshots

N/A — no UI changes in this PR.

🤖 Generated with Claude Code

racquesta and others added 3 commits October 12, 2026 19:34
…pdate endpoint [NMV-1073]

Remove PUT from update_secrets_collection: metadata-only updates and
full replacements both go through PATCH, so previously fetched
(soon-to-be-masked) secret values are never resent. Full replacements
are expressed as create/update/delete operations against the keys of
the existing secrets.

Add patch_secrets_collection and SecretOperation wrapping the new
PATCH endpoint, --create/--update/--delete on
`nextmv cloud secrets update`, and the cloud_update_secrets_collection
MCP tool.

Co-Authored-By: Claude (claude-opus-5-5[1m]) <noreply@anthropic.com>
…NMV-1073]

Drop the explicit create/update/delete operations surface so that
updating a secrets collection behaves exactly as before:

- Remove --create/--update/--delete from `nextmv cloud secrets update`.
- Remove the cloud_update_secrets_collection MCP tool.
- Remove patch_secrets_collection, SecretOperation, and
  SecretOperationType from the public SDK.

update_secrets_collection still goes through the PATCH endpoint so
masked values are never resent: metadata-only updates send no secrets,
and --secrets replaces the whole collection, with the operations
derived internally from the keys returned by GET.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…1073]

Add a keep_existing option to update_secrets_collection and a
--keep-existing flag to `nextmv cloud secrets update`. When set, the
provided secrets are upserted (updated if they exist, created otherwise)
and existing secrets that are not provided are kept instead of deleted.
The default remains a full replace.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@racquesta
racquesta marked this pull request as ready for review October 19, 2026 11:38

@merschformann merschformann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Kevin had a side-note that might be worth considering. But otherwise, happy to quick approve. ☺️

Note

Kevin's review.

✅ LGTM — clean migration to PATCH: fetched values are never sent back, metadata-only updates skip the GET, and the keep_existing behaviour matches the description. Ruff passes and pytest --ignore=tests/integration passes locally (829). The C2 merge gate in the description is the real release dependency.

  • 🟡 1 minor inline — non-blocking, fine to skip or do later

🤖 Kevin (PR review bot)

# masked, are never sent back to the server.
collection = self.secrets_collection(secrets_collection_id)
existing_keys = {(secret.secret_type, secret.location) for secret in collection.secrets}
new_keys = {(secret.secret_type, secret.location) for secret in new_secrets}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · non-blocking

If the caller passes the same (type, location) twice (e.g. a copy-paste in --secrets '[...]'), this emits two update/create ops for the same key. With the old PUT the server just got the list. Now the result depends on how C2 handles duplicate ops in one PATCH: an error, last-one-wins, or a partially applied request if it isn't atomic. A cheap client-side check would make this deterministic, e.g. raising ValueError("duplicate secret ...") when len(new_keys) != len(new_secrets), before the GET. Non-blocking: fine to skip if C2 already rejects duplicates atomically.

🤖 Kevin (PR review bot)

…NMV-1073]

Each secret becomes its own PATCH operation, so passing the same
(type, location) twice would rely on how the server handles several
operations on the same key. Raise ValueError before any request instead.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@merschformann merschformann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@racquesta
racquesta merged commit d8f4f05 into develop Oct 19, 2026
57 checks passed
@racquesta
racquesta deleted the feature/NMV-1073/s1-migrate-python-sdks-update-secrets-collection branch October 19, 2026 13:10
@racquesta racquesta mentioned this pull request Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants