zen-cli 0.1.20__tar.gz → 0.1.22__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of zen-cli might be problematic. Click here for more details.

Files changed (232) hide show
  1. {zen_cli-0.1.20 → zen_cli-0.1.22}/CHANGELOG.md +12 -0
  2. {zen_cli-0.1.20 → zen_cli-0.1.22}/PKG-INFO +2 -1
  3. {zen_cli-0.1.20 → zen_cli-0.1.22}/pyproject.toml +4 -1
  4. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/auth/login.py +2 -1
  5. zen_cli-0.1.22/src/zen_cli/cmds/auth/logout.py +18 -0
  6. zen_cli-0.1.22/src/zen_cli/cmds/profile/lock.py +22 -0
  7. zen_cli-0.1.22/src/zen_cli/cmds/profile/unlock.py +24 -0
  8. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/built_in_cmds/profile.py +9 -3
  9. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/profile.py +141 -11
  10. zen_cli-0.1.22/src/zen_cli/ctxp/secret_store.py +279 -0
  11. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/support/login_support.py +2 -2
  12. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/sglib/auth.py +4 -4
  13. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/sglib/csp.py +1 -1
  14. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/sglib/ez_client.py +2 -2
  15. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/util/versions.py +1 -1
  16. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/test_auth_status.py +20 -0
  17. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/test_cli.py +3 -0
  18. zen_cli-0.1.22/tests/test_dev_release.py +103 -0
  19. zen_cli-0.1.22/tests/test_profile_keyring.py +250 -0
  20. zen_cli-0.1.20/src/zen_cli/cmds/auth/logout.py +0 -9
  21. zen_cli-0.1.20/tests/test_dev_release.py +0 -56
  22. {zen_cli-0.1.20 → zen_cli-0.1.22}/.gitignore +0 -0
  23. {zen_cli-0.1.20 → zen_cli-0.1.22}/LICENSE +0 -0
  24. {zen_cli-0.1.20 → zen_cli-0.1.22}/README.md +0 -0
  25. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/__init__.py +0 -0
  26. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/__main__.py +0 -0
  27. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cli.py +0 -0
  28. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/auth/__init__.py +0 -0
  29. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/auth/details.py +0 -0
  30. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/auth/refresh.py +0 -0
  31. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/auth/status.py +0 -0
  32. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/auth/token.py +0 -0
  33. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/completion.py +0 -0
  34. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/__init__.py +0 -0
  35. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/activity/__init__.py +0 -0
  36. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/activity/get.py +0 -0
  37. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/activity/list.py +0 -0
  38. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/activity/use.py +0 -0
  39. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/api.py +0 -0
  40. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/credential/__init__.py +0 -0
  41. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/credential/create.py +0 -0
  42. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/credential/delete.py +0 -0
  43. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/credential/get.py +0 -0
  44. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/credential/list.py +0 -0
  45. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/credential/use.py +0 -0
  46. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/deployment/__init__.py +0 -0
  47. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/deployment/create.py +0 -0
  48. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/deployment/delete.py +0 -0
  49. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/deployment/get.py +0 -0
  50. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/deployment/list.py +0 -0
  51. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/deployment/use.py +0 -0
  52. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/entitlement/__init__.py +0 -0
  53. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/entitlement/create.py +0 -0
  54. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/entitlement/delete.py +0 -0
  55. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/entitlement/get.py +0 -0
  56. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/entitlement/list.py +0 -0
  57. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/entitlement/use.py +0 -0
  58. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/group/__init__.py +0 -0
  59. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/group/create.py +0 -0
  60. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/group/delete.py +0 -0
  61. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/group/get.py +0 -0
  62. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/group/list.py +0 -0
  63. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/group/use.py +0 -0
  64. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/mcp.py +0 -0
  65. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/network/__init__.py +0 -0
  66. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/network/create.py +0 -0
  67. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/network/delete.py +0 -0
  68. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/network/get.py +0 -0
  69. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/network/list.py +0 -0
  70. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/network/use.py +0 -0
  71. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/notification/__init__.py +0 -0
  72. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/notification/get.py +0 -0
  73. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/notification/list.py +0 -0
  74. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/notification/use.py +0 -0
  75. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/org/__init__.py +0 -0
  76. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/org/create.py +0 -0
  77. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/org/get.py +0 -0
  78. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/org/list.py +0 -0
  79. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/org/use.py +0 -0
  80. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/pool/__init__.py +0 -0
  81. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/pool/create.py +0 -0
  82. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/pool/delete.py +0 -0
  83. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/pool/get.py +0 -0
  84. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/pool/list.py +0 -0
  85. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/pool/use.py +0 -0
  86. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/provider/__init__.py +0 -0
  87. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/provider/create.py +0 -0
  88. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/provider/delete.py +0 -0
  89. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/provider/get.py +0 -0
  90. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/provider/list.py +0 -0
  91. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/provider/use.py +0 -0
  92. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/sag/__init__.py +0 -0
  93. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/sag/create.py +0 -0
  94. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/sag/delete.py +0 -0
  95. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/sag/get.py +0 -0
  96. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/sag/list.py +0 -0
  97. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/sag/use.py +0 -0
  98. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/task/__init__.py +0 -0
  99. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/task/cancel.py +0 -0
  100. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/task/duplicate.py +0 -0
  101. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/task/get.py +0 -0
  102. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/task/list.py +0 -0
  103. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/task/log.py +0 -0
  104. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/task/namespaces.py +0 -0
  105. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/task/use.py +0 -0
  106. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/task/wait.py +0 -0
  107. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/vm/__init__.py +0 -0
  108. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/vm/delete.py +0 -0
  109. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/vm/get.py +0 -0
  110. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/vm/list.py +0 -0
  111. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/vm/poweroff.py +0 -0
  112. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/vm/poweron.py +0 -0
  113. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/vm/restart.py +0 -0
  114. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/vm/shutdown.py +0 -0
  115. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/vm/use.py +0 -0
  116. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/daas/vm/wait.py +0 -0
  117. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/profile/__init__.py +0 -0
  118. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/profile/init.py +0 -0
  119. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/cmds/upgrade.py +0 -0
  120. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/config/default.yaml +0 -0
  121. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/config/int.yaml +0 -0
  122. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/config/prod.yaml +0 -0
  123. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/config/stg.yaml +0 -0
  124. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/__init__.py +0 -0
  125. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/_init.py +0 -0
  126. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/built_in_cmds/__init__.py +0 -0
  127. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/built_in_cmds/_ut.py +0 -0
  128. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/built_in_cmds/context.py +0 -0
  129. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/cli_options.py +0 -0
  130. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/cli_processor.py +0 -0
  131. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/config.py +0 -0
  132. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/context.py +0 -0
  133. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/data_util.py +0 -0
  134. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/file_lock.py +0 -0
  135. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/httpx_alias.py +0 -0
  136. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/logger.py +0 -0
  137. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/profile_store.py +0 -0
  138. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/recent.py +0 -0
  139. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/state.py +0 -0
  140. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/telemetry.py +0 -0
  141. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/ctxp/util.py +0 -0
  142. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/__init__.py +0 -0
  143. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/__init__.py +0 -0
  144. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/_util.py +0 -0
  145. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/resources/__init__.py +0 -0
  146. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/resources/activity.py +0 -0
  147. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/resources/api.py +0 -0
  148. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/resources/credential.py +0 -0
  149. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/resources/deployment.py +0 -0
  150. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/resources/entitlement.py +0 -0
  151. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/resources/group.py +0 -0
  152. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/resources/network.py +0 -0
  153. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/resources/notification.py +0 -0
  154. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/resources/org.py +0 -0
  155. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/resources/pool.py +0 -0
  156. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/resources/provider.py +0 -0
  157. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/resources/sag.py +0 -0
  158. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/resources/task.py +0 -0
  159. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/resources/vm.py +0 -0
  160. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/mcp/server.py +0 -0
  161. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/__init__.py +0 -0
  162. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/activity.py +0 -0
  163. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/api.py +0 -0
  164. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/broker/__init__.py +0 -0
  165. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/broker/entitlement.py +0 -0
  166. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/broker/pool_group.py +0 -0
  167. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/cockpit/__init__.py +0 -0
  168. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/cockpit/network.py +0 -0
  169. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/cockpit/pool.py +0 -0
  170. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/cockpit/provider.py +0 -0
  171. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/cockpit/sag.py +0 -0
  172. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/cockpit/vm.py +0 -0
  173. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/credential.py +0 -0
  174. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/deployment.py +0 -0
  175. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/notification.py +0 -0
  176. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/org.py +0 -0
  177. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/service/task.py +0 -0
  178. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/support/activity.py +0 -0
  179. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/support/auth.py +0 -0
  180. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/support/deployment.py +0 -0
  181. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/support/network.py +0 -0
  182. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/support/notification.py +0 -0
  183. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/support/org.py +0 -0
  184. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/support/payload.py +0 -0
  185. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/support/pool.py +0 -0
  186. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/support/profile.py +0 -0
  187. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/support/recent.py +0 -0
  188. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/support/task.py +0 -0
  189. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/support/use_util.py +0 -0
  190. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/daas/support/vm.py +0 -0
  191. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/dex/.gitkeep +0 -0
  192. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/sglib/__init__.py +0 -0
  193. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/sglib/cli_options.py +0 -0
  194. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/sglib/client_util.py +0 -0
  195. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/sglib/mdc.py +0 -0
  196. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/sglib/requtil.py +0 -0
  197. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/sglib/zds_client.py +0 -0
  198. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/util/exec_util.py +0 -0
  199. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/util/exit.py +0 -0
  200. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/util/query_util.py +0 -0
  201. {zen_cli-0.1.20 → zen_cli-0.1.22}/src/zen_cli/util/readonly.py +0 -0
  202. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/__init__.py +0 -0
  203. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/__init__.py +0 -0
  204. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/cli_test.py +0 -0
  205. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/conftest.py +0 -0
  206. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/test_api.py +0 -0
  207. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/test_auth.py +0 -0
  208. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/test_completion.py +0 -0
  209. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/test_context.py +0 -0
  210. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/test_errors.py +0 -0
  211. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/test_help.py +0 -0
  212. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/test_io.py +0 -0
  213. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/test_login.py +0 -0
  214. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/test_logout.py +0 -0
  215. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/test_org.py +0 -0
  216. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/test_pool.py +0 -0
  217. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/test_profile.py +0 -0
  218. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/test_root.py +0 -0
  219. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/blackbox/util.py +0 -0
  220. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/test_dev_bundle.py +0 -0
  221. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/test_device_login.py +0 -0
  222. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/test_error_details.py +0 -0
  223. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/test_error_object.py +0 -0
  224. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/test_import_lazy.py +0 -0
  225. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/test_leaf_help.py +0 -0
  226. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/test_mcp.py +0 -0
  227. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/test_payload.py +0 -0
  228. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/test_profile_features.py +0 -0
  229. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/test_profile_lazy.py +0 -0
  230. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/test_profile_templates.py +0 -0
  231. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/test_query_util.py +0 -0
  232. {zen_cli-0.1.20 → zen_cli-0.1.22}/tests/test_recent.py +0 -0
