codapact 0.6.1__tar.gz → 0.8.0__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.
Files changed (170) hide show
  1. codapact-0.8.0/.release-please-manifest.json +1 -0
  2. {codapact-0.6.1 → codapact-0.8.0}/CHANGELOG.md +14 -0
  3. {codapact-0.6.1 → codapact-0.8.0}/PKG-INFO +1 -1
  4. {codapact-0.6.1 → codapact-0.8.0}/docs/configuration.md +34 -11
  5. {codapact-0.6.1 → codapact-0.8.0}/pyproject.toml +1 -1
  6. {codapact-0.6.1 → codapact-0.8.0}/pyproject.toml.orig +1 -1
  7. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/__init__.py +1 -1
  8. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/commands/derive.py +1 -0
  9. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/cli.py +71 -11
  10. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/cli_auth.py +133 -21
  11. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/cli_tools.py +2 -0
  12. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/credentials.py +2 -2
  13. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/oauth.py +22 -1
  14. codapact-0.8.0/src/codapact/runtime/profiles.py +224 -0
  15. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/targets/python/cli.py +4 -1
  16. {codapact-0.6.1 → codapact-0.8.0}/tests/e2e/test_auth_e2e.py +44 -1
  17. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_cli_auth.py +16 -4
  18. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_cli_builtins.py +11 -0
  19. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_cli_options.py +12 -2
  20. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_oauth.py +2 -1
  21. codapact-0.8.0/tests/unit/test_profiles.py +302 -0
  22. {codapact-0.6.1 → codapact-0.8.0}/uv.lock +1 -1
  23. codapact-0.6.1/.release-please-manifest.json +0 -1
  24. {codapact-0.6.1 → codapact-0.8.0}/.github/workflows/ci.yml +0 -0
  25. {codapact-0.6.1 → codapact-0.8.0}/.github/workflows/codeql.yml +0 -0
  26. {codapact-0.6.1 → codapact-0.8.0}/.github/workflows/mutation.yml +0 -0
  27. {codapact-0.6.1 → codapact-0.8.0}/.github/workflows/nightly.yml +0 -0
  28. {codapact-0.6.1 → codapact-0.8.0}/.github/workflows/release.yml +0 -0
  29. {codapact-0.6.1 → codapact-0.8.0}/LICENSE +0 -0
  30. {codapact-0.6.1 → codapact-0.8.0}/README.md +0 -0
  31. {codapact-0.6.1 → codapact-0.8.0}/docs/architecture.md +0 -0
  32. {codapact-0.6.1 → codapact-0.8.0}/docs/branding/README.md +0 -0
  33. {codapact-0.6.1 → codapact-0.8.0}/docs/branding/mark.svg +0 -0
  34. {codapact-0.6.1 → codapact-0.8.0}/docs/branding/wordmark.svg +0 -0
  35. {codapact-0.6.1 → codapact-0.8.0}/docs/testing.md +0 -0
  36. {codapact-0.6.1 → codapact-0.8.0}/examples/library/codapact.yaml +0 -0
  37. {codapact-0.6.1 → codapact-0.8.0}/examples/library/operations.graphql +0 -0
  38. {codapact-0.6.1 → codapact-0.8.0}/examples/library/schema.graphql +0 -0
  39. {codapact-0.6.1 → codapact-0.8.0}/examples/petstore/codapact.yaml +0 -0
  40. {codapact-0.6.1 → codapact-0.8.0}/examples/petstore/openapi.yaml +0 -0
  41. {codapact-0.6.1 → codapact-0.8.0}/release-please-config.json +0 -0
  42. {codapact-0.6.1 → codapact-0.8.0}/scripts/extract_openapi_subset.py +0 -0
  43. {codapact-0.6.1 → codapact-0.8.0}/scripts/mutation_score.py +0 -0
  44. {codapact-0.6.1 → codapact-0.8.0}/scripts/verify_dist.py +0 -0
  45. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/__main__.py +0 -0
  46. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/commands/__init__.py +0 -0
  47. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/commands/model.py +0 -0
  48. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/core/__init__.py +0 -0
  49. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/core/diagnostics.py +0 -0
  50. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/core/errors.py +0 -0
  51. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/core/naming.py +0 -0
  52. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/core/net.py +0 -0
  53. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/model/__init__.py +0 -0
  54. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/model/api.py +0 -0
  55. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/model/authspec.py +0 -0
  56. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/model/migrations.py +0 -0
  57. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/model/rewrite.py +0 -0
  58. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/model/serialize.py +0 -0
  59. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/model/types.py +0 -0
  60. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/model/validate.py +0 -0
  61. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/model/values.py +0 -0
  62. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/pipeline/__init__.py +0 -0
  63. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/pipeline/cli.py +0 -0
  64. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/pipeline/config.py +0 -0
  65. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/pipeline/defaults.py +0 -0
  66. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/pipeline/pipeline.py +0 -0
  67. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/pipeline/sync.py +0 -0
  68. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/pipeline/writer.py +0 -0
  69. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/plugins/__init__.py +0 -0
  70. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/plugins/external.py +0 -0
  71. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/plugins/protocol.py +0 -0
  72. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/plugins/registry.py +0 -0
  73. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/py.typed +0 -0
  74. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/__init__.py +0 -0
  75. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/abstractions.py +0 -0
  76. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/arguments.py +0 -0
  77. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/auth.py +0 -0
  78. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/client.py +0 -0
  79. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/codec.py +0 -0
  80. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/errors.py +0 -0
  81. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/middleware.py +0 -0
  82. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/protocols/__init__.py +0 -0
  83. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/protocols/base.py +0 -0
  84. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/protocols/graphql.py +0 -0
  85. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/protocols/http.py +0 -0
  86. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/runtime/selftest.py +0 -0
  87. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/shaping/__init__.py +0 -0
  88. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/shaping/base.py +0 -0
  89. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/shaping/engine.py +0 -0
  90. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/shaping/transforms.py +0 -0
  91. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/sources/__init__.py +0 -0
  92. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/sources/base.py +0 -0
  93. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/sources/graphql/__init__.py +0 -0
  94. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/sources/graphql/translator.py +0 -0
  95. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/sources/loader.py +0 -0
  96. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/sources/openapi/__init__.py +0 -0
  97. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/sources/openapi/translator.py +0 -0
  98. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/surface/__init__.py +0 -0
  99. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/surface/derive.py +0 -0
  100. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/surface/model.py +0 -0
  101. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/targets/__init__.py +0 -0
  102. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/targets/python/__init__.py +0 -0
  103. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/targets/python/e2e.py +0 -0
  104. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/targets/python/library.py +0 -0
  105. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/targets/python/naming.py +0 -0
  106. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/targets/typescript/__init__.py +0 -0
  107. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/targets/typescript/library.py +0 -0
  108. {codapact-0.6.1 → codapact-0.8.0}/src/codapact/targets/typescript/runtime.ts +0 -0
  109. {codapact-0.6.1 → codapact-0.8.0}/tests/authlab.py +0 -0
  110. {codapact-0.6.1 → codapact-0.8.0}/tests/conftest.py +0 -0
  111. {codapact-0.6.1 → codapact-0.8.0}/tests/e2e/test_cli_e2e.py +0 -0
  112. {codapact-0.6.1 → codapact-0.8.0}/tests/e2e/test_public_apis.py +0 -0
  113. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/authlab/authlab_plugin.py +0 -0
  114. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/authlab/codapact.yaml +0 -0
  115. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/authlab/fake_browser.py +0 -0
  116. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/authlab/openapi.yaml +0 -0
  117. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/authlab_smoke.ts +0 -0
  118. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/contracts/wire.yaml +0 -0
  119. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/corpus/README.md +0 -0
  120. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/corpus/countries/codapact.yaml +0 -0
  121. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/corpus/countries/operations.graphql +0 -0
  122. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/corpus/countries/schema.graphql +0 -0
  123. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/corpus/github/codapact.yaml +0 -0
  124. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/corpus/github/openapi.json +0 -0
  125. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/corpus/pokeapi/codapact.yaml +0 -0
  126. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/corpus/pokeapi/openapi.yml +0 -0
  127. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/corpus/ynab/README.md +0 -0
  128. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/corpus/ynab/codapact.yaml +0 -0
  129. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/corpus/ynab/openapi.yaml +0 -0
  130. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/library_smoke.ts +0 -0
  131. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/outline_plugin.py +0 -0
  132. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/petstore_smoke.ts +0 -0
  133. {codapact-0.6.1 → codapact-0.8.0}/tests/fixtures/wire_parity.ts +0 -0
  134. {codapact-0.6.1 → codapact-0.8.0}/tests/integration/test_cli_conformance.py +0 -0
  135. {codapact-0.6.1 → codapact-0.8.0}/tests/integration/test_cli_conventions.py +0 -0
  136. {codapact-0.6.1 → codapact-0.8.0}/tests/integration/test_contract_properties.py +0 -0
  137. {codapact-0.6.1 → codapact-0.8.0}/tests/integration/test_corpus.py +0 -0
  138. {codapact-0.6.1 → codapact-0.8.0}/tests/integration/test_generated_code_properties.py +0 -0
  139. {codapact-0.6.1 → codapact-0.8.0}/tests/integration/test_generation.py +0 -0
  140. {codapact-0.6.1 → codapact-0.8.0}/tests/integration/test_public_api_cli.py +0 -0
  141. {codapact-0.6.1 → codapact-0.8.0}/tests/integration/test_wire_parity.py +0 -0
  142. {codapact-0.6.1 → codapact-0.8.0}/tests/integration/test_ynab_contract.py +0 -0
  143. {codapact-0.6.1 → codapact-0.8.0}/tests/perf/test_scaling.py +0 -0
  144. {codapact-0.6.1 → codapact-0.8.0}/tests/public_api_contract.py +0 -0
  145. {codapact-0.6.1 → codapact-0.8.0}/tests/strategies.py +0 -0
  146. {codapact-0.6.1 → codapact-0.8.0}/tests/support.py +0 -0
  147. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_architecture.py +0 -0
  148. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_auth_and_graphql_sources.py +0 -0
  149. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_auth_sources.py +0 -0
  150. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_bundle_e2e.py +0 -0
  151. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_codec_serialize.py +0 -0
  152. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_core.py +0 -0
  153. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_credential_fields.py +0 -0
  154. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_env_prefix.py +0 -0
  155. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_guards.py +0 -0
  156. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_live_ynab_findings.py +0 -0
  157. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_model.py +0 -0
  158. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_mutation_score.py +0 -0
  159. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_openapi_edges.py +0 -0
  160. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_openapi_translator_units.py +0 -0
  161. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_plugins_pipeline.py +0 -0
  162. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_public_api_findings.py +0 -0
  163. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_runtime.py +0 -0
  164. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_runtime_edges.py +0 -0
  165. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_runtime_pagination.py +0 -0
  166. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_shaping_surface_commands.py +0 -0
  167. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_sources.py +0 -0
  168. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_sync.py +0 -0
  169. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_target_rendering.py +0 -0
  170. {codapact-0.6.1 → codapact-0.8.0}/tests/unit/test_usability.py +0 -0
