microcks-cli icon indicating copy to clipboard operation
microcks-cli copied to clipboard

fix: clean up auth when deleting named contexts

Open cotishq opened this issue 6 months ago • 1 comments

Description

  • Fixes named context deletion so cleanup uses the removed context's referenced user and server values instead of the context name.
  • Removes the associated auth entry when deleting a context, matching the expected cleanup behavior for credentials tied to that server.
  • Adds a regression test covering context --delete for a named context where contexts[].name differs from contexts[].user.

Screenshot

Screenshot From 2026-05-25 12-04-04

Related issue(s)

Fixes #427

cotishq avatar May 25 '26 06:05 cotishq

hey @Harsh4902 , would love your feedback here

cotishq avatar May 29 '26 15:05 cotishq

@cotishq Please resolve the conflicts.

Vaishnav88sk avatar Jul 16 '26 12:07 Vaishnav88sk

The current delete path uses the context name for user cleanup, which is wrong for named contexts where contexts[].name != contexts[].user. Cleaning up by the removed ContextRef is the right direction, and adding auth cleanup for the associated server also makes sense.

One thing to double-check before merge: are server, user, or auth entries ever intentionally shared by multiple contexts? If yes, deleting them unconditionally here could remove credentials/config still referenced by another context. If they are always 1:1 with a context, then this is fine.

If shared references are not a supported case, LGTM. @Harsh4902

Vaishnav88sk avatar Jul 16 '26 12:07 Vaishnav88sk

yeah you are right, since microcks login supports the --name flag, users can define multiple named contexts pointing to the same server or user. so if one is deleted, deleting the server, user or auth config unconditionally would indeed break the remaining contexts that reference them.

i think we should check if any other contexts still reference the removed contexts user or server before deleting them.

what's your opinion should i update the PR to add references checking ?

cotishq avatar Jul 16 '26 18:07 cotishq

yeah you are right, since microcks login supports the --name flag, users can define multiple named contexts pointing to the same server or user. so if one is deleted, deleting the server, user or auth config unconditionally would indeed break the remaining contexts that reference them.

i think we should check if any other contexts still reference the removed contexts user or server before deleting them.

what's your opinion should i update the PR to add references checking ?

Yes, please update the PR with reference checks.

Because multiple named contexts can share the same server / user / auth, we should only remove those entries if the deleted context was the last one referencing them.

Please add tests for both shared-reference and last-reference cases as well. Then I’ll re-review.

Vaishnav88sk avatar Jul 23 '26 08:07 Vaishnav88sk