@@ -9,6 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.1.22] - 2026-10-12
13
+
14
+ ## [0.1.21] - 2026-10-08
15
+
16
+ ### Added
17
+
18
+ - `zen profile lock` stores profile secrets and `.auth` tokens in the OS keyring (`features.keyring`). `zen profile unlock` writes them back into the profile files. The default remains plaintext. `zen profile get --show-secret` prints resolved secrets.
19
+
20
+ ### Changed
21
+
22
+ - `./dev release --no-test` skips pytest. Lint and audit still run.
23
+
12
24
  ## [0.1.20] - 2026-10-07
13
25
 
14
26
  ### Changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: zen-cli
3
- Version: 0.1.20
3
+ Version: 0.1.22
4
4
  Summary: CLI for Zen Cloud Service. Designed for AI and Human.
5
5
  Project-URL: Homepage, https://pypi.org/project/zen-cli/
6
6
  Author: zen-cli authors
@@ -10,6 +10,7 @@ Requires-Python: >=3.14
10
10
  Requires-Dist: authlib>=1.3
11
11
  Requires-Dist: click>=8.1
12
12
  Requires-Dist: httpx2>=2
13
+ Requires-Dist: keyring>=25.7
13
14
  Requires-Dist: mcp>=2
14
15
  Requires-Dist: packaging>=23