@@ -0,0 +1 @@
1
+ {".":"0.8.0"}
@@ -2,6 +2,20 @@
2
2
 
3
3
  <!-- markdownlint-configure-file { "MD024": { "siblings_only": true } } -->
4
4
 
5
+ ## [0.8.0](https://github.com/mikejhill/codapact/compare/v0.7.0...v0.8.0) (2026-11-14)
6
+
7
+
8
+ ### Features
9
+
10
+ * **cli:** report the installed distribution's version ([#49](https://github.com/mikejhill/codapact/issues/49)) ([d7d663d](https://github.com/mikejhill/codapact/commit/d7d663d611548534e3657b1ffc6ec8a048ebc96d))
11
+
12
+ ## [0.7.0](https://github.com/mikejhill/codapact/compare/v0.6.1...v0.7.0) (2026-11-14)
13
+
14
+
15
+ ### Features
16
+
17
+ * **auth:** credential profiles; doctor names the exact keyring entry ([#47](https://github.com/mikejhill/codapact/issues/47)) ([de86a9e](https://github.com/mikejhill/codapact/commit/de86a9ec0eefd7cc9e4b65ba76abb8ee99088fcd))
18
+
5
19
  ## [0.6.1](https://github.com/mikejhill/codapact/compare/v0.6.0...v0.6.1) (2026-11-14)
6
20
 
7
21
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codapact
3
- Version: 0.6.1
3
+ Version: 0.8.0
4
4
  Summary: Contracts into callable tools: generate libraries, then CLIs, from OpenAPI, GraphQL, and other API contracts.
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -143,13 +143,14 @@ Precedence: flag, then environment, then settings file.
143
143
  | Error format | `--error-format text\|json` | `<PREFIX>_ERROR_FORMAT` | `error_format` |
144
144
  | Credentials | none | `<PREFIX>_<SCHEME>`; basic uses `_USERNAME`/`_PASSWORD`; full chain under [Authentication](#authentication) | `auth_plugin`; secrets are never read from the file |
145
145
  | Option defaults | the option itself | none | `defaults: {plan_id: "…"}` (option names, `_` or `-`) |
146
+ | Saved-login profile | `--profile NAME` | `<PREFIX>_PROFILE` | `profile`; otherwise the default from `auth use` ([Profiles](#profiles)) |
146
147
 
147
148
  The settings file is `--config PATH` or `$XDG_CONFIG_HOME/<program>/config.json`.
148
149
  `<PREFIX>` is `cli.env_prefix` when set (upper snake case, e.g. `ACME`), else the program
149
150
  name in upper snake case (`cli.program: my-tool` gives `MY_TOOL`). `<program> --help` lists
150
151
  the credential variables for the contract's auth schemes.
151
152
 
152
- Global options work before or after the command: `--base-url`, `--timeout`, `--config`,
153
+ Global options work before or after the command: `--base-url`, `--timeout`, `--profile`, `--config`,
153
154
  `-o/--output`, `--query PATH` (`data.items[].name`, `data.items[0]`; with `--all` the
154
155
  result is the item list, so `[].name`; a path that matches nothing fails with exit 2 and lists the keys that exist), `--dry-run`, `-v/--verbose`, `--error-format`,
155
156
  `--allow-private`, and `--response-validation`. Command help lists them in one line;
@@ -163,7 +164,7 @@ result is the item list, so `[].name`; a path that matches nothing fails with ex
163
164
  | Need | How |
164
165
  | --- | --- |
165
166
  | Help | `-h`/`--help` on every level; bare `<program>` or `<program> GROUP` prints help (exit `0`). Command help has a usage line with positionals and required options, examples, and a global-options reminder. |
166
- | Version | `-V`/`--version`: `poke 0.1.0 (PokéAPI 2.10.0; codapact 0.4.0)` |
167
+ | Version | `-V`/`--version`: `poke 0.1.0 (PokéAPI 2.10.0; codapact 0.4.0)`; the installed distribution's version when it differs from the generated `version` option (so a release tool can bump packaging alone) |
167
168
  | Discovery for agents | `<program> describe [COMMAND…]`: JSON with every command's arguments (type, required, positional, choices, repeated), `read_only`/`destructive`/`paginated`, `requires_one_of` option groups, environment variables, exit codes. `describe --brief` keeps only names, summaries, and usage lines. Naming one command (or passing `--schemas`) adds the JSON Schema of its output and of each JSON-valued argument |
168
169
  | Diagnosis | `<program> doctor [--offline]`: version, settings file, base URL and its source, credentials (set or missing, never printed), proxy, connectivity. Table on a terminal, JSON otherwise; exit `1` when a check fails |
169
170
  | Completion | `<program> completion bash\|zsh\|fish\|powershell` prints a script that asks the program for candidates |
@@ -172,11 +173,11 @@ result is the item list, so `[].name`; a path that matches nothing fails with ex
172
173
  | Mistakes | unknown commands, choices, and options get "did you mean" hints; leftovers are reported by the command they were given to; API failures name the command typed (`pets get failed with HTTP 404`) |
173
174
  | Machine-readable errors | `--error-format json` prints one `{"error": {"type", "message", "exit_code", "status", "hint", "details"}}` object on stderr; contract warnings become `{"warning": …}` lines |
174
175
 
175
- | Credentials | `<program> auth login\|logout\|status\|token`; see [Authentication](#authentication) |
176
+ | Credentials | `<program> auth login\|logout\|status\|token\|profiles\|use`; see [Authentication](#authentication) |
176
177
 
177
178
  `describe`, `doctor`, `completion`, and `auth` are skipped when the API has a top-level command
178
- of the same name; `--version`, `--dry-run`, `--verbose`, and `--error-format` are reserved, so
179
- API parameters with those names become `--arg-version` and so on.
179
+ of the same name; `--version`, `--dry-run`, `--verbose`, `--error-format`, and `--profile` are
180
+ reserved, so API parameters with those names become `--arg-version` and so on.
180
181
 
181
182
  `tests/integration/test_cli_conformance.py` checks these conventions for every example
182
183
  contract (Petstore, Library, PokéAPI, YNAB, Countries), including a `--dry-run` of every
@@ -282,12 +283,34 @@ The sign-in itself (multi-step forms, SSO, redirects, MFA) stays in the plugin;
282
283
  supply and store its inputs. Field names are lower snake case; `secret`, `optional` and `help`
283
284
  are the only keys.
284
285
 
285
- Saved credentials and tokens go to the OS keyring when one is usable, one entry per scheme
286
- named `codapact:<program>:<scheme>` (user name `<scheme>`; for example `codapact:ynab:bearer`
287
- in Windows Credential Manager), otherwise to a
288
- `0600` JSON file at `$XDG_CONFIG_HOME/<program>/credentials.json`.
289
- `<PREFIX>_CREDENTIAL_STORE=keyring|file|memory` forces one. Entries saved by codapact
290
- before 0.6.1 (service `<program>`) are moved to the new name the first time they are read.
286
+ Saved credentials and tokens go to the OS keyring when one is usable, one entry per profile
287
+ and scheme named `codapact:<program>:<profile>:<scheme>` (user name `<profile>:<scheme>`; for
288
+ example `codapact:ynab:default:bearer` in Windows Credential Manager), otherwise to a
289
+ `0600` JSON file at `$XDG_CONFIG_HOME/<program>/credentials.json` (keys `<profile>:<scheme>`).
290
+ `<PREFIX>_CREDENTIAL_STORE=keyring|file|memory` forces one. Logins saved before profiles
291
+ existed (keyring service `<program>` before 0.6.1, `codapact:<program>:<scheme>` in 0.6.1)
292
+ belong to the `default` profile and move to its name the first time they are read.
293
+
294
+ ### Profiles
295
+
296
+ Several saved logins per CLI: different accounts, or tokens with different access levels.
297
+
298
+ | Need | Command |
299
+ | --- | --- |
300
+ | First login | `auth login` saves to profile `default`, which becomes the default |
301
+ | Another login, named automatically | `auth login --new` (`profile-2`, `profile-3`, …) |
302
+ | Another login, named by you | `auth login --profile work` (creates `work`, or replaces its login) |
303
+ | List | `auth profiles`: name, whether it is the default, which schemes are saved |
304
+ | Change the default | `auth use work` |
305
+ | Use one for a single command | `--profile work` on any command, or `<PREFIX>_PROFILE=work` |
306
+ | Remove | `auth logout --profile work` (without `--scheme` it also forgets the profile) |
307
+
308
+ Selection order: `--profile`, `<PREFIX>_PROFILE`, the settings file's `profile`, the default
309
+ set by `auth use` (stored in `$XDG_CONFIG_HOME/<program>/profiles.json`, no secrets), then
310
+ `default`. Naming a profile that does not exist fails, except for `auth login`, which creates
311
+ it. Profiles scope saved logins only: `<PREFIX>_<SCHEME>` variables, credential commands and
312
+ OAuth client settings still come first. `auth status` and `doctor` show the profile in use and
313
+ the exact keyring entry or file key a saved login came from.
291
314
 
292
315
  Libraries take the same objects directly:
293
316
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "codapact"
3
- version = "0.6.1"
3
+ version = "0.8.0"
4
4
  description = "Contracts into callable tools: generate libraries, then CLIs, from OpenAPI, GraphQL, and other API contracts."
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "codapact"
3
- version = "0.6.1"
3
+ version = "0.8.0"
4
4
  description = "Contracts into callable tools: generate libraries, then CLIs, from OpenAPI, GraphQL, and other API contracts."
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -5,4 +5,4 @@ from importlib.metadata import PackageNotFoundError, version
5
5
  try:
6
6
  __version__ = version("codapact")
7
7
  except PackageNotFoundError: # pragma: no cover - running from an unbuilt tree
8
- __version__ = "0.6.1"
8
+ __version__ = "0.8.0"
@@ -42,6 +42,7 @@ RESERVED_FLAGS = frozenset(
42
42
  "dry-run",
43
43
  "verbose",
44
44
  "error-format",
45
+ "profile",
45
46
  }
46
47
  )
47
48
  DESTRUCTIVE_VERBS = frozenset({"delete", "remove", "destroy", "purge"})
@@ -9,6 +9,7 @@ from __future__ import annotations
9
9
 
10
10
  import argparse
11
11
  import difflib
12
+ import importlib.metadata
12
13
  import json
13
14
  import os
14
15
  import re
@@ -45,6 +46,7 @@ from codapact.runtime.errors import (
45
46
  )
46
47
  from codapact.runtime.middleware import Retry
47
48
  from codapact.runtime.oauth import TokenStore, default_store
49
+ from codapact.runtime.profiles import ProfileIndex, ProfileStore, check_profile_name, profiles_path
48
50
 
49
51
  EXIT_OK = 0
50
52
  EXIT_API = 1
@@ -78,6 +80,7 @@ SETTINGS_KEYS = frozenset(
78
80
  "defaults",
79
81
  "auth_plugin",
80
82
  "auth",
83
+ "profile",
81
84
  }
82
85
  )
83
86
 
@@ -288,6 +291,23 @@ class CliRuntime:
288
291
  """Default ``package.module:factory`` auth plugin (``cli.auth_plugin`` in codapact.yaml)."""
289
292
  auth_config: Mapping[str, Mapping[str, Any]] | None = None
290
293
  """Per-scheme OAuth defaults baked in at generation (``cli.auth`` in codapact.yaml)."""
294
+ distribution: str = ""
295
+ """Installed distribution name; its metadata version wins over ``version``."""
296
+
297
+ @property
298
+ def program_version(self) -> str:
299
+ """Return the installed distribution's version, else the generated ``version``.
300
+
301
+ Packaging may set the release version outside the generated code (for example a
302
+ hand-written ``pyproject.toml`` that release tooling bumps), so the installed
303
+ metadata is the source of truth when it exists.
304
+ """
305
+ if self.distribution:
306
+ try:
307
+ return importlib.metadata.version(self.distribution)
308
+ except importlib.metadata.PackageNotFoundError:
309
+ pass
310
+ return self.version
291
311
 
292
312
  @property
293
313
  def env(self) -> dict[str, str]:
@@ -324,7 +344,7 @@ class CliRuntime:
324
344
  """Return ``program version (API version; codapact version)``."""
325
345
  api = f"{self.api_name} {self.api_version}".strip()
326
346
  parts = [p for p in (api, f"codapact {__version__}") if p]
327
- return f"{self.program} {self.version or '0.0.0'} ({'; '.join(parts)})"
347
+ return f"{self.program} {self.program_version or '0.0.0'} ({'; '.join(parts)})"
328
348
 
329
349
  def epilog(self, credentials: str = "", examples: Sequence[str] = ()) -> str:
330
350
  """Return the root help epilog: examples, credentials, settings, exit codes."""
@@ -425,6 +445,12 @@ class CliRuntime:
425
445
  default=keep,
426
446
  help=text(f"request timeout in seconds (env {e}_TIMEOUT)"),
427
447
  )
448
+ group.add_argument(
449
+ "--profile",
450
+ default=keep,
451
+ metavar="NAME",
452
+ help=text(f"saved-login profile to use (env {e}_PROFILE; default: auth use)"),
453
+ )
428
454
  group.add_argument(
429
455
  "--config", default=keep, metavar="FILE", help=text("settings file (default: XDG dir)")
430
456
  )
@@ -446,7 +472,8 @@ class CliRuntime:
446
472
  options = (
447
473
  f"-o/--output {{{','.join(OUTPUT_FORMATS)}}}, --query PATH, --pick KEYS, "
448
474
  "--dry-run, -v/--verbose, "
449
- "--error-format {text,json}, --base-url URL, --timeout SECONDS, --config FILE, "
475
+ "--error-format {text,json}, --base-url URL, --timeout SECONDS, --profile NAME, "
476
+ "--config FILE, "
450
477
  "--allow-private, --response-validation {strict,warn,off}"
451
478
  )
452
479
  body = textwrap.fill(
@@ -589,12 +616,38 @@ class CliRuntime:
589
616
  plugin, sources["auth_plugin"] = self._setting(args, file_settings, "auth_plugin")
590
617
  if not plugin and self.auth_plugin:
591
618
  plugin, sources["auth_plugin"] = self.auth_plugin, "generated default"
592
- options["auth"] = self.credentials(options, file_settings, str(plugin or ""))
619
+ profile, source = self.profile(args, file_settings)
620
+ sources["profile"] = f"{profile} (from {source})"
621
+ options["auth"] = self.credentials(options, file_settings, str(plugin or ""), profile)
593
622
  return options, sources
594
623
 
595
- def credential_store(self) -> TokenStore:
596
- """Return where ``auth login`` saves secrets (keyring, or a 0600 file)."""
597
- return default_store(self.program, self.env, self.env_prefix)
624
+ def profiles(self) -> ProfileIndex:
625
+ """Return the list of saved-login profiles and the default one."""
626
+ memory = self.env.get(f"{self.env_prefix}_CREDENTIAL_STORE", "").lower() == "memory"
627
+ return ProfileIndex(None if memory else profiles_path(self.program, self.env))
628
+
629
+ def profile(self, args: argparse.Namespace, file_settings: dict[str, Any]) -> tuple[str, str]:
630
+ """Return the profile in effect and where it came from.
631
+
632
+ A profile named explicitly must exist, except for ``auth login``, which creates it.
633
+ """
634
+ index = self.profiles()
635
+ name, source = self._setting(args, file_settings, "profile")
636
+ if name is None:
637
+ return index.default, "profiles default" if index.names else "default"
638
+ name = check_profile_name(str(name))
639
+ if not index.known(name) and getattr(args, "auth_action", None) != "login":
640
+ raise index.unknown(name)
641
+ return name, source
642
+
643
+ def credential_store(self, profile: str | None = None) -> TokenStore:
644
+ """Return where ``auth login`` saves secrets for ``profile`` (default: the default).
645
+
646
+ The OS keyring or a 0600 file, with keys scoped to the profile.
647
+ """
648
+ index = self.profiles()
649
+ inner = default_store(self.program, self.env, self.env_prefix)
650
+ return ProfileStore(inner, profile or index.default, on_save=index.add)
598
651
 
599
652
  @staticmethod
600
653
  def _auth_http(options: Mapping[str, Any]) -> SafeHttpClient:
@@ -605,7 +658,11 @@ class CliRuntime:
605
658
  )
606
659
 
607
660
  def credentials(
608
- self, options: Mapping[str, Any], file_settings: Mapping[str, Any], plugin: str = ""
661
+ self,
662
+ options: Mapping[str, Any],
663
+ file_settings: Mapping[str, Any],
664
+ plugin: str = "",
665
+ profile: str | None = None,
609
666
  ) -> ChainAuth:
610
667
  """Build the credential chain: plugin, env, command, OAuth client, saved login."""
611
668
  configured: dict[str, Mapping[str, Any]] = dict(self.auth_config or {})
@@ -624,7 +681,7 @@ class CliRuntime:
624
681
  program=self.program,
625
682
  prefix=self.env_prefix,
626
683
  environ=self.env,
627
- store=self.credential_store(),
684
+ store=self.credential_store(profile),
628
685
  http=self._auth_http(options),
629
686
  plugin=plugin or None,
630
687
  configured=configured,
@@ -828,7 +885,7 @@ class CliRuntime:
828
885
  if name == "describe":
829
886
  header = {
830
887
  "program": self.program,
831
- "version": self.version,
888
+ "version": self.program_version,
832
889
  "api": {"name": self.api_name, "version": self.api_version},
833
890
  "usage": f"{self.program} [global options] COMMAND [arguments]",
834
891
  "global_options": _global_options(parser),
@@ -857,7 +914,7 @@ class CliRuntime:
857
914
  return EXIT_OK
858
915
  doctor = cli_tools.Doctor(
859
916
  program=self.program,
860
- version=self.version,
917
+ version=self.program_version,
861
918
  env_prefix=self.env_prefix,
862
919
  env=self.env,
863
920
  load_model=load_model,
@@ -876,12 +933,14 @@ class CliRuntime:
876
933
  def _auth(self, args: argparse.Namespace, api: Api, fmt: str, out: TextIO, err: TextIO) -> int:
877
934
  options, _ = self.resolve(args)
878
935
  chain = options["auth"]
936
+ profile, _ = self.profile(args, self._file_settings(getattr(args, "config", None)))
879
937
  commands = cli_auth.AuthCommands(
880
938
  program=self.program,
881
939
  prefix=self.env_prefix,
882
940
  api=api,
883
941
  chain=chain,
884
- store=self.credential_store(),
942
+ store=self.credential_store(profile),
943
+ profiles=self.profiles(),
885
944
  http=self._auth_http(options),
886
945
  environ=self.env,
887
946
  configured=self.auth_config or {},
@@ -915,6 +974,7 @@ class CliRuntime:
915
974
  if api.auth_schemes:
916
975
  found[f"{e}_AUTH_PLUGIN"] = "package.module:factory returning an AuthProvider"
917
976
  found[f"{e}_CREDENTIAL_STORE"] = "where auth login saves: keyring, file, or memory"
977
+ found[f"{e}_PROFILE"] = "saved-login profile to use (see auth profiles)"
918
978
  for scheme in api.auth_schemes:
919
979
  variable = auth.variable(scheme)
920
980
  for name, spec in field_specs((self.auth_config or {}).get(scheme.name)).items():
@@ -1,4 +1,6 @@
1
- """The ``auth`` command group of every generated CLI: login, logout, status, token.
1
+ """The ``auth`` command group of every generated CLI: login, logout, status, token, and more.
2
+
3
+ Actions: ``login``, ``logout``, ``status``, ``token``, ``profiles``, ``use``.
2
4
 
3
5
  ``login`` saves a credential so later commands need no environment variables:
4
6
 
@@ -13,6 +15,10 @@
13
15
 
14
16
  Secrets go to the OS keyring when the ``keyring`` package is available, and to
15
17
  ``~/.config/<program>/credentials.json`` (mode 0600) otherwise.
18
+
19
+ Each login belongs to a profile (see ``codapact.runtime.profiles``): ``login --new``
20
+ adds an automatically named one, ``--profile NAME`` names or selects one,
21
+ ``profiles`` lists them, and ``use NAME`` changes the default.
16
22
  """
17
23
 
18
24
  from __future__ import annotations
@@ -22,7 +28,7 @@ import getpass
22
28
  import sys
23
29
  import time
24
30
  from collections.abc import Callable, Mapping
25
- from dataclasses import dataclass, replace
31
+ from dataclasses import dataclass, field, replace
26
32
  from typing import Any, TextIO
27
33
 
28
34
  from codapact.core.naming import env_variable
@@ -38,9 +44,17 @@ from codapact.runtime.credentials import (
38
44
  session_key,
39
45
  )
40
46
  from codapact.runtime.errors import AuthError
41
- from codapact.runtime.oauth import OAuth2, Token, TokenEndpoint, TokenStore, grant_for_scheme
47
+ from codapact.runtime.oauth import (
48
+ OAuth2,
49
+ Token,
50
+ TokenEndpoint,
51
+ TokenStore,
52
+ grant_for_scheme,
53
+ store_location,
54
+ )
55
+ from codapact.runtime.profiles import DEFAULT_PROFILE, ProfileIndex, ProfileStore
42
56
 
43
- ACTIONS = ("login", "logout", "status", "token")
57
+ ACTIONS = ("login", "logout", "status", "token", "profiles", "use")
44
58
 
45
59
 
46
60
  def add_auth_commands(
@@ -48,7 +62,7 @@ def add_auth_commands(
48
62
  program: str,
49
63
  add_global_options: Callable[[argparse.ArgumentParser], None],
50
64
  ) -> None:
51
- """Register ``auth login|logout|status|token``."""
65
+ """Register ``auth login|logout|status|token|profiles|use``."""
52
66
  group = commands.add_parser(
53
67
  "auth",
54
68
  help="sign in, sign out, and inspect credentials",
@@ -62,10 +76,17 @@ def add_auth_commands(
62
76
  description="Save a credential for later commands.",
63
77
  epilog=f"examples:\n {program} auth login\n"
64
78
  f" echo $TOKEN | {program} auth login --with-token\n"
65
- f" {program} auth login --flow device_code",
79
+ f" {program} auth login --flow device_code\n"
80
+ f" {program} auth login --new (another account, auto-named)\n"
81
+ f" {program} auth login --profile work",
66
82
  formatter_class=argparse.RawDescriptionHelpFormatter,
67
83
  )
68
84
  login.add_argument("--scheme", help="credential scheme (default: the only one)")
85
+ login.add_argument(
86
+ "--new",
87
+ action="store_true",
88
+ help="save to a new profile, named automatically unless --profile names it",
89
+ )
69
90
  login.add_argument("--with-token", action="store_true", help="read the secret from stdin")
70
91
  login.add_argument("--username", help="username for basic auth")
71
92
  login.add_argument(
@@ -80,12 +101,22 @@ def add_auth_commands(
80
101
  choices=[k.value for k in OAuthFlowKind if k is not OAuthFlowKind.IMPLICIT],
81
102
  help="OAuth flow to run",
82
103
  )
83
- logout = actions.add_parser("logout", help="forget a saved credential")
104
+ logout = actions.add_parser(
105
+ "logout", help="forget a saved credential (all of them removes the profile)"
106
+ )
84
107
  logout.add_argument("--scheme", help="credential scheme (default: all)")
85
108
  status = actions.add_parser("status", help="show where each credential comes from")
86
109
  token = actions.add_parser("token", help="print the credential a command would send")
87
110
  token.add_argument("--scheme", help="credential scheme (default: the only one)")
88
- for parser in (login, logout, status, token):
111
+ profiles = actions.add_parser(
112
+ "profiles",
113
+ help="list saved-login profiles and the default",
114
+ description="List profiles. Pick one per command with --profile NAME or "
115
+ "the PREFIX_PROFILE environment variable.",
116
+ )
117
+ use = actions.add_parser("use", help="make a profile the default")
118
+ use.add_argument("name", metavar="NAME", help="profile name")
119
+ for parser in (login, logout, status, token, profiles, use):
89
120
  add_global_options(parser)
90
121
  parser.set_defaults(builtin="auth")
91
122
 
@@ -102,6 +133,7 @@ class AuthCommands:
102
133
  http: Transport
103
134
  environ: Mapping[str, str]
104
135
  configured: Mapping[str, Mapping[str, Any]]
136
+ profiles: ProfileIndex = field(default_factory=lambda: ProfileIndex(None))
105
137
  stdin: TextIO | None = None
106
138
  err: TextIO | None = None
107
139
  prompt: Callable[[str], str] = input
@@ -110,12 +142,79 @@ class AuthCommands:
110
142
  def run(self, args: argparse.Namespace) -> Any:
111
143
  """Return the data to render for ``args.auth_action`` (never a secret)."""
112
144
  self._require_schemes()
145
+ self._adopt_legacy()
113
146
  action = args.auth_action
147
+ if action == "profiles":
148
+ return self.list_profiles()
149
+ if action == "use":
150
+ self.profiles.use(args.name)
151
+ return {"default": args.name}
114
152
  if action == "status":
115
153
  return self.status()
116
154
  if action == "logout":
117
155
  return self.logout(args.scheme)
118
- return self.login(self.scheme(args.scheme), args)
156
+ if getattr(args, "new", False):
157
+ self.store = self._new_profile(getattr(args, "profile", None))
158
+ result = self._scoped(self.login(self.scheme(args.scheme), args))
159
+ if self.profile and self.profile != self.profiles.default:
160
+ result["note"] = (
161
+ f"{self.profile} is not the default profile: pass --profile {self.profile}, "
162
+ f"or run {self.program} auth use {self.profile}"
163
+ )
164
+ return result
165
+
166
+ @property
167
+ def profile(self) -> str:
168
+ """The profile this command works on."""
169
+ return str(getattr(self.store, "profile", ""))
170
+
171
+ def _adopt_legacy(self) -> None:
172
+ """Move logins saved before profiles into ``default`` and register it.
173
+
174
+ Runs before any profile is created or listed, so an upgrade never makes a new
175
+ profile the default over (or overwrite) the login the user already had.
176
+ """
177
+ if not isinstance(self.store, ProfileStore):
178
+ return
179
+ view = ProfileStore(self.store.inner, DEFAULT_PROFILE, on_save=self.profiles.add)
180
+ for scheme in self.api.auth_schemes:
181
+ view.load(scheme.name)
182
+ view.load(session_key(scheme.name))
183
+
184
+ def _scoped(self, data: dict[str, Any]) -> dict[str, Any]:
185
+ """Put the profile first in ``data`` when the store has profiles."""
186
+ return {"profile": self.profile, **data} if self.profile else data
187
+
188
+ def _new_profile(self, name: str | None) -> TokenStore:
189
+ if not isinstance(self.store, ProfileStore):
190
+ raise AuthError("this credential store has no profiles")
191
+ if name and name in self.profiles.names:
192
+ raise AuthError(f"profile {name!r} already exists; drop --new to replace its login")
193
+ chosen = name or self.profiles.next_name()
194
+ return ProfileStore(self.store.inner, chosen, on_save=self.profiles.add)
195
+
196
+ def list_profiles(self) -> list[dict[str, Any]]:
197
+ """Each known profile, whether it is the default, and which schemes it has saved."""
198
+ names = self.profiles.names or [self.profiles.default]
199
+ if self.profile and self.profile not in names:
200
+ names.append(self.profile)
201
+ inner = self.store.inner if isinstance(self.store, ProfileStore) else None
202
+ rows = []
203
+ for name in names:
204
+ view = (
205
+ ProfileStore(inner, name, on_save=self.profiles.add)
206
+ if inner is not None
207
+ else self.store
208
+ )
209
+ saved = [s.name for s in self.api.auth_schemes if view.load(s.name) is not None]
210
+ rows.append(
211
+ {
212
+ "profile": name,
213
+ "default": name == self.profiles.default,
214
+ "saved": ", ".join(saved) or "nothing",
215
+ }
216
+ )
217
+ return rows
119
218
 
120
219
  def secret(self, args: argparse.Namespace) -> str:
121
220
  """Return the credential ``auth token`` prints, kept apart from rendered data."""
@@ -145,12 +244,14 @@ class AuthCommands:
145
244
  rows = []
146
245
  for scheme in self.api.auth_schemes:
147
246
  source = describe_source(self.chain, scheme)
148
- row: dict[str, Any] = {
149
- "scheme": scheme.name,
150
- "kind": scheme.kind.value,
151
- "status": _status(source),
152
- "source": source or self.chain.hint(scheme) or "not configured",
153
- }
247
+ row: dict[str, Any] = self._scoped(
248
+ {
249
+ "scheme": scheme.name,
250
+ "kind": scheme.kind.value,
251
+ "status": _status(source),
252
+ "source": source or self.chain.hint(scheme) or "not configured",
253
+ }
254
+ )
154
255
  stored = self.store.load(scheme.name)
155
256
  token = Token.from_data(stored) if stored and stored.get("type") == "oauth2" else None
156
257
  if token is not None and token.expires_at is not None:
@@ -184,7 +285,11 @@ class AuthCommands:
184
285
  session = self.store.delete(session_key(scheme.name))
185
286
  if self.store.delete(scheme.name) or session:
186
287
  removed.append(scheme.name)
187
- return {"removed": removed}
288
+ result = self._scoped({"removed": removed})
289
+ if not name and self.profile and self.profiles.remove(self.profile):
290
+ result["profile_removed"] = True
291
+ result["default"] = self.profiles.default
292
+ return result
188
293
 
189
294
  def token(self, scheme: AuthScheme) -> str:
190
295
  """Return the secret a request would carry."""
@@ -222,7 +327,7 @@ class AuthCommands:
222
327
  else:
223
328
  secret = self._read_secret(args.with_token, f"{scheme.name} token: ")
224
329
  self.store.save(scheme.name, {"type": "token", "secret": secret})
225
- return {"scheme": scheme.name, "saved": _location(self.store)}
330
+ return {"scheme": scheme.name, "saved": _location(self.store, scheme.name)}
226
331
 
227
332
  def _fields_login(
228
333
  self, scheme: AuthScheme, spec: Mapping[str, Mapping[str, Any]], given: list[str]
@@ -260,7 +365,11 @@ class AuthCommands:
260
365
  raise AuthError(f"{name} is required")
261
366
  self.store.save(scheme.name, {"type": "fields", "fields": values})
262
367
  self.store.delete(session_key(scheme.name)) # new values: drop the old session
263
- return {"scheme": scheme.name, "saved": _location(self.store), "fields": list(values)}
368
+ return {
369
+ "scheme": scheme.name,
370
+ "saved": _location(self.store, scheme.name),
371
+ "fields": list(values),
372
+ }
264
373
 
265
374
  def _read_secret(self, from_stdin: bool, label: str) -> str:
266
375
  if from_stdin:
@@ -296,7 +405,10 @@ class AuthCommands:
296
405
  metadata={"token_url": grant.token_url, "client_id": settings.client_id},
297
406
  )
298
407
  token = session.login()
299
- result: dict[str, Any] = {"scheme": scheme.name, "saved": _location(self.store)}
408
+ result: dict[str, Any] = {
409
+ "scheme": scheme.name,
410
+ "saved": _location(self.store, scheme.name),
411
+ }
300
412
  result["flow"] = type(grant).__name__
301
413
  if token.expires_at is not None:
302
414
  result["expires_in"] = int(token.expires_at - time.time())
@@ -310,8 +422,8 @@ def _status(source: str | None) -> str:
310
422
  return "error" if source.startswith("error") else "ok"
311
423
 
312
424
 
313
- def _location(store: TokenStore) -> str:
314
- return str(getattr(store, "location", type(store).__name__))
425
+ def _location(store: TokenStore, key: str | None = None) -> str:
426
+ return store_location(store, key)
315
427
 
316
428
 
317
429
  __all__ = ["ACTIONS", "AuthCommands", "add_auth_commands"]
@@ -495,6 +495,8 @@ class Doctor:
495
495
  return checks
496
496
  base_url = options.get("base_url") or (api.servers[0].url if api.servers else "")
497
497
  base_ok = self._base_url(checks, base_url, sources.get("base_url", "contract"), options)
498
+ if api.auth_schemes and sources.get("profile"):
499
+ checks.append(Check("profile", "info", sources["profile"]))
498
500
  checks.extend(self._credentials(api, options.get("auth")))
499
501
  scheme = urlsplit(base_url).scheme if base_ok else ""
500
502
  proxy = urllib.request.getproxies_environment().get(scheme) if scheme else None
@@ -35,6 +35,7 @@ from codapact.runtime.oauth import (
35
35
  TokenEndpoint,
36
36
  TokenStore,
37
37
  grant_for_scheme,
38
+ store_location,
38
39
  )
39
40
 
40
41
  COMMAND_TIMEOUT = 60.0
@@ -370,8 +371,7 @@ def _provider_label(provider: AuthProvider, scheme: AuthScheme) -> str:
370
371
  case OAuthClientAuth():
371
372
  return "OAuth client credentials"
372
373
  case StoreAuth():
373
- location = getattr(provider.store, "location", "credential store")
374
- return f"saved login ({location})"
374
+ return f"saved login ({store_location(provider.store, scheme.name)})"
375
375
  case _:
376
376
  pass
377
377
  return f"auth plugin ({type(provider).__name__})"