codapact 0.6.0__tar.gz → 0.7.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.7.0/.release-please-manifest.json +1 -0
  2. {codapact-0.6.0 → codapact-0.7.0}/CHANGELOG.md +14 -0
  3. {codapact-0.6.0 → codapact-0.7.0}/PKG-INFO +1 -1
  4. {codapact-0.6.0 → codapact-0.7.0}/docs/configuration.md +33 -7
  5. {codapact-0.6.0 → codapact-0.7.0}/pyproject.toml +1 -1
  6. {codapact-0.6.0 → codapact-0.7.0}/pyproject.toml.orig +1 -1
  7. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/__init__.py +1 -1
  8. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/commands/derive.py +1 -0
  9. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/cli.py +50 -8
  10. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/cli_auth.py +133 -21
  11. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/cli_tools.py +2 -0
  12. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/credentials.py +2 -2
  13. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/oauth.py +84 -16
  14. codapact-0.7.0/src/codapact/runtime/profiles.py +224 -0
  15. {codapact-0.6.0 → codapact-0.7.0}/tests/e2e/test_auth_e2e.py +44 -1
  16. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_cli_auth.py +16 -4
  17. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_cli_options.py +12 -2
  18. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_oauth.py +54 -7
  19. codapact-0.7.0/tests/unit/test_profiles.py +302 -0
  20. {codapact-0.6.0 → codapact-0.7.0}/uv.lock +1 -1
  21. codapact-0.6.0/.release-please-manifest.json +0 -1
  22. {codapact-0.6.0 → codapact-0.7.0}/.github/workflows/ci.yml +0 -0
  23. {codapact-0.6.0 → codapact-0.7.0}/.github/workflows/codeql.yml +0 -0
  24. {codapact-0.6.0 → codapact-0.7.0}/.github/workflows/mutation.yml +0 -0
  25. {codapact-0.6.0 → codapact-0.7.0}/.github/workflows/nightly.yml +0 -0
  26. {codapact-0.6.0 → codapact-0.7.0}/.github/workflows/release.yml +0 -0
  27. {codapact-0.6.0 → codapact-0.7.0}/LICENSE +0 -0
  28. {codapact-0.6.0 → codapact-0.7.0}/README.md +0 -0
  29. {codapact-0.6.0 → codapact-0.7.0}/docs/architecture.md +0 -0
  30. {codapact-0.6.0 → codapact-0.7.0}/docs/branding/README.md +0 -0
  31. {codapact-0.6.0 → codapact-0.7.0}/docs/branding/mark.svg +0 -0
  32. {codapact-0.6.0 → codapact-0.7.0}/docs/branding/wordmark.svg +0 -0
  33. {codapact-0.6.0 → codapact-0.7.0}/docs/testing.md +0 -0
  34. {codapact-0.6.0 → codapact-0.7.0}/examples/library/codapact.yaml +0 -0
  35. {codapact-0.6.0 → codapact-0.7.0}/examples/library/operations.graphql +0 -0
  36. {codapact-0.6.0 → codapact-0.7.0}/examples/library/schema.graphql +0 -0
  37. {codapact-0.6.0 → codapact-0.7.0}/examples/petstore/codapact.yaml +0 -0
  38. {codapact-0.6.0 → codapact-0.7.0}/examples/petstore/openapi.yaml +0 -0
  39. {codapact-0.6.0 → codapact-0.7.0}/release-please-config.json +0 -0
  40. {codapact-0.6.0 → codapact-0.7.0}/scripts/extract_openapi_subset.py +0 -0
  41. {codapact-0.6.0 → codapact-0.7.0}/scripts/mutation_score.py +0 -0
  42. {codapact-0.6.0 → codapact-0.7.0}/scripts/verify_dist.py +0 -0
  43. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/__main__.py +0 -0
  44. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/commands/__init__.py +0 -0
  45. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/commands/model.py +0 -0
  46. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/core/__init__.py +0 -0
  47. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/core/diagnostics.py +0 -0
  48. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/core/errors.py +0 -0
  49. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/core/naming.py +0 -0
  50. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/core/net.py +0 -0
  51. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/model/__init__.py +0 -0
  52. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/model/api.py +0 -0
  53. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/model/authspec.py +0 -0
  54. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/model/migrations.py +0 -0
  55. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/model/rewrite.py +0 -0
  56. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/model/serialize.py +0 -0
  57. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/model/types.py +0 -0
  58. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/model/validate.py +0 -0
  59. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/model/values.py +0 -0
  60. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/pipeline/__init__.py +0 -0
  61. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/pipeline/cli.py +0 -0
  62. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/pipeline/config.py +0 -0
  63. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/pipeline/defaults.py +0 -0
  64. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/pipeline/pipeline.py +0 -0
  65. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/pipeline/sync.py +0 -0
  66. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/pipeline/writer.py +0 -0
  67. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/plugins/__init__.py +0 -0
  68. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/plugins/external.py +0 -0
  69. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/plugins/protocol.py +0 -0
  70. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/plugins/registry.py +0 -0
  71. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/py.typed +0 -0
  72. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/__init__.py +0 -0
  73. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/abstractions.py +0 -0
  74. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/arguments.py +0 -0
  75. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/auth.py +0 -0
  76. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/client.py +0 -0
  77. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/codec.py +0 -0
  78. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/errors.py +0 -0
  79. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/middleware.py +0 -0
  80. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/protocols/__init__.py +0 -0
  81. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/protocols/base.py +0 -0
  82. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/protocols/graphql.py +0 -0
  83. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/protocols/http.py +0 -0
  84. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/runtime/selftest.py +0 -0
  85. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/shaping/__init__.py +0 -0
  86. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/shaping/base.py +0 -0
  87. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/shaping/engine.py +0 -0
  88. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/shaping/transforms.py +0 -0
  89. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/sources/__init__.py +0 -0
  90. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/sources/base.py +0 -0
  91. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/sources/graphql/__init__.py +0 -0
  92. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/sources/graphql/translator.py +0 -0
  93. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/sources/loader.py +0 -0
  94. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/sources/openapi/__init__.py +0 -0
  95. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/sources/openapi/translator.py +0 -0
  96. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/surface/__init__.py +0 -0
  97. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/surface/derive.py +0 -0
  98. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/surface/model.py +0 -0
  99. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/targets/__init__.py +0 -0
  100. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/targets/python/__init__.py +0 -0
  101. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/targets/python/cli.py +0 -0
  102. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/targets/python/e2e.py +0 -0
  103. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/targets/python/library.py +0 -0
  104. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/targets/python/naming.py +0 -0
  105. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/targets/typescript/__init__.py +0 -0
  106. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/targets/typescript/library.py +0 -0
  107. {codapact-0.6.0 → codapact-0.7.0}/src/codapact/targets/typescript/runtime.ts +0 -0
  108. {codapact-0.6.0 → codapact-0.7.0}/tests/authlab.py +0 -0
  109. {codapact-0.6.0 → codapact-0.7.0}/tests/conftest.py +0 -0
  110. {codapact-0.6.0 → codapact-0.7.0}/tests/e2e/test_cli_e2e.py +0 -0
  111. {codapact-0.6.0 → codapact-0.7.0}/tests/e2e/test_public_apis.py +0 -0
  112. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/authlab/authlab_plugin.py +0 -0
  113. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/authlab/codapact.yaml +0 -0
  114. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/authlab/fake_browser.py +0 -0
  115. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/authlab/openapi.yaml +0 -0
  116. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/authlab_smoke.ts +0 -0
  117. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/contracts/wire.yaml +0 -0
  118. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/corpus/README.md +0 -0
  119. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/corpus/countries/codapact.yaml +0 -0
  120. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/corpus/countries/operations.graphql +0 -0
  121. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/corpus/countries/schema.graphql +0 -0
  122. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/corpus/github/codapact.yaml +0 -0
  123. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/corpus/github/openapi.json +0 -0
  124. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/corpus/pokeapi/codapact.yaml +0 -0
  125. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/corpus/pokeapi/openapi.yml +0 -0
  126. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/corpus/ynab/README.md +0 -0
  127. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/corpus/ynab/codapact.yaml +0 -0
  128. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/corpus/ynab/openapi.yaml +0 -0
  129. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/library_smoke.ts +0 -0
  130. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/outline_plugin.py +0 -0
  131. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/petstore_smoke.ts +0 -0
  132. {codapact-0.6.0 → codapact-0.7.0}/tests/fixtures/wire_parity.ts +0 -0
  133. {codapact-0.6.0 → codapact-0.7.0}/tests/integration/test_cli_conformance.py +0 -0
  134. {codapact-0.6.0 → codapact-0.7.0}/tests/integration/test_cli_conventions.py +0 -0
  135. {codapact-0.6.0 → codapact-0.7.0}/tests/integration/test_contract_properties.py +0 -0
  136. {codapact-0.6.0 → codapact-0.7.0}/tests/integration/test_corpus.py +0 -0
  137. {codapact-0.6.0 → codapact-0.7.0}/tests/integration/test_generated_code_properties.py +0 -0
  138. {codapact-0.6.0 → codapact-0.7.0}/tests/integration/test_generation.py +0 -0
  139. {codapact-0.6.0 → codapact-0.7.0}/tests/integration/test_public_api_cli.py +0 -0
  140. {codapact-0.6.0 → codapact-0.7.0}/tests/integration/test_wire_parity.py +0 -0
  141. {codapact-0.6.0 → codapact-0.7.0}/tests/integration/test_ynab_contract.py +0 -0
  142. {codapact-0.6.0 → codapact-0.7.0}/tests/perf/test_scaling.py +0 -0
  143. {codapact-0.6.0 → codapact-0.7.0}/tests/public_api_contract.py +0 -0
  144. {codapact-0.6.0 → codapact-0.7.0}/tests/strategies.py +0 -0
  145. {codapact-0.6.0 → codapact-0.7.0}/tests/support.py +0 -0
  146. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_architecture.py +0 -0
  147. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_auth_and_graphql_sources.py +0 -0
  148. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_auth_sources.py +0 -0
  149. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_bundle_e2e.py +0 -0
  150. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_cli_builtins.py +0 -0
  151. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_codec_serialize.py +0 -0
  152. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_core.py +0 -0
  153. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_credential_fields.py +0 -0
  154. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_env_prefix.py +0 -0
  155. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_guards.py +0 -0
  156. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_live_ynab_findings.py +0 -0
  157. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_model.py +0 -0
  158. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_mutation_score.py +0 -0
  159. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_openapi_edges.py +0 -0
  160. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_openapi_translator_units.py +0 -0
  161. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_plugins_pipeline.py +0 -0
  162. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_public_api_findings.py +0 -0
  163. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_runtime.py +0 -0
  164. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_runtime_edges.py +0 -0
  165. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_runtime_pagination.py +0 -0
  166. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_shaping_surface_commands.py +0 -0
  167. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_sources.py +0 -0
  168. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_sync.py +0 -0
  169. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_target_rendering.py +0 -0
  170. {codapact-0.6.0 → codapact-0.7.0}/tests/unit/test_usability.py +0 -0