15
16
  Requires-Dist: portalocker[win32]>=2.8
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "zen-cli"
7
- version = "0.1.20"
7
+ version = "0.1.22"
8
8
  description = "CLI for Zen Cloud Service. Designed for AI and Human."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -21,6 +21,7 @@ dependencies = [
21
21
  "python-dotenv>=1",
22
22
  "pydantic>=2",
23
23
  "portalocker[win32]>=2.8",
24
+ "keyring>=25.7",
24
25
  "PyJWT>=2.8",
25
26
  "pyyaml>=6",
26
27
  "questionary>=2",
@@ -107,6 +108,8 @@ module = [
107
108
  "yumako.*",
108
109
  "authlib",
109
110
  "authlib.*",
111
+ "keyring",
112
+ "keyring.*",
110
113
  "yaml",
111
114
  "httpx2",
112
115
  "httpx2.*",
@@ -36,7 +36,7 @@ from zen_cli.sglib.cli_options import use_org
36
36
  "--org",
37
37
  type=str,
38
38
  required=False,
39
- help="CSP organization to login.",
39
+ help="Pin CSP org for interactive login (device/browser OAuth scope and authorize query).",
40
40
  )
41
41
  @click.option("--api-token", type=str, required=False, help="Login with a user CSP API token.")
42
42
  @click.option("--client-id", type=str, required=False, help="Login with OAuth client ID/secret.")
@@ -310,6 +310,7 @@ def _do_device_login() -> Any:
310
310
  _echo(f" Organization: {org_id if org_id else '<default>'}")
311
311
  _echo(f" Profile: {ctxp.profile.name()}")
312
312
  _echo(f"Open: {url}")
313
+ _echo("On the sign-in page, use your ZITADEL login name (not your DCP portal email).")
313
314
  _echo("Waiting for authorization. Press CTRL+C to abort.")
314
315
 
315
316
  token = login_support.login_via_device_code(auth_config.url, org_id, announce=_announce)
@@ -0,0 +1,18 @@
1
+ import rich_click as click
2
+
3
+ from zen_cli.ctxp import profile
4
+
5
+
6
+ @click.command()
7
+ def logout() -> None:
8
+ """Logout the current profile."""
9
+ profile.auth.delete()
10
+ try:
11
+ current = profile.current(exit_on_failure=False)
12
+ except Exception:
13
+ current = None
14
+ if current is not None:
15
+ csp = getattr(current, "csp", None)
16
+ if csp is not None:
17
+ csp.orgId = None
18
+ profile.save()
@@ -0,0 +1,22 @@
1
+ import rich_click as click
2
+
3
+ from zen_cli.ctxp import panic, profile
4
+
5
+
6
+ @click.command()
7
+ @click.argument("name", required=False)
8
+ def lock(name: str | None) -> str:
9
+ """Store this profile's secrets in the OS keyring and set features.keyring to true.
10
+
11
+ \b
12
+ Examples:
13
+ 1. Lock the current profile:
14
+ zen profile lock
15
+ 2. Lock a named profile:
16
+ zen profile lock prod
17
+ """
18
+ chosen = name or profile.name()
19
+ if not profile.exists(chosen):
20
+ panic("No such profile: " + chosen)
21
+ profile.lock(chosen)
22
+ return f"Profile '{chosen}' locked: secrets are in the keyring."
@@ -0,0 +1,24 @@
1
+ import rich_click as click
2
+
3
+ from zen_cli.ctxp import panic, profile
4
+
5
+
6
+ @click.command()
7
+ @click.argument("name", required=False)
8
+ def unlock(name: str | None) -> str:
9
+ """Move this profile's secrets from the OS keyring back into its files.
10
+
11
+ Sets features.keyring to false.
12
+
13
+ \b
14
+ Examples:
15
+ 1. Unlock the current profile:
16
+ zen profile unlock
17
+ 2. Unlock a named profile:
18
+ zen profile unlock prod
19
+ """
20
+ chosen = name or profile.name()
21
+ if not profile.exists(chosen):
22
+ panic("No such profile: " + chosen)
23
+ profile.unlock(chosen)
24
+ return f"Profile '{chosen}' unlocked: secrets are in the profile files."
@@ -59,7 +59,7 @@ def copy(from_: str | None, to: str, no_edit: bool) -> Any:
59
59
  panic("No such profile: " + from_)
60
60
  if profile.exists(to):
61
61
  panic("Profile already exists: " + to)
62
- data = profile.create(to, data, True)
62
+ data = profile.create(to, profile.reveal_all(data, missing="keep"), True)
63
63
 
64
64
  if no_edit:
65
65
  return data
@@ -69,7 +69,13 @@ def copy(from_: str | None, to: str, no_edit: bool) -> Any:
69
69
 
70
70
  @profile_cmd_group.command()
71
71
  @click.argument("name", required=False)
72
- def get(name: str | None) -> Any:
72
+ @click.option(
73
+ "--show-secret",
74
+ is_flag=True,
75
+ default=False,
76
+ help="Resolve keyring references and print the real secrets.",
77
+ )
78
+ def get(name: str | None, show_secret: bool) -> Any:
73
79
  """Get content of a specific profile."""
74
80
  data: Any
75
81
  if name:
@@ -87,7 +93,7 @@ def get(name: str | None) -> Any:
87
93
  "'zen profile user <name>' to switch to a profile, or 'zen profile init' to create one."
88
94
  )
