Repository navigation
NMV-1073: S1 — Migrate Python SDK's update_secrets_collection onto the partial-update endpoint - #375
Conversation
…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>
merschformann
left a comment
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
🟡 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>
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 newPATCH /v1/applications/{app_id}/secrets/{collection_id}endpoint (C2). Previously fetched values are never sent back.keep_existingargument (SDK) and--keep-existing/-kflag (CLI) to add or update secrets without deleting the ones not provided.secrets=. The new argument and flag default to off. See Behavior changes below for the edge cases that differ.Changes
update_secrets_collection(): PUT is removed.nameand/ordescription) send a single PATCH with nooperations, 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.keep_existing: bool = Falsekeyword argument. WhenTrue, the delete operations are skipped, so existing secrets that aren't provided are kept. It has no effect withoutsecrets.ValueErrorbefore any request if there is nothing to update, or if a secret is not aSecretor dict.Secret(secret_type=..., location=..., value=...)fields.nextmv cloud secrets update: new--keep-existing/-kflag passed through to the SDK. It errors if used without--secrets. Help text and examples updated.keep_existing.Behavior changes
None of these change the documented contract, but SDK users may notice them:
ValueError.update_secrets_collection("id")with noname,descriptionorsecretsused to PUT the collection back unchanged. The CLI already rejected this case.secrets=[]is now treated the same assecrets=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.Secret.from_dict, so a malformed dict fails before any request instead of at the server.Test plan
uv run ruff check .: passesuv run pytest --ignore=tests/integration: 829 passedtests/cloud/test_secrets.py:secrets=[]) send a PATCH with nooperationsand no GETkeep_existing=Truesends only update/create operations, with no deletesNotes
update_secrets_collection()will fail.keep_existing/--keep-existingaddition and the behavior changes above in the release notes.Screenshots
N/A — no UI changes in this PR.
🤖 Generated with Claude Code