@@ -0,0 +1 @@
1
+ {".":"0.7.0"}
@@ -2,6 +2,20 @@
2
2
 
3
3
  <!-- markdownlint-configure-file { "MD024": { "siblings_only": true } } -->
4
4
 
5
+ ## [0.7.0](https://github.com/mikejhill/codapact/compare/v0.6.1...v0.7.0) (2026-11-14)
6
+
7
+
8
+ ### Features
9
+
10
+ * **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))
11
+
12
+ ## [0.6.1](https://github.com/mikejhill/codapact/compare/v0.6.0...v0.6.1) (2026-11-14)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **auth:** namespace keyring entries as codapact:PROGRAM:SCHEME ([#45](https://github.com/mikejhill/codapact/issues/45)) ([8c46322](https://github.com/mikejhill/codapact/commit/8c463221052a017e2a5626e888f76eb26bc84c43))
18
+
5
19
  ## [0.6.0](https://github.com/mikejhill/codapact/compare/v0.5.2...v0.6.0) (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.0
3
+ Version: 0.7.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;
@@ -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,9 +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, otherwise to a
286
- `0600` JSON file at `$XDG_CONFIG_HOME/<program>/credentials.json`.
287
- `<PREFIX>_CREDENTIAL_STORE=keyring|file|memory` forces one.
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.
288
314
 