89
95
 
90
- return data
96
+ return profile.reveal_all(data) if show_secret else data
91
97
 
92
98
 
93
99
  @profile_cmd_group.command()
@@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Any
7
7
  from yumako import env
8
8
  from yumako.jsondot import DotDict, dotify
9
9
 
10
- from . import state
10
+ from . import secret_store, state
11
11
  from .data_util import load_data_file, save_data_file
12
12
  from .util import CtxpException, panic
13
13
 
@@ -18,6 +18,7 @@ _repo_path: str | None = None
18
18
  _active_profile_name: str | None = None
19
19
  _data: DotDict | None = None
20
20
  _auth_cache: dict[str, Any] | None = None
21
+ _secrets: dict[str, str] = {} # keyring reference -> secret, this process only. _data keeps the references.
21
22
  _ensure_hook: Callable[[], None] | None = None
22
23
  _on_use_hook: Callable[[], None] | None = None
23
24
  _on_use_running = False
@@ -87,14 +88,118 @@ def path(profile_name: str | None = None) -> str:
87
88
  return os.path.join(_repo(), profile_name)
88
89
 
89
90
 
91
+ def _scope(profile_name: str, file_name: str = "profile.yml") -> str:
92
+ """Keyring namespace of one profile file: <profile>/<file>."""
93
+ return f"{profile_name}/{file_name}"
94
+
95
+
96
+ def _keyring_on(data: Any) -> bool:
97
+ """features.keyring of the document being read or written. Default false."""
98
+ features = data.get("features") if hasattr(data, "get") else None
99
+ value = features.get("keyring") if features is not None and hasattr(features, "get") else None
100
+ return _as_bool(value, False)
101
+
102
+
103
+ def _save_private(data: dict[str, Any], file_name: str) -> None:
104
+ pathlib.Path(os.path.dirname(file_name)).mkdir(parents=True, exist_ok=True)
105
+ save_data_file(data, file_name, "yaml", 0o600)
106
+
107
+
108
+ def _drop_auth_cache(profile_name: str) -> None:
109
+ """A new secret sits behind the same reference: cached tokens must not be reused."""
110
+ file_name = os.path.join(path(profile_name), ".auth")
111
+ secret_store.delete(file_name, _scope(profile_name, ".auth"))
112
+ if os.path.exists(file_name):
113
+ os.unlink(file_name)
114
+ global _auth_cache
115
+ if profile_name == name():
116
+ _auth_cache = None
117
+
118
+
119
+ def _write_profile(profile_name: str, data: dict[str, Any], keyring: bool) -> None:
120
+ _secrets.clear()
121
+ secret_store.save(
122
+ data,
123
+ file(profile_name),
124
+ _scope(profile_name),
125
+ _save_private,
126
+ secret_store.PROFILE_FIELDS,
127
+ enabled=keyring,
128
+ )
129
+
130
+
131
+ def _save_profile(profile_name: str, data: dict[str, Any]) -> None:
132
+ keyring = _keyring_on(data)
133
+ if keyring and secret_store.has_plaintext(data, secret_store.PROFILE_FIELDS):
134
+ _drop_auth_cache(profile_name)
135
+ _write_profile(profile_name, data, keyring)
136
+
137
+
138
+ def _set_keyring(profile_name: str, on: bool) -> None:
139
+ """Move profile.yml and .auth secrets into the keyring, or back into the files."""
140
+ if on and not secret_store.available():
141
+ raise CtxpException("No usable keyring on this system.")
142
+ raw = load_data_file(file(profile_name), {}, "yaml")
143
+ if not isinstance(raw, dict):
144
+ raw = {}
145
+ data = secret_store.reveal(raw, secret_store.PROFILE_FIELDS, "keep")
146
+ features = dict(data.get("features") or {})
147
+ features["keyring"] = on
148
+ data["features"] = features
149
+ _write_profile(profile_name, data, on)
150
+ auth_file = os.path.join(path(profile_name), ".auth")
151
+ if os.path.exists(auth_file):
152
+ secret_store.save(
153
+ secret_store.load(auth_file),
154
+ auth_file,
155
+ _scope(profile_name, ".auth"),
156
+ _save_private,
157
+ enabled=on,
158
+ )
159
+ global _data, _auth_cache
160
+ if profile_name == name():
161
+ _data = None
162
+ _auth_cache = None
163
+
164
+
165
+ def lock(profile_name: str | None = None) -> None:
166
+ """Keep this profile's secrets in the OS keyring (sets features.keyring)."""
167
+ _set_keyring(profile_name or name(), True)
168
+
169
+
170
+ def unlock(profile_name: str | None = None) -> None:
171
+ """Bring this profile's secrets back into its files (clears features.keyring)."""
172
+ _set_keyring(profile_name or name(), False)
173
+
174
+
175
+ def reveal(value: Any) -> Any:
176
+ """Real value of a profile field. A keyring:// reference is resolved once per process."""
177
+ if not isinstance(value, str) or not value.startswith(secret_store.REF_PREFIX):
178
+ return value
179
+ if value not in _secrets:
180
+ secret = secret_store.reveal_value(value)
181
+ if not isinstance(secret, str):
182
+ return None
183
+ _secrets[value] = secret
184
+ return _secrets[value]
185
+
186
+
187
+ def reveal_fields(fields: Any) -> dict[str, Any]:
188
+ """Shallow copy with secret fields (apiToken, clientSecret, basic, ...) revealed."""
189
+ return {key: reveal(value) if key in secret_store.PROFILE_FIELDS else value for key, value in fields.items()}
190
+
191
+
192
+ def reveal_all(data: Any, missing: secret_store.Missing = "field") -> Any:
193
+ """Profile data with every secret revealed, for explicit display or copy."""
194
+ return dotify(secret_store.reveal(dict(data), secret_store.PROFILE_FIELDS, missing))
195
+
196
+
90
197
  def create(name: str, data: dict[str, Any], auto_use: bool = True, overwrite: bool = False) -> Any:
91
198
  if not overwrite and exists(name):
92
199
  if auto_use:
93
200
  use(name)
94
201
  raise CtxpException("Profile already exists: " + name)
95
- file_path = file(name)
96
- pathlib.Path(os.path.dirname(file_path)).mkdir(parents=True, exist_ok=True)
97
- save_data_file(data, file(name), "yaml", 0o600)
202
+ _save_profile(name, data)
98
203
  if auto_use:
99
204
  use(name)
100
205
  return get(name, reload=True)
@@ -106,7 +211,7 @@ def copy(from_name: str, to_name: str, overwrite: bool = True) -> None:
106
211
  data = get(from_name)
107
212
  if not data:
108
213
  raise CtxpException("Profile does not exist: " + from_name)
109
- create(to_name, deepcopy(data), auto_use=False)
214
+ create(to_name, reveal_all(data, missing="keep"), auto_use=False)
110
215
 
111
216
 
112
217
  def current(reload: bool = False, exit_on_failure: bool = True, exclude_secret: bool = False) -> Any:
@@ -142,10 +247,7 @@ def save() -> None:
142
247
 
143
248
  def write(profile_name: str, data: dict[str, Any]) -> None:
144
249
  """Save profile by name"""
145
- save_data_file(data, file(profile_name), "yaml", 0o600)
146
- global _data
147
- if _active_profile_name == profile_name:
148
- _data = None
250
+ _save_profile(profile_name, data)
149
251
 
