codapact 0.6.0__tar.gz → 0.6.1__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.
- codapact-0.6.1/.release-please-manifest.json +1 -0
- {codapact-0.6.0 → codapact-0.6.1}/CHANGELOG.md +7 -0
- {codapact-0.6.0 → codapact-0.6.1}/PKG-INFO +1 -1
- {codapact-0.6.0 → codapact-0.6.1}/docs/configuration.md +5 -2
- {codapact-0.6.0 → codapact-0.6.1}/pyproject.toml +1 -1
- {codapact-0.6.0 → codapact-0.6.1}/pyproject.toml.orig +1 -1
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/__init__.py +1 -1
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/oauth.py +63 -16
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_oauth.py +53 -7
- {codapact-0.6.0 → codapact-0.6.1}/uv.lock +1 -1
- codapact-0.6.0/.release-please-manifest.json +0 -1
- {codapact-0.6.0 → codapact-0.6.1}/.github/workflows/ci.yml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/.github/workflows/codeql.yml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/.github/workflows/mutation.yml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/.github/workflows/nightly.yml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/.github/workflows/release.yml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/LICENSE +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/README.md +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/docs/architecture.md +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/docs/branding/README.md +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/docs/branding/mark.svg +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/docs/branding/wordmark.svg +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/docs/testing.md +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/examples/library/codapact.yaml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/examples/library/operations.graphql +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/examples/library/schema.graphql +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/examples/petstore/codapact.yaml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/examples/petstore/openapi.yaml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/release-please-config.json +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/scripts/extract_openapi_subset.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/scripts/mutation_score.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/scripts/verify_dist.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/__main__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/commands/__init__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/commands/derive.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/commands/model.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/core/__init__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/core/diagnostics.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/core/errors.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/core/naming.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/core/net.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/model/__init__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/model/api.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/model/authspec.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/model/migrations.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/model/rewrite.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/model/serialize.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/model/types.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/model/validate.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/model/values.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/pipeline/__init__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/pipeline/cli.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/pipeline/config.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/pipeline/defaults.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/pipeline/pipeline.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/pipeline/sync.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/pipeline/writer.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/plugins/__init__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/plugins/external.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/plugins/protocol.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/plugins/registry.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/py.typed +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/__init__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/abstractions.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/arguments.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/auth.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/cli.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/cli_auth.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/cli_tools.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/client.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/codec.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/credentials.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/errors.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/middleware.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/protocols/__init__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/protocols/base.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/protocols/graphql.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/protocols/http.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/runtime/selftest.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/shaping/__init__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/shaping/base.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/shaping/engine.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/shaping/transforms.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/sources/__init__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/sources/base.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/sources/graphql/__init__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/sources/graphql/translator.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/sources/loader.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/sources/openapi/__init__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/sources/openapi/translator.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/surface/__init__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/surface/derive.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/surface/model.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/targets/__init__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/targets/python/__init__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/targets/python/cli.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/targets/python/e2e.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/targets/python/library.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/targets/python/naming.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/targets/typescript/__init__.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/targets/typescript/library.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/src/codapact/targets/typescript/runtime.ts +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/authlab.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/conftest.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/e2e/test_auth_e2e.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/e2e/test_cli_e2e.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/e2e/test_public_apis.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/authlab/authlab_plugin.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/authlab/codapact.yaml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/authlab/fake_browser.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/authlab/openapi.yaml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/authlab_smoke.ts +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/contracts/wire.yaml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/corpus/README.md +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/corpus/countries/codapact.yaml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/corpus/countries/operations.graphql +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/corpus/countries/schema.graphql +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/corpus/github/codapact.yaml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/corpus/github/openapi.json +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/corpus/pokeapi/codapact.yaml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/corpus/pokeapi/openapi.yml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/corpus/ynab/README.md +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/corpus/ynab/codapact.yaml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/corpus/ynab/openapi.yaml +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/library_smoke.ts +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/outline_plugin.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/petstore_smoke.ts +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/fixtures/wire_parity.ts +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/integration/test_cli_conformance.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/integration/test_cli_conventions.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/integration/test_contract_properties.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/integration/test_corpus.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/integration/test_generated_code_properties.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/integration/test_generation.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/integration/test_public_api_cli.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/integration/test_wire_parity.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/integration/test_ynab_contract.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/perf/test_scaling.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/public_api_contract.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/strategies.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/support.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_architecture.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_auth_and_graphql_sources.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_auth_sources.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_bundle_e2e.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_cli_auth.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_cli_builtins.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_cli_options.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_codec_serialize.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_core.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_credential_fields.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_env_prefix.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_guards.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_live_ynab_findings.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_model.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_mutation_score.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_openapi_edges.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_openapi_translator_units.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_plugins_pipeline.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_public_api_findings.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_runtime.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_runtime_edges.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_runtime_pagination.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_shaping_surface_commands.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_sources.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_sync.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_target_rendering.py +0 -0
- {codapact-0.6.0 → codapact-0.6.1}/tests/unit/test_usability.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{".":"0.6.1"}
|
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- markdownlint-configure-file { "MD024": { "siblings_only": true } } -->
|
|
4
4
|
|
|
5
|
+
## [0.6.1](https://github.com/mikejhill/codapact/compare/v0.6.0...v0.6.1) (2026-11-14)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **auth:** namespace keyring entries as codapact:PROGRAM:SCHEME ([#45](https://github.com/mikejhill/codapact/issues/45)) ([8c46322](https://github.com/mikejhill/codapact/commit/8c463221052a017e2a5626e888f76eb26bc84c43))
|
|
11
|
+
|
|
5
12
|
## [0.6.0](https://github.com/mikejhill/codapact/compare/v0.5.2...v0.6.0) (2026-11-14)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -282,9 +282,12 @@ The sign-in itself (multi-step forms, SSO, redirects, MFA) stays in the plugin;
|
|
|
282
282
|
supply and store its inputs. Field names are lower snake case; `secret`, `optional` and `help`
|
|
283
283
|
are the only keys.
|
|
284
284
|
|
|
285
|
-
Saved credentials and tokens go to the OS keyring when one is usable,
|
|
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
|
|
286
288
|
`0600` JSON file at `$XDG_CONFIG_HOME/<program>/credentials.json`.
|
|
287
|
-
`<PREFIX>_CREDENTIAL_STORE=keyring|file|memory` forces one.
|
|
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.
|
|
288
291
|
|
|
289
292
|
Libraries take the same objects directly:
|
|
290
293
|
|
|
@@ -202,20 +202,41 @@ class FileTokenStore:
|
|
|
202
202
|
return True
|
|
203
203
|
|
|
204
204
|
|
|
205
|
+
KEYRING_NAMESPACE = "codapact"
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def keyring_service(program: str) -> str:
|
|
209
|
+
"""The keyring namespace of a generated CLI: ``codapact:<program>``."""
|
|
210
|
+
return f"{KEYRING_NAMESPACE}:{program}"
|
|
211
|
+
|
|
212
|
+
|
|
205
213
|
@dataclass(frozen=True, slots=True)
|
|
206
214
|
class KeyringTokenStore:
|
|
207
|
-
"""The OS keyring (macOS Keychain, Windows Credential
|
|
215
|
+
"""The OS keyring (macOS Keychain, Windows Credential Manager, Secret Service).
|
|
216
|
+
|
|
217
|
+
Each key is its own entry, with service ``<service>:<key>`` and the key as
|
|
218
|
+
user name, so entries read as ``codapact:ynab:bearer`` in Windows Credential
|
|
219
|
+
Manager or Keychain Access and never collide with other applications.
|
|
220
|
+
|
|
221
|
+
``legacy_service`` names where older versions saved (service ``<program>``,
|
|
222
|
+
user name ``<key>``): an entry found only there is moved to the new name the
|
|
223
|
+
first time it is read, and ``save``/``delete`` remove the old entry too.
|
|
208
224
|
|
|
209
225
|
Needs the optional ``keyring`` package.
|
|
210
226
|
"""
|
|
211
227
|
|
|
212
228
|
service: str
|
|
213
229
|
backend: Any = None
|
|
230
|
+
legacy_service: str | None = None
|
|
214
231
|
|
|
215
232
|
@property
|
|
216
233
|
def location(self) -> str:
|
|
217
234
|
"""Describe where secrets live."""
|
|
218
|
-
return f"keyring service {self.service!r}"
|
|
235
|
+
return f"keyring service {self.service + ':<scheme>'!r}"
|
|
236
|
+
|
|
237
|
+
def entry(self, key: str) -> str:
|
|
238
|
+
"""The keyring service name that holds ``key``."""
|
|
239
|
+
return f"{self.service}:{key}"
|
|
219
240
|
|
|
220
241
|
def _keyring(self) -> Any:
|
|
221
242
|
if self.backend is not None:
|
|
@@ -227,29 +248,54 @@ class KeyringTokenStore:
|
|
|
227
248
|
return keyring
|
|
228
249
|
|
|
229
250
|
def load(self, key: str) -> dict[str, Any] | None:
|
|
230
|
-
"""Return the stored data for ``key
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
251
|
+
"""Return the stored data for ``key``, moving a legacy entry to its new name."""
|
|
252
|
+
backend = self._keyring()
|
|
253
|
+
data = _decode(backend.get_password(self.entry(key), key))
|
|
254
|
+
if data is not None or not self.legacy_service:
|
|
255
|
+
return data
|
|
256
|
+
data = _decode(backend.get_password(self.legacy_service, key))
|
|
257
|
+
if data is not None:
|
|
258
|
+
backend.set_password(self.entry(key), key, json.dumps(data, sort_keys=True))
|
|
259
|
+
self._drop_legacy(backend, key)
|
|
260
|
+
return data
|
|
239
261
|
|
|
240
262
|
def save(self, key: str, data: dict[str, Any]) -> None:
|
|
241
263
|
"""Store ``data`` under ``key``."""
|
|
242
|
-
self._keyring()
|
|
264
|
+
backend = self._keyring()
|
|
265
|
+
backend.set_password(self.entry(key), key, json.dumps(data, sort_keys=True))
|
|
266
|
+
self._drop_legacy(backend, key)
|
|
243
267
|
|
|
244
268
|
def delete(self, key: str) -> bool:
|
|
245
|
-
"""Remove ``key
|
|
269
|
+
"""Remove ``key`` (and any legacy entry for it)."""
|
|
246
270
|
backend = self._keyring()
|
|
247
|
-
|
|
271
|
+
removed = self._drop_legacy(backend, key)
|
|
272
|
+
if backend.get_password(self.entry(key), key) is not None:
|
|
273
|
+
backend.delete_password(self.entry(key), key)
|
|
274
|
+
removed = True
|
|
275
|
+
return removed
|
|
276
|
+
|
|
277
|
+
def _drop_legacy(self, backend: Any, key: str) -> bool:
|
|
278
|
+
if not self.legacy_service:
|
|
279
|
+
return False
|
|
280
|
+
try:
|
|
281
|
+
if backend.get_password(self.legacy_service, key) is None:
|
|
282
|
+
return False
|
|
283
|
+
backend.delete_password(self.legacy_service, key)
|
|
284
|
+
except Exception: # noqa: BLE001 - a stale legacy entry must never block the new one
|
|
248
285
|
return False
|
|
249
|
-
backend.delete_password(self.service, key)
|
|
250
286
|
return True
|
|
251
287
|
|
|
252
288
|
|
|
289
|
+
def _decode(raw: str | None) -> dict[str, Any] | None:
|
|
290
|
+
if not raw:
|
|
291
|
+
return None
|
|
292
|
+
try:
|
|
293
|
+
data = json.loads(raw)
|
|
294
|
+
except ValueError:
|
|
295
|
+
return None
|
|
296
|
+
return data if isinstance(data, dict) else None
|
|
297
|
+
|
|
298
|
+
|
|
253
299
|
def default_store(program: str, env: Mapping[str, str], prefix: str) -> TokenStore:
|
|
254
300
|
"""Pick the credential store for a CLI.
|
|
255
301
|
|
|
@@ -266,7 +312,7 @@ def default_store(program: str, env: Mapping[str, str], prefix: str) -> TokenSto
|
|
|
266
312
|
return MemoryTokenStore()
|
|
267
313
|
keyring = _usable_keyring()
|
|
268
314
|
if keyring is not None:
|
|
269
|
-
return KeyringTokenStore(program, keyring)
|
|
315
|
+
return KeyringTokenStore(keyring_service(program), keyring, legacy_service=program)
|
|
270
316
|
if choice == "keyring":
|
|
271
317
|
raise AuthError("the keyring credential store needs the 'keyring' package")
|
|
272
318
|
return file_store
|
|
@@ -837,6 +883,7 @@ __all__ = [
|
|
|
837
883
|
"FileTokenStore",
|
|
838
884
|
"Grant",
|
|
839
885
|
"KeyringTokenStore",
|
|
886
|
+
"keyring_service",
|
|
840
887
|
"MemoryTokenStore",
|
|
841
888
|
"OAuth2",
|
|
842
889
|
"OAuthSettings",
|
|
@@ -8,7 +8,7 @@ import threading
|
|
|
8
8
|
import types
|
|
9
9
|
import urllib.request
|
|
10
10
|
from pathlib import Path
|
|
11
|
-
from typing import Any
|
|
11
|
+
from typing import Any, override
|
|
12
12
|
from urllib.parse import parse_qs, urlsplit
|
|
13
13
|
|
|
14
14
|
import pytest
|
|
@@ -139,21 +139,63 @@ class FakeKeyring:
|
|
|
139
139
|
|
|
140
140
|
def test_keyring_store() -> None:
|
|
141
141
|
backend = FakeKeyring()
|
|
142
|
-
store = KeyringTokenStore("acme", backend)
|
|
143
|
-
assert store.location == "keyring service 'acme'"
|
|
142
|
+
store = KeyringTokenStore("codapact:acme", backend)
|
|
143
|
+
assert store.location == "keyring service 'codapact:acme:<scheme>'"
|
|
144
144
|
assert store.load("k") is None
|
|
145
145
|
removed = store.delete("k")
|
|
146
146
|
assert removed is False
|
|
147
147
|
store.save("k", {"secret": "s"})
|
|
148
|
+
assert ("codapact:acme:k", "k") in backend.items
|
|
148
149
|
assert store.load("k") == {"secret": "s"}
|
|
149
150
|
removed = store.delete("k")
|
|
150
151
|
assert removed is True
|
|
151
152
|
assert store.load("k") is None
|
|
152
|
-
backend.items[("acme", "bad")] = "{"
|
|
153
|
-
backend.items[("acme", "list")] = "[1]"
|
|
153
|
+
backend.items[("codapact:acme:bad", "bad")] = "{"
|
|
154
|
+
backend.items[("codapact:acme:list", "list")] = "[1]"
|
|
154
155
|
assert store.load("bad") is None and store.load("list") is None
|
|
155
156
|
|
|
156
157
|
|
|
158
|
+
def test_keyring_store_moves_legacy_entries() -> None:
|
|
159
|
+
backend = FakeKeyring()
|
|
160
|
+
backend.items[("acme", "bearer")] = json.dumps({"secret": "old"})
|
|
161
|
+
backend.items[("acme", "broken")] = "{"
|
|
162
|
+
store = KeyringTokenStore("codapact:acme", backend, legacy_service="acme")
|
|
163
|
+
moved = store.load("bearer")
|
|
164
|
+
assert moved == {"secret": "old"}
|
|
165
|
+
assert backend.items == {
|
|
166
|
+
("codapact:acme:bearer", "bearer"): json.dumps({"secret": "old"}),
|
|
167
|
+
("acme", "broken"): "{",
|
|
168
|
+
}
|
|
169
|
+
reread = store.load("bearer") # now from the new entry
|
|
170
|
+
broken = store.load("broken")
|
|
171
|
+
assert reread == {"secret": "old"}
|
|
172
|
+
assert broken is None
|
|
173
|
+
assert ("acme", "broken") in backend.items # unreadable entries stay put
|
|
174
|
+
store.save("broken", {"secret": "new"}) # re-login replaces the legacy entry
|
|
175
|
+
assert ("acme", "broken") not in backend.items
|
|
176
|
+
backend.items[("acme", "gone")] = json.dumps({"secret": "x"})
|
|
177
|
+
first = store.delete("gone")
|
|
178
|
+
again = store.delete("gone")
|
|
179
|
+
assert first is True
|
|
180
|
+
assert again is False
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def test_keyring_store_ignores_legacy_delete_failures() -> None:
|
|
184
|
+
class Stubborn(FakeKeyring):
|
|
185
|
+
@override
|
|
186
|
+
def delete_password(self, service: str, key: str) -> None:
|
|
187
|
+
if service == "acme":
|
|
188
|
+
raise RuntimeError("access denied")
|
|
189
|
+
super().delete_password(service, key)
|
|
190
|
+
|
|
191
|
+
backend = Stubborn()
|
|
192
|
+
backend.items[("acme", "bearer")] = json.dumps({"secret": "old"})
|
|
193
|
+
store = KeyringTokenStore("codapact:acme", backend, legacy_service="acme")
|
|
194
|
+
moved = store.load("bearer")
|
|
195
|
+
assert moved == {"secret": "old"}
|
|
196
|
+
assert backend.items[("codapact:acme:bearer", "bearer")] == json.dumps({"secret": "old"})
|
|
197
|
+
|
|
198
|
+
|
|
157
199
|
def fake_keyring_module(monkeypatch: pytest.MonkeyPatch, *, failing: bool) -> FakeKeyring:
|
|
158
200
|
backend = FakeKeyring()
|
|
159
201
|
module = types.ModuleType("keyring")
|
|
@@ -195,11 +237,15 @@ def test_default_store_choices(tmp_path: Path, monkeypatch: pytest.MonkeyPatch)
|
|
|
195
237
|
|
|
196
238
|
def test_default_store_uses_a_working_keyring(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
197
239
|
backend = fake_keyring_module(monkeypatch, failing=False)
|
|
240
|
+
backend.items[("acme", "old")] = json.dumps({"a": 0})
|
|
198
241
|
store = default_store("acme", {}, "ACME")
|
|
199
242
|
assert isinstance(store, KeyringTokenStore)
|
|
243
|
+
migrated = store.load("old")
|
|
244
|
+
assert migrated == {"a": 0}
|
|
245
|
+
assert ("acme", "old") not in backend.items
|
|
200
246
|
store.save("k", {"a": 1})
|
|
201
|
-
assert json.loads(backend.items[("acme", "k")]) == {"a": 1}
|
|
202
|
-
assert KeyringTokenStore("acme").load("k") == {"a": 1} # imports the module itself
|
|
247
|
+
assert json.loads(backend.items[("codapact:acme:k", "k")]) == {"a": 1}
|
|
248
|
+
assert KeyringTokenStore("codapact:acme").load("k") == {"a": 1} # imports the module itself
|
|
203
249
|
fake_keyring_module(monkeypatch, failing=True)
|
|
204
250
|
assert isinstance(default_store("acme", {}, "ACME"), FileTokenStore)
|
|
205
251
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{".":"0.6.0"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|