289
315
  Libraries take the same objects directly:
290
316
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "codapact"
3
- version = "0.6.0"
3
+ version = "0.7.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.0"
3
+ version = "0.7.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.0"
8
+ __version__ = "0.7.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"})
@@ -45,6 +45,7 @@ from codapact.runtime.errors import (
45
45
  )
46
46
  from codapact.runtime.middleware import Retry
47
47
  from codapact.runtime.oauth import TokenStore, default_store
48
+ from codapact.runtime.profiles import ProfileIndex, ProfileStore, check_profile_name, profiles_path
48
49
 
49
50
  EXIT_OK = 0
50
51
  EXIT_API = 1
@@ -78,6 +79,7 @@ SETTINGS_KEYS = frozenset(
78
79
  "defaults",
79
80
  "auth_plugin",
80
81
  "auth",
82
+ "profile",
81
83
  }
82
84
  )
83
85
 
@@ -425,6 +427,12 @@ class CliRuntime:
425
427
  default=keep,
426
428
  help=text(f"request timeout in seconds (env {e}_TIMEOUT)"),
427
429
  )
430
+ group.add_argument(
431
+ "--profile",
432
+ default=keep,
433
+ metavar="NAME",
434
+ help=text(f"saved-login profile to use (env {e}_PROFILE; default: auth use)"),
435
+ )
428
436
  group.add_argument(
429
437
  "--config", default=keep, metavar="FILE", help=text("settings file (default: XDG dir)")
430
438
  )
@@ -446,7 +454,8 @@ class CliRuntime:
446
454
  options = (
447
455
  f"-o/--output {{{','.join(OUTPUT_FORMATS)}}}, --query PATH, --pick KEYS, "
448
456
  "--dry-run, -v/--verbose, "
449
- "--error-format {text,json}, --base-url URL, --timeout SECONDS, --config FILE, "
457
+ "--error-format {text,json}, --base-url URL, --timeout SECONDS, --profile NAME, "
458
+ "--config FILE, "
450
459
  "--allow-private, --response-validation {strict,warn,off}"
451
460
  )