150
252
 
151
253
  def name() -> str:
@@ -204,6 +306,9 @@ def delete(profile_name: str | None = None) -> None:
204
306
  _data = None
205
307
  _auth_cache = None
206
308
 
309
+ # Keyring entries are found through the placeholders, so remove them before the files.
310
+ secret_store.delete(file(profile_name), _scope(profile_name), secret_store.PROFILE_FIELDS)
311
+ secret_store.delete(os.path.join(path(profile_name), ".auth"), _scope(profile_name, ".auth"))
207
312
  shutil.rmtree(os.path.join(_repo(), profile_name), ignore_errors=True)
208
313
 
209
314
 
@@ -230,6 +335,24 @@ def _load_data_file_with_env_overrides(profile_name: str, default: Any) -> Any:
230
335
  data = load_data_file(file(profile_name), default=default)
231
336
  if data is None:
232
337
  return None
338
+ if isinstance(data, dict) and _keyring_on(data):
339
+ # Secrets typed into the file (for example via 'profile edit') move into the keyring here.
340
+ # Keyring off: leave the parsed document alone. No secret walk, no keyring.
341
+ profile_file = file(profile_name)
342
+
343
+ def rewrite(document: dict[str, Any]) -> None:
344
+ _save_private(document, profile_file)
345
+
346
+ stored = secret_store.protect(
347
+ data,
348
+ _scope(profile_name),
349
+ secret_store.PROFILE_FIELDS,
350
+ rewrite=rewrite,
351
+ enabled=True,
352
+ )
353
+ if stored is not data:
354
+ _drop_auth_cache(profile_name)
355
+ data = stored
233
356
 
234
357
  for key, value in os.environ.items():
235
358
  if not key.upper().startswith(env_prefix):
@@ -294,7 +417,7 @@ class auth:
294
417
  def get() -> Any:
295
418
  global _auth_cache
296
419
  if _auth_cache is None:
297
- _auth_cache = load_data_file(auth._file_name(), {}, "yaml")
420
+ _auth_cache = secret_store.load(auth._file_name())
298
421
  return dotify(deepcopy(_auth_cache))
299
422
 
300
423
  @staticmethod
@@ -307,11 +430,18 @@ class auth:
307
430
  _auth_cache = deepcopy(data)
308
431
  if env.bool("CTXP_AUTH_PERSIST", True):
309
432
  file_name = auth._file_name()
310
- save_data_file(data, file_name, "yaml", 0o600)
433
+ secret_store.save(
434
+ data,
435
+ file_name,
436
+ _scope(name(), ".auth"),
437
+ _save_private,
438
+ enabled=feature("keyring"),
439
+ )
311
440
 
312
441
  @staticmethod
313
442
  def delete() -> None:
314
443
  file_name = auth._file_name()
444
+ secret_store.delete(file_name, _scope(name(), ".auth"))
315
445
  if os.path.exists(file_name):
316
446
  os.unlink(file_name)
317
447
  global _auth_cache