452
461
  body = textwrap.fill(
@@ -589,12 +598,38 @@ class CliRuntime:
589
598
  plugin, sources["auth_plugin"] = self._setting(args, file_settings, "auth_plugin")
590
599
  if not plugin and self.auth_plugin:
591
600
  plugin, sources["auth_plugin"] = self.auth_plugin, "generated default"
592
- options["auth"] = self.credentials(options, file_settings, str(plugin or ""))
601
+ profile, source = self.profile(args, file_settings)
602
+ sources["profile"] = f"{profile} (from {source})"
603
+ options["auth"] = self.credentials(options, file_settings, str(plugin or ""), profile)
593
604
  return options, sources
594
605
 
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)
606
+ def profiles(self) -> ProfileIndex:
607
+ """Return the list of saved-login profiles and the default one."""
608
+ memory = self.env.get(f"{self.env_prefix}_CREDENTIAL_STORE", "").lower() == "memory"
609
+ return ProfileIndex(None if memory else profiles_path(self.program, self.env))
610
+
611
+ def profile(self, args: argparse.Namespace, file_settings: dict[str, Any]) -> tuple[str, str]:
612
+ """Return the profile in effect and where it came from.
613
+
614
+ A profile named explicitly must exist, except for ``auth login``, which creates it.
615
+ """
616
+ index = self.profiles()
617
+ name, source = self._setting(args, file_settings, "profile")
618
+ if name is None:
619
+ return index.default, "profiles default" if index.names else "default"
620
+ name = check_profile_name(str(name))
621
+ if not index.known(name) and getattr(args, "auth_action", None) != "login":
622
+ raise index.unknown(name)
623
+ return name, source
624
+
625
+ def credential_store(self, profile: str | None = None) -> TokenStore:
626
+ """Return where ``auth login`` saves secrets for ``profile`` (default: the default).
627
+
628
+ The OS keyring or a 0600 file, with keys scoped to the profile.
629
+ """
630
+ index = self.profiles()
631
+ inner = default_store(self.program, self.env, self.env_prefix)
632
+ return ProfileStore(inner, profile or index.default, on_save=index.add)
598
633
 
599
634
  @staticmethod
600
635
  def _auth_http(options: Mapping[str, Any]) -> SafeHttpClient:
@@ -605,7 +640,11 @@ class CliRuntime:
605
640
  )
606
641
 
607
642
  def credentials(
608
- self, options: Mapping[str, Any], file_settings: Mapping[str, Any], plugin: str = ""
643
+ self,
644
+ options: Mapping[str, Any],
645
+ file_settings: Mapping[str, Any],
646
+ plugin: str = "",
647
+ profile: str | None = None,
609
648
  ) -> ChainAuth:
610
649
  """Build the credential chain: plugin, env, command, OAuth client, saved login."""
611
650
  configured: dict[str, Mapping[str, Any]] = dict(self.auth_config or {})
@@ -624,7 +663,7 @@ class CliRuntime:
624
663
  program=self.program,
625
664
  prefix=self.env_prefix,
626
665
  environ=self.env,
627
- store=self.credential_store(),
666
+ store=self.credential_store(profile),
628
667
  http=self._auth_http(options),
629
668
  plugin=plugin or None,
630
669
  configured=configured,
@@ -876,12 +915,14 @@ class CliRuntime:
876
915
  def _auth(self, args: argparse.Namespace, api: Api, fmt: str, out: TextIO, err: TextIO) -> int:
877
916
  options, _ = self.resolve(args)
878
917
  chain = options["auth"]
918
+ profile, _ = self.profile(args, self._file_settings(getattr(args, "config", None)))
879
919
  commands = cli_auth.AuthCommands(
880
920
  program=self.program,
881
921
  prefix=self.env_prefix,
882
922
  api=api,
883
923
  chain=chain,
884
- store=self.credential_store(),
924
+ store=self.credential_store(profile),
925
+ profiles=self.profiles(),
885
926
  http=self._auth_http(options),
886
927
  environ=self.env,
887
928
  configured=self.auth_config or {},
@@ -915,6 +956,7 @@ class CliRuntime:
915
956
  if api.auth_schemes:
916
957
  found[f"{e}_AUTH_PLUGIN"] = "package.module:factory returning an AuthProvider"
917
958
  found[f"{e}_CREDENTIAL_STORE"] = "where auth login saves: keyring, file, or memory"
959
+ found[f"{e}_PROFILE"] = "saved-login profile to use (see auth profiles)"
918
960
  for scheme in api.auth_schemes:
919
961
  variable = auth.variable(scheme)
920
962
  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__})"