@@ -0,0 +1,279 @@
1
+ """Optional OS keyring for profile and auth secrets.
2
+
3
+ Off unless the caller passes enabled=True (profile features.keyring). The file then keeps a reference:
4
+
5
+ keyring://zen-cli/<profile>/<file>/<field.path>
6
+ e.g. keyring://zen-cli/prod/profile.yml/csp.apiToken
7
+ keyring://zen-cli/prod/.auth/<cache-hash>.access_token
8
+
9
+ Reading follows the reference. New secrets stay plaintext when keyring is off or no backend exists.
10
+ Existing references are still read, and removed on delete, when the feature is off.
11
+ A secret field's name must not contain ".".
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import contextlib
17
+ import copy
18
+ import logging
19
+ import os
20
+ from typing import TYPE_CHECKING, Any, Literal
21
+
22
+ if TYPE_CHECKING:
23
+ from collections.abc import Callable
24
+
25
+ from .data_util import load_data_file
26
+ from .util import CtxpException
27
+
28
+ log = logging.getLogger(__name__)
29
+
30
+ SERVICE = "zen-cli"
31
+ REF_PREFIX = "keyring://"
32
+ AUTH_FIELDS = ("access_token", "refresh_token", "id_token")
33
+ PROFILE_FIELDS = (
34
+ "apiToken",
35
+ "api_token",
36
+ "api-token",
37
+ "clientSecret",
38
+ "client_secret",
39
+ "client-secret",
40
+ "password",
41
+ "basic",
42
+ "accessToken",
43
+ "access_token",
44
+ )
45
+
46
+ Missing = Literal["dict", "field", "keep"]
47
+
48
+ _warned = False
49
+
50
+
51
+ def _backend() -> Any:
52
+ """The keyring module when a real backend exists, else None."""
53
+ try:
54
+ import keyring
55
+ from keyring.backends import fail
56
+
57
+ return None if isinstance(keyring.get_keyring(), fail.Keyring) else keyring
58
+ except Exception:
59
+ return None
60
+
61
+
62
+ def available() -> bool:
63
+ """Whether a usable keyring backend exists."""
64
+ return _backend() is not None
65
+
66
+
67
+ def _warn(error: Exception) -> None:
68
+ global _warned
69
+ if not _warned:
70
+ _warned = True
71
+ log.warning("Keyring unavailable, keeping secrets in the profile files: %s", error)
72
+
73
+
74
+ def _ref(account: str) -> str:
75
+ return f"{REF_PREFIX}{SERVICE}/{account}"
76
+
77
+
78
+ def _parse(value: object) -> tuple[str, str] | None:
79
+ """(service, account) of a keyring reference, else None."""
80
+ if not (isinstance(value, str) and value.startswith(REF_PREFIX)):
81
+ return None
82
+ service, _, account = value[len(REF_PREFIX) :].partition("/")
83
+ return (service, account) if service and account else None
84
+
85
+
86
+ def _slots(
87
+ data: dict[str, Any], fields: tuple[str, ...], prefix: tuple[str, ...] = ()
88
+ ) -> list[tuple[dict[str, Any], str, tuple[str, ...]]]:
89
+ """(container, key, field path) for every non-empty string secret field."""
90
+ found: list[tuple[dict[str, Any], str, tuple[str, ...]]] = []
91
+ for key, value in data.items():
92
+ if isinstance(value, dict):
93
+ found.extend(_slots(value, fields, (*prefix, str(key))))
94
+ elif key in fields and isinstance(value, str) and value:
95
+ found.append((data, str(key), (*prefix, str(key))))
96
+ return found
97
+
98
+
99
+ def _protect(data: dict[str, Any], scope: str, kr: Any, fields: tuple[str, ...]) -> dict[str, Any]:
100
+ """Move plaintext secrets into the keyring, leaving a reference. References are left alone."""
101
+ out = copy.deepcopy(data)
102
+ for container, key, parts in _slots(out, fields):
103
+ if _parse(container[key]):
104
+ continue
105
+ if any("." in part for part in parts):
106
+ joined = ".".join(parts)
107
+ raise CtxpException(f"Cannot store secret '{joined}' in the keyring: field names must not contain '.'.")
108
+ account = f"{scope}/{'.'.join(parts)}"
109
+ kr.set_password(SERVICE, account, container[key])
110
+ container[key] = _ref(account)
111
+ return out
112
+
113
+
114
+ def has_plaintext(data: dict[str, Any], fields: tuple[str, ...]) -> bool:
115
+ return any(not _parse(container[key]) for container, key, _ in _slots(data, fields))
116
+
117
+
118
+ def _refs(data: dict[str, Any], fields: tuple[str, ...]) -> set[tuple[str, str]]:
119
+ return {ref for container, key, _ in _slots(data, fields) if (ref := _parse(container[key]))}
120
+
121
+
122
+ def _own(refs: set[tuple[str, str]], scope: str) -> list[tuple[str, str]]:
123
+ """References that belong to this scope: the only ones delete may remove."""
124
+ return [(svc, acct) for svc, acct in refs if svc == SERVICE and acct.startswith(f"{scope}/")]
125
+
126
+
127
+ def _reveal(data: dict[str, Any], kr: Any, fields: tuple[str, ...], missing: Missing) -> dict[str, Any] | None:
128
+ """Replace references with the secrets they point to.
129
+
130
+ When one can't be resolved, `missing` decides: "dict" drops the containing dict (a half token is
131
+ never returned); "field" drops just that field; "keep" leaves the reference in place.
132
+ """
133
+ out: dict[str, Any] = {}
134
+ for key, value in data.items():
135
+ if isinstance(value, dict):
136
+ nested = _reveal(value, kr, fields, missing)
137
+ if nested is not None:
138
+ out[key] = nested
139
+ continue
140
+ if key in fields and isinstance(value, str) and value.startswith(REF_PREFIX):
141
+ ref = _parse(value)
142
+ secret = None
143
+ if ref and kr:
144
+ with contextlib.suppress(Exception):
145
+ secret = kr.get_password(*ref)
146
+ if secret is not None:
147
+ out[key] = secret
148
+ elif missing == "dict":
149
+ return None
150
+ elif missing == "keep":
151
+ out[key] = value
152
+ continue
153
+ out[key] = value
154
+ return out
155
+
156
+
157
+ def protect(
158
+ data: dict[str, Any],
159
+ scope: str,
160
+ fields: tuple[str, ...],
161
+ rewrite: Callable[[dict[str, Any]], None],
162
+ enabled: bool = False,
163
+ ) -> dict[str, Any]:
164
+ """With enabled and a usable keyring, move plaintext secrets into it and rewrite the file.
165
+
166
+ References are kept as they are. Returns the data that should stay in memory (references when moved).
167
+ """
168
+ kr = _backend() if enabled and has_plaintext(data, fields) else None
169
+ if kr:
170
+ try:
171
+ file_data = _protect(data, scope, kr, fields)
172
+ rewrite(file_data)
173
+ return file_data
174
+ except CtxpException:
175
+ raise
176
+ except Exception as e:
177
+ _warn(e)
178
+ return data
179
+
180
+
181
+ def reveal(data: dict[str, Any], fields: tuple[str, ...], missing: Missing = "dict") -> dict[str, Any]:
182
+ """Return data with references resolved. No reference means the keyring is not opened."""
183
+ if not _refs(data, fields):
184
+ return data
185
+ return _reveal(data, _backend(), fields, missing) or {}
186
+
187
+
188
+ def reveal_value(value: object) -> Any:
189
+ """The secret behind one reference; any other value is returned as is. None if it can't be resolved."""
190
+ ref = _parse(value)
191
+ if not ref:
192
+ return value
193
+ kr = _backend()
194
+ if kr:
195
+ with contextlib.suppress(Exception):
196
+ return kr.get_password(*ref)
197
+ return None
198
+
199
+
200
+ def _stored_refs(file_name: str, fields: tuple[str, ...]) -> set[tuple[str, str]]:
201
+ """References already stored in a file.
202
+
203
+ Missing files and files with no ``keyring://`` text are not parsed, and the keyring is not opened.
204
+ """
205
+ if not os.path.isfile(file_name):
206
+ return set()
207
+ with open(file_name, encoding="utf-8") as handle:
208
+ text = handle.read()
209
+ if REF_PREFIX not in text:
210
+ return set()
211
+ import yaml
212
+
213
+ loaded = yaml.safe_load(text)
214
+ if not isinstance(loaded, dict):
215
+ return set()
216
+ return _refs(loaded, fields)
217
+
218
+
219
+ def load(file_name: str, fields: tuple[str, ...] = AUTH_FIELDS) -> dict[str, Any]:
220
+ """Load a secured data file. Plaintext secrets are read as is. References are resolved."""
221
+ loaded = load_data_file(file_name, {}, "yaml")
222
+ if not isinstance(loaded, dict):
223
+ return {}
224
+ return reveal(loaded, fields)
225
+
226
+
227
+ def _delete_refs(refs: set[tuple[str, str]], scope: str, kr: Any) -> None:
228
+ for ref in _own(refs, scope):
229
+ with contextlib.suppress(Exception):
230
+ kr.delete_password(*ref)
231
+
232
+
233
+ def save(
234
+ data: dict[str, Any],
235
+ file_name: str,
236
+ scope: str,
237
+ write: Callable[[dict[str, Any], str], None],
238
+ fields: tuple[str, ...] = AUTH_FIELDS,
239
+ enabled: bool = False,
240
+ ) -> None:
241
+ """Save with secrets in the keyring when enabled and usable, else plaintext in the file.
242
+
243
+ The keyring is opened only to store a new plaintext secret or to delete a reference that the
244
+ file is no longer keeping.
245
+ """
246
+ previous_refs = _stored_refs(file_name, fields)
247
+ if enabled and has_plaintext(data, fields):
248
+ kr = _backend()
249
+ if kr:
250
+ try:
251
+ file_data = _protect(data, scope, kr, fields)
252
+ write(file_data, file_name)
253
+ _delete_refs(previous_refs - _refs(file_data, fields), scope, kr)
254
+ return
255
+ except CtxpException:
256
+ raise
257
+ except Exception as e:
258
+ _warn(e)
259
+ write(data, file_name)
260
+ stale = previous_refs - _refs(data, fields)
261
+ if not stale:
262
+ return
263
+ kr = _backend()
264
+ if kr:
265
+ _delete_refs(stale, scope, kr)
266
+
267
+
268
+ def delete(file_name: str, scope: str, fields: tuple[str, ...] = AUTH_FIELDS) -> None:
269
+ """Remove this scope's keyring entries referenced by the file. The caller removes the file.
270
+
271
+ A reference that points into another scope is left alone. No reference means the keyring is not opened.
272
+ """
273
+ refs = _stored_refs(file_name, fields)
274
+ if not refs:
275
+ return
276
+ kr = _backend()
277
+ if not kr:
278
+ return
279
+ _delete_refs(refs, scope, kr)