asanypath 2.3.1__tar.gz → 2.3.2__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 (81) hide show
  1. {asanypath-2.3.1 → asanypath-2.3.2}/.github/workflows/publish.yml +1 -1
  2. {asanypath-2.3.1 → asanypath-2.3.2}/PKG-INFO +54 -4
  3. {asanypath-2.3.1 → asanypath-2.3.2}/README.md +52 -2
  4. asanypath-2.3.2/SECURITY.md +18 -0
  5. {asanypath-2.3.1 → asanypath-2.3.2}/hatch_build.py +9 -3
  6. asanypath-2.3.2/src/asanypath/_prompt.py +22 -0
  7. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/_version.py +2 -2
  8. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/artifactory.py +56 -33
  9. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/azure.py +14 -14
  10. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/batcher.py +16 -19
  11. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/cli.py +13 -1
  12. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/cloud.py +161 -19
  13. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/common.py +46 -12
  14. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/ftp.py +14 -22
  15. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/gcs.py +8 -12
  16. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/http.py +58 -11
  17. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/s3.py +24 -16
  18. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/ssh.py +157 -42
  19. {asanypath-2.3.1 → asanypath-2.3.2}/tests/conftest.py +6 -0
  20. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_artifactory.py +7 -2
  21. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_azure.py +16 -12
  22. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_batcher.py +0 -1
  23. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_cli.py +16 -10
  24. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_cloudpathmixin.py +7 -6
  25. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_commonpathmixin.py +13 -3
  26. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_gcs.py +2 -7
  27. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_http_auth.py +4 -0
  28. asanypath-2.3.2/tests/test_isolation.py +579 -0
  29. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_s3.py +1 -1
  30. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_ssh.py +21 -2
  31. asanypath-2.3.2/tests/test_ssh_hostkeys.py +149 -0
  32. asanypath-2.3.2/tests/test_transport_hardening.py +149 -0
  33. asanypath-2.3.1/SECURITY.md +0 -17
  34. {asanypath-2.3.1 → asanypath-2.3.2}/.copilot/skills/async-python-lib/SKILL.md +0 -0
  35. {asanypath-2.3.1 → asanypath-2.3.2}/.copilot/skills/gitguro/SKILL.md +0 -0
  36. {asanypath-2.3.1 → asanypath-2.3.2}/.github/CODEOWNERS +0 -0
  37. {asanypath-2.3.1 → asanypath-2.3.2}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  38. {asanypath-2.3.1 → asanypath-2.3.2}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  39. {asanypath-2.3.1 → asanypath-2.3.2}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  40. {asanypath-2.3.1 → asanypath-2.3.2}/.github/dependabot.yml +0 -0
  41. {asanypath-2.3.1 → asanypath-2.3.2}/.github/workflows/unittests.yml +0 -0
  42. {asanypath-2.3.1 → asanypath-2.3.2}/.gitignore +0 -0
  43. {asanypath-2.3.1 → asanypath-2.3.2}/.pre-commit-config.yaml +0 -0
  44. {asanypath-2.3.1 → asanypath-2.3.2}/CODE_OF_CONDUCT.md +0 -0
  45. {asanypath-2.3.1 → asanypath-2.3.2}/CONTRIBUTING.md +0 -0
  46. {asanypath-2.3.1 → asanypath-2.3.2}/LICENSE +0 -0
  47. {asanypath-2.3.1 → asanypath-2.3.2}/asanypath.png +0 -0
  48. {asanypath-2.3.1 → asanypath-2.3.2}/compose.yml +0 -0
  49. {asanypath-2.3.1 → asanypath-2.3.2}/pyproject.toml +0 -0
  50. {asanypath-2.3.1 → asanypath-2.3.2}/scripts/bench.py +0 -0
  51. {asanypath-2.3.1 → asanypath-2.3.2}/scripts/bench_upload.py +0 -0
  52. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/__init__.py +0 -0
  53. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/__init__.pyi +0 -0
  54. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/_backend_opts.py +0 -0
  55. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/_credstore.py +0 -0
  56. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/_resume.py +0 -0
  57. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/_transfer.py +0 -0
  58. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/asanypath.py +0 -0
  59. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/asanypath.pyi +0 -0
  60. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/cache.py +0 -0
  61. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/exceptions.py +0 -0
  62. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/local.py +0 -0
  63. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/options.py +0 -0
  64. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/py.typed +0 -0
  65. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/sync.py +0 -0
  66. {asanypath-2.3.1 → asanypath-2.3.2}/src/asanypath/unsupported.py +0 -0
  67. {asanypath-2.3.1 → asanypath-2.3.2}/tests/__init__.py +0 -0
  68. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_asanypath.py +0 -0
  69. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_backend_options.py +0 -0
  70. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_cache.py +0 -0
  71. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_credstore.py +0 -0
  72. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_ftp.py +0 -0
  73. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_http.py +0 -0
  74. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_local.py +0 -0
  75. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_options.py +0 -0
  76. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_py_typed.py +0 -0
  77. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_resume.py +0 -0
  78. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_sync.py +0 -0
  79. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_syncpath.py +0 -0
  80. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_unsupported_path.py +0 -0
  81. {asanypath-2.3.1 → asanypath-2.3.2}/tests/test_upload.py +0 -0
@@ -139,7 +139,7 @@ jobs:
139
139
  env:
140
140
  VERSION: ${{ needs.release-version.outputs.value }}
141
141
  run: |
142
- unzip -p dist/*.whl '*/METADATA' | grep -Fx "Requires-Dist: asanypath-native~=${VERSION%.*}.0"
142
+ unzip -p dist/*.whl '*/METADATA' | grep -Fx "Requires-Dist: asanypath-native~=${VERSION}"
143
143
 
144
144
  - name: Upload Python distributions
145
145
  uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: asanypath
3
- Version: 2.3.1
3
+ Version: 2.3.2
4
4
  Summary: Async pathlib for local and cloud storage
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -19,7 +19,7 @@ Classifier: Programming Language :: Python :: 3.14
19
19
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
20
  Requires-Python: >=3.10
21
21
  Requires-Dist: anyio>=4
22
- Requires-Dist: asanypath-native~=2.3.0
22
+ Requires-Dist: asanypath-native~=2.3.2
23
23
  Requires-Dist: msgspec>=0.22.0
24
24
  Requires-Dist: yarl>=1.2
25
25
  Provides-Extra: all
@@ -271,6 +271,49 @@ Pure path operations (e.g. `.name`, `.parent`, joins) still work, while backend
271
271
  operations (e.g. `.exists()`, `.read_bytes()`, `.open()`) raise
272
272
  `UnsupportedProtocolError` on use.
273
273
 
274
+ ### Credentials and derived paths
275
+
276
+ Credentials and endpoints passed to a constructor belong to that path and to
277
+ paths derived from it (`/`, `parent`, `with_name`, `with_segments`, listing
278
+ children). Independently constructed paths resolve their own credentials from
279
+ the environment, the keyring, or the backend's usual configuration:
280
+
281
+ ```python
282
+ from asanypath.s3 import S3Path
283
+
284
+ p = S3Path("s3://bucket/data", endpoint_url="https://minio.local", aws_access_key_id="...",
285
+ aws_secret_access_key="...")
286
+ child = p / "part-0.parquet" # same endpoint and credentials
287
+ other = S3Path("s3://bucket/data") # default AWS configuration
288
+ ```
289
+
290
+ For backends whose credentials authenticate against the host in the URL
291
+ (Artifactory, SSH, FTP), explicit credentials never follow a derived path to a
292
+ different host. Listing results are only yielded when they name a direct child
293
+ of the listed path.
294
+
295
+ Ambient (environment) credentials belong to one configured service and are only
296
+ sent to that service's origin (scheme, host and port). Without a configured
297
+ service they are not sent at all, and a warning names the missing setting:
298
+
299
+ - **HTTP(S):** `HTTP_AUTH_USER`/`HTTP_AUTH_PASSWORD` or `HTTP_AUTH_TOKEN`
300
+ (with optional `HTTP_AUTH_HEADER`) are only used for URLs on the origin of
301
+ `HTTP_AUTH_URL`, e.g. `HTTP_AUTH_URL=https://files.example.com`. On a
302
+ redirect to another scheme, host or port, only non-credential headers
303
+ (`Range`, `Accept`, conditional headers, ...) are forwarded.
304
+ - **Artifactory:** `ARTIFACTORY_IDENTITY_TOKEN` is only used for the service in
305
+ `ARTIFACTORY_BASE_URL` (or `ART_BASE_URL`). A JFrog CLI server token is only
306
+ used for that server's own origin.
307
+ - **SSH:** host keys are checked like OpenSSH. `StrictHostKeyChecking`
308
+ (`yes`, `ask`, `accept-new`, `no`) and `UserKnownHostsFile` are read from
309
+ ssh_config; the default is `ask` against `~/.ssh/known_hosts`. Interactive
310
+ sessions are prompted for a host with no recorded key; non-interactive ones
311
+ refuse it. A changed key is refused, and with `StrictHostKeyChecking no`
312
+ password authentication is disabled for it. Pass `known_hosts=()` (or set
313
+ `SSH_KNOWN_HOSTS=none`) to disable checking.
314
+ - **Azure `presign()`** signs a blob-scoped SAS with the account key; a
315
+ configured SAS token is never handed out as a presigned URL.
316
+
274
317
  ### Download caching (opt-in)
275
318
 
276
319
  Reading the same object or URL twice always re-downloads it — there is **no
@@ -318,9 +361,16 @@ Behaviour and trade-offs:
318
361
  payloads; SQLite metadata and transaction journals add filesystem overhead.
319
362
  Objects larger than the budget are returned without being cached.
320
363
  - **Byte-only native storage:** SQLite stores raw bytes, never Python pickles.
321
- The database lives under `native-v1/` in the configured cache directory.
364
+ The database lives under `native-v1/` in the configured cache directory,
365
+ readable only by its owner (directory `0700`, files `0600` on POSIX).
322
366
  Legacy DiskCache files are ignored, not migrated or deleted. Multiple
323
- processes can share the new store; use the same size limit across them.
367
+ processes of the same user can share the new store; use the same size limit
368
+ across them.
369
+ - **Scoped to credentials.** Entries are keyed by URL plus a hash of the
370
+ path's credentials and endpoint, so different identities never share an
371
+ entry. Credentials themselves are never written to the cache. A cached entry
372
+ is not revalidated, so revoking an identity's access upstream does not evict
373
+ what it already cached.
324
374
  - **Staleness is on you.** Entries are keyed by URL with no revalidation — a
325
375
  cached object that changes upstream is served stale until it expires (`ttl`)
326
376
  or is evicted. Prefer caching immutable/versioned objects, or set a `ttl`.
@@ -215,6 +215,49 @@ Pure path operations (e.g. `.name`, `.parent`, joins) still work, while backend
215
215
  operations (e.g. `.exists()`, `.read_bytes()`, `.open()`) raise
216
216
  `UnsupportedProtocolError` on use.
217
217
 
218
+ ### Credentials and derived paths
219
+
220
+ Credentials and endpoints passed to a constructor belong to that path and to
221
+ paths derived from it (`/`, `parent`, `with_name`, `with_segments`, listing
222
+ children). Independently constructed paths resolve their own credentials from
223
+ the environment, the keyring, or the backend's usual configuration:
224
+
225
+ ```python
226
+ from asanypath.s3 import S3Path
227
+
228
+ p = S3Path("s3://bucket/data", endpoint_url="https://minio.local", aws_access_key_id="...",
229
+ aws_secret_access_key="...")
230
+ child = p / "part-0.parquet" # same endpoint and credentials
231
+ other = S3Path("s3://bucket/data") # default AWS configuration
232
+ ```
233
+
234
+ For backends whose credentials authenticate against the host in the URL
235
+ (Artifactory, SSH, FTP), explicit credentials never follow a derived path to a
236
+ different host. Listing results are only yielded when they name a direct child
237
+ of the listed path.
238
+
239
+ Ambient (environment) credentials belong to one configured service and are only
240
+ sent to that service's origin (scheme, host and port). Without a configured
241
+ service they are not sent at all, and a warning names the missing setting:
242
+
243
+ - **HTTP(S):** `HTTP_AUTH_USER`/`HTTP_AUTH_PASSWORD` or `HTTP_AUTH_TOKEN`
244
+ (with optional `HTTP_AUTH_HEADER`) are only used for URLs on the origin of
245
+ `HTTP_AUTH_URL`, e.g. `HTTP_AUTH_URL=https://files.example.com`. On a
246
+ redirect to another scheme, host or port, only non-credential headers
247
+ (`Range`, `Accept`, conditional headers, ...) are forwarded.
248
+ - **Artifactory:** `ARTIFACTORY_IDENTITY_TOKEN` is only used for the service in
249
+ `ARTIFACTORY_BASE_URL` (or `ART_BASE_URL`). A JFrog CLI server token is only
250
+ used for that server's own origin.
251
+ - **SSH:** host keys are checked like OpenSSH. `StrictHostKeyChecking`
252
+ (`yes`, `ask`, `accept-new`, `no`) and `UserKnownHostsFile` are read from
253
+ ssh_config; the default is `ask` against `~/.ssh/known_hosts`. Interactive
254
+ sessions are prompted for a host with no recorded key; non-interactive ones
255
+ refuse it. A changed key is refused, and with `StrictHostKeyChecking no`
256
+ password authentication is disabled for it. Pass `known_hosts=()` (or set
257
+ `SSH_KNOWN_HOSTS=none`) to disable checking.
258
+ - **Azure `presign()`** signs a blob-scoped SAS with the account key; a
259
+ configured SAS token is never handed out as a presigned URL.
260
+
218
261
  ### Download caching (opt-in)
219
262
 
220
263
  Reading the same object or URL twice always re-downloads it — there is **no
@@ -262,9 +305,16 @@ Behaviour and trade-offs:
262
305
  payloads; SQLite metadata and transaction journals add filesystem overhead.
263
306
  Objects larger than the budget are returned without being cached.
264
307
  - **Byte-only native storage:** SQLite stores raw bytes, never Python pickles.
265
- The database lives under `native-v1/` in the configured cache directory.
308
+ The database lives under `native-v1/` in the configured cache directory,
309
+ readable only by its owner (directory `0700`, files `0600` on POSIX).
266
310
  Legacy DiskCache files are ignored, not migrated or deleted. Multiple
267
- processes can share the new store; use the same size limit across them.
311
+ processes of the same user can share the new store; use the same size limit
312
+ across them.
313
+ - **Scoped to credentials.** Entries are keyed by URL plus a hash of the
314
+ path's credentials and endpoint, so different identities never share an
315
+ entry. Credentials themselves are never written to the cache. A cached entry
316
+ is not revalidated, so revoking an identity's access upstream does not evict
317
+ what it already cached.
268
318
  - **Staleness is on you.** Entries are keyed by URL with no revalidation — a
269
319
  cached object that changes upstream is served stale until it expires (`ttl`)
270
320
  or is evicted. Prefer caching immutable/versioned objects, or set a `ttl`.
@@ -0,0 +1,18 @@
1
+ # Security Policy
2
+
3
+ ## Reporting a Vulnerability
4
+
5
+ Do not report suspected vulnerabilities in public issues or pull requests.
6
+ Report them privately through GitHub's private vulnerability reporting: open
7
+ the repository's **Security** tab and choose **Report a vulnerability**.
8
+ Include reproduction details, affected versions, and potential impact. Do not
9
+ include credentials, tokens, or customer data in the report.
10
+
11
+ Maintainers coordinate fixes through a GitHub security advisory and publish the
12
+ advisory together with the patched release.
13
+
14
+ ## Supported Versions
15
+
16
+ Security fixes are applied to the latest released version. The project may also
17
+ publish fixes for an earlier release when maintainers determine that it is
18
+ necessary and practical.
@@ -4,17 +4,23 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://opensource.org/licenses/MIT.
6
6
 
7
+ import re
8
+
7
9
  from hatchling.metadata.plugin.interface import MetadataHookInterface
8
10
 
9
11
 
10
12
  class PinNativeHook(MetadataHookInterface):
11
- """Provide dependencies, pinning asanypath-native to asanypath's minor version."""
13
+ """Provide dependencies, pinning asanypath-native to asanypath's release.
14
+
15
+ ``~=X.Y.Z`` requires at least the same patch release (fixes and APIs the
16
+ Python code relies on) while allowing later patches of the same minor.
17
+ """
12
18
 
13
19
  def update(self, metadata: dict) -> None:
14
- major, minor, *_ = metadata["version"].split(".")
20
+ major, minor, patch = re.match(r"(\d+)\.(\d+)\.(\d+)", metadata["version"]).groups()
15
21
  metadata["dependencies"] = [
16
22
  "anyio>=4",
17
- f"asanypath-native~={major}.{minor}.0",
23
+ f"asanypath-native~={major}.{minor}.{patch}",
18
24
  "msgspec>=0.22.0",
19
25
  "yarl>=1.2",
20
26
  ]
@@ -0,0 +1,22 @@
1
+ # Copyright (C) 2026 Axis Communications AB, Lund, Sweden
2
+ #
3
+ # Use of this source code is governed by an MIT-style
4
+ # license that can be found in the LICENSE file or at
5
+ # https://opensource.org/licenses/MIT.
6
+
7
+ """Whether backends may prompt the user on the terminal."""
8
+
9
+ from __future__ import annotations
10
+
11
+ import sys
12
+ from os import getenv
13
+
14
+
15
+ def interactive() -> bool:
16
+ """Whether a backend may prompt the user (credentials, host keys)."""
17
+ if getenv("ASANYPATH_INTERACTIVE") == "0":
18
+ return False
19
+ try:
20
+ return sys.stdin.isatty()
21
+ except (AttributeError, ValueError): # pragma: no cover
22
+ return False # pragma: no cover
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '2.3.1'
22
- __version_tuple__ = version_tuple = (2, 3, 1)
21
+ __version__ = version = '2.3.2'
22
+ __version_tuple__ = version_tuple = (2, 3, 2)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -8,6 +8,7 @@
8
8
 
9
9
  from __future__ import annotations
10
10
 
11
+ import hashlib
11
12
  import json
12
13
  import os
13
14
  import shutil
@@ -38,7 +39,7 @@ from asanypath_native import (
38
39
  art_storage_info,
39
40
  )
40
41
 
41
- from asanypath.cloud import CloudPathMixin
42
+ from asanypath.cloud import CloudPathMixin, _service_origin
42
43
  from asanypath.options import (
43
44
  UPLOAD_CHUNK_SIZE,
44
45
  AccessGrant,
@@ -49,33 +50,27 @@ from asanypath.options import (
49
50
 
50
51
 
51
52
  def _jfrog_conf_token(base_url: str) -> str | None:
52
- """Return an access token from the JFrog CLI config matching ``base_url``.
53
+ """Return an access token from the JFrog CLI config for ``base_url``'s service.
53
54
 
54
- Reads ``$JFROG_CLI_HOME`` (default ``~/.jfrog``), preferring a server whose
55
- configured URL contains the target host, else the default/first server.
55
+ Reads ``$JFROG_CLI_HOME`` (default ``~/.jfrog``) and only uses a server
56
+ whose configured URL has exactly this origin (scheme, host and port): a
57
+ token is never sent to a service it wasn't configured for.
56
58
  """
57
59
  root = Path(getenv("JFROG_CLI_HOME") or (Path.home() / ".jfrog"))
58
- host = base_url.split("/")[0].lower() if base_url else ""
60
+ target = _service_origin(base_url) if base_url else None
61
+ if target is None:
62
+ return None
59
63
  for name in ("jfrog-cli.conf.v7", "jfrog-cli.conf.v6", "jfrog-cli.conf.v5", "jfrog-cli.conf"):
60
64
  try:
61
65
  data = json.loads((root / name).read_text())
62
66
  except (OSError, ValueError):
63
67
  continue
64
68
  servers = data.get("servers") if isinstance(data, dict) else None
65
- if not servers:
66
- continue
67
- match = next(
68
- (
69
- s
70
- for s in servers
71
- if host and host in f"{s.get('url', '')}{s.get('artifactoryUrl', '')}".lower()
72
- ),
73
- None,
74
- )
75
- if match is None:
76
- match = next((s for s in servers if s.get("isDefault")), servers[0])
77
- if token := match.get("accessToken"):
78
- return token
69
+ for server in servers or ():
70
+ urls = (server.get("url"), server.get("artifactoryUrl"))
71
+ if any(url and _service_origin(url) == target for url in urls):
72
+ if token := server.get("accessToken"):
73
+ return token
79
74
  return None
80
75
 
81
76
 
@@ -88,6 +83,7 @@ class ArtifactoryPath(CloudPathMixin):
88
83
  Example:
89
84
  ```python
90
85
  import asyncio
86
+ import hashlib
91
87
  from asanypath import AsAnyPath
92
88
 
93
89
  async def main():
@@ -104,11 +100,15 @@ class ArtifactoryPath(CloudPathMixin):
104
100
  """
105
101
 
106
102
  protocol: str = "art"
103
+ _options_bound_to_authority = True
107
104
  _supports_range_read: bool = True
108
105
  # Artifactory has no multipart API: objects at/above this size stream a single
109
106
  # PUT body from disk (bounded memory) instead of buffering the whole object.
110
107
  _STREAM_THRESHOLD = UPLOAD_CHUNK_SIZE
111
108
  _copy_batch_fn = staticmethod(art_copy_batch)
109
+ # Tokens per service (``art:<host>/artifactory``), mirroring the keyring so
110
+ # repeated constructions skip it. Never applied to a different service.
111
+ _service_tokens: dict[str, str] = {}
112
112
 
113
113
  @staticmethod
114
114
  def _batcher_key_fn(base_url: str, token: str, **_kw) -> str:
@@ -148,23 +148,26 @@ class ArtifactoryPath(CloudPathMixin):
148
148
  from asanypath import _credstore
149
149
 
150
150
  cred_key = f"art:{self._base_url}"
151
- self._token = token or self.env_config.token
152
- if not self._token:
153
- self._token = _credstore.load(cred_key)
154
- if not self._token:
155
- self._token = _jfrog_conf_token(self._base_url)
151
+ known = ArtifactoryPath._service_tokens
152
+ if token:
153
+ # Persist user-supplied tokens once per service, not per derived path.
154
+ if known.get(cred_key) != token:
155
+ _credstore.save(cred_key, token)
156
+ known[cred_key] = token
157
+ self._token = token
158
+ self._init_options = {"token": token}
159
+ else:
160
+ self._token = self._env_token() or known.get(cred_key)
161
+ if not self._token:
162
+ self._token = _credstore.load(cred_key) or _jfrog_conf_token(self._base_url)
163
+ if self._token:
164
+ known[cred_key] = self._token
156
165
  if not self._token:
157
166
  raise ValueError(
158
167
  "Artifactory token required via 'token' parameter, "
159
168
  "ARTIFACTORY_IDENTITY_TOKEN environment variable, the JFrog CLI config "
160
169
  "(~/.jfrog/jfrog-cli.conf), or a previously cached token (see keyring)."
161
170
  )
162
- # Promote the resolved token into the class-level cache so derived
163
- # instances (parent, /, iterdir children, ...) inherit it without
164
- # re-hitting the keyring. Persist only user-supplied tokens.
165
- self.env_config.token = self._token
166
- if token:
167
- _credstore.save(cred_key, token)
168
171
  # Cached folder hint — set by iterdir() to avoid redundant API calls
169
172
  self._is_folder: bool | None = None
170
173
  self._cached_info: dict | None = None
@@ -180,6 +183,19 @@ class ArtifactoryPath(CloudPathMixin):
180
183
  # CloudPathMixin hooks
181
184
  # ------------------------------------------------------------------
182
185
 
186
+ def _env_token(self) -> str | None:
187
+ """``ARTIFACTORY_IDENTITY_TOKEN``, only for the service named by
188
+ ``ARTIFACTORY_BASE_URL`` (or ``ART_BASE_URL``)."""
189
+ token = self.env_config.token
190
+ if token and self._ambient_credentials_allowed(
191
+ self._resolve_base_url_prefix(),
192
+ self._base_url,
193
+ credential="ARTIFACTORY_IDENTITY_TOKEN",
194
+ setting="ARTIFACTORY_BASE_URL",
195
+ ):
196
+ return token
197
+ return None
198
+
183
199
  @property
184
200
  def _item_path(self) -> str:
185
201
  return self._repo_path
@@ -203,6 +219,11 @@ class ArtifactoryPath(CloudPathMixin):
203
219
  "token": self._token,
204
220
  }
205
221
 
222
+ def _identity_parts(self) -> tuple:
223
+ # Keep cache identity scoped even when the token came from keyring/JFrog.
224
+ token_fp = hashlib.sha256(self._token.encode()).hexdigest()
225
+ return (*super()._identity_parts(), self._base_url, token_fp)
226
+
206
227
  # ------------------------------------------------------------------
207
228
  # Backend-specific operations
208
229
  # ------------------------------------------------------------------
@@ -243,7 +264,7 @@ class ArtifactoryPath(CloudPathMixin):
243
264
  options_json=options_json,
244
265
  **self._native_kwargs,
245
266
  )
246
- type(self)._listing_cache.pop(self._listing_cache_key(), None)
267
+ self._invalidate_listing()
247
268
 
248
269
  async def _storage_info(self) -> dict:
249
270
  """Fetch item metadata from the Artifactory storage API (cached).
@@ -308,8 +329,10 @@ class ArtifactoryPath(CloudPathMixin):
308
329
  )
309
330
  base = str(self).rstrip("/")
310
331
  for uri, is_folder in results:
311
- child_name = uri.rsplit("/", 1)[-1]
312
- yield self._child(f"{base}/{child_name}", _is_folder=is_folder)
332
+ child_name = uri.rstrip("/").rsplit("/", 1)[-1]
333
+ child = self._confined_child(f"{base}/{child_name}", _is_folder=is_folder)
334
+ if child is not None:
335
+ yield child
313
336
 
314
337
  async def _list_containers(self) -> list[str] | None:
315
338
  """List repositories when at the server root (``art://<host>/artifactory/``).
@@ -39,7 +39,7 @@ from asanypath_native import (
39
39
  )
40
40
 
41
41
  from asanypath._transfer import upload_parts
42
- from asanypath.cloud import CloudPathMixin
42
+ from asanypath.cloud import CloudPathMixin, _explicit
43
43
  from asanypath.options import (
44
44
  UPLOAD_CHUNK_SIZE,
45
45
  AccessGrant,
@@ -136,16 +136,12 @@ class AzurePath(CloudPathMixin):
136
136
  or cfg.endpoint_url
137
137
  or (f"https://{self._account_name}.blob.core.windows.net")
138
138
  )
139
- # Promote explicit params into class cache so derived instances
140
- # (parent, /, with_name, etc.) inherit them.
141
- if account_name:
142
- cfg.account_name = account_name
143
- if account_key:
144
- cfg.account_key = account_key
145
- if sas_token:
146
- cfg.sas_token = sas_token
147
- if endpoint_url:
148
- cfg.endpoint_url = endpoint_url
139
+ self._init_options = _explicit(
140
+ endpoint_url=endpoint_url,
141
+ account_name=account_name,
142
+ account_key=account_key,
143
+ sas_token=sas_token,
144
+ )
149
145
 
150
146
  # URL format: az://container/blob/path
151
147
  self._container = self._path.host or ""
@@ -231,7 +227,7 @@ class AzurePath(CloudPathMixin):
231
227
  options_json=options_json,
232
228
  **self._native_kwargs,
233
229
  )
234
- type(self)._listing_cache.pop(self._listing_cache_key(), None)
230
+ self._invalidate_listing()
235
231
 
236
232
  async def is_dir(self) -> bool:
237
233
  """Check if path is a directory prefix (has blobs with this prefix)."""
@@ -315,8 +311,9 @@ class AzurePath(CloudPathMixin):
315
311
  async def presign(self, *, expires: int = 3600, method: str = "GET") -> str:
316
312
  """Generate a presigned URL for this Azure blob using a Service SAS token.
317
313
 
318
- Requires account_key to be set. If a SAS token is already configured,
319
- returns the blob URL with the existing SAS token appended.
314
+ The SAS is signed with the account key and scoped to this blob,
315
+ *method* and *expires*. A configured SAS token is never returned: it is
316
+ a credential that may grant more than this blob.
320
317
 
321
318
  Args:
322
319
  expires: URL validity in seconds (default 3600).
@@ -324,6 +321,9 @@ class AzurePath(CloudPathMixin):
324
321
 
325
322
  Returns:
326
323
  A presigned URL string.
324
+
325
+ Raises:
326
+ ValueError: If no account key is configured.
327
327
  """
328
328
  return az_presign(
329
329
  endpoint=self._endpoint_url,
@@ -29,19 +29,13 @@ class MicroBatcher:
29
29
  Each operation is registered with :meth:`register`, which returns a
30
30
  submit coroutine callers use to enqueue work. At the end of the
31
31
  current tick, all enqueued items are flushed together via the
32
- backend-provided *flush_fn*.
33
-
34
- Parameters
35
- ----------
36
- key_fn:
37
- Callable that produces a hashable grouping key from the keyword
38
- arguments passed to the submit function. Calls with the same
39
- key are batched together.
32
+ backend-provided *flush_fn*. Calls are batched together only when all
33
+ their keyword arguments (credentials included) are identical.
40
34
  """
41
35
 
42
36
  def __init__(self) -> None:
43
- self._pending: dict[str, list] = {}
44
- self._scheduled: set[str] = set()
37
+ # A key is present exactly while its flush is scheduled.
38
+ self._pending: dict[tuple, list] = {}
45
39
  self._ops: dict[str, _OpSpec] = {}
46
40
 
47
41
  def __getattr__(self, name: str) -> Callable[..., Coroutine]:
@@ -70,7 +64,8 @@ class MicroBatcher:
70
64
  ``async def flush_fn(items, futures, use_h2, **kwargs)``
71
65
  Called with the collected items list and their futures.
72
66
  key_fn:
73
- ``def key_fn(**kwargs) -> str`` — returns a grouping key.
67
+ ``def key_fn(**kwargs) -> str`` — identifies the backend client;
68
+ grouping always uses the full keyword arguments.
74
69
  item_key:
75
70
  Name of the keyword argument that carries the per-call item
76
71
  (default ``"item"``).
@@ -96,18 +91,20 @@ class MicroBatcher:
96
91
 
97
92
  async def _submit(self, spec: _OpSpec, kwargs: dict) -> Any:
98
93
  item = kwargs.pop(spec.item_key)
99
- key = f"{spec.op}|{spec.key_fn(**kwargs)}"
100
- fut: asyncio.Future = asyncio.get_running_loop().create_future()
101
- pending = self._pending.setdefault(key, [])
94
+ # The flush reuses one caller's kwargs for the whole batch, so only
95
+ # calls with identical kwargs (credentials included) may share it.
96
+ key = (spec.op, tuple(kwargs.items()))
97
+ loop = asyncio.get_running_loop()
98
+ fut: asyncio.Future = loop.create_future()
99
+ pending = self._pending.get(key)
100
+ if pending is None:
101
+ pending = self._pending[key] = []
102
+ loop.call_soon(self._flush, key, spec, kwargs)
102
103
  pending.append((item, fut))
103
- if key not in self._scheduled:
104
- self._scheduled.add(key)
105
- asyncio.get_running_loop().call_soon(self._flush, key, spec, kwargs)
106
104
  return await fut
107
105
 
108
- def _flush(self, key: str, spec: _OpSpec, kwargs: dict) -> None:
106
+ def _flush(self, key: tuple, spec: _OpSpec, kwargs: dict) -> None:
109
107
  items = self._pending.pop(key, [])
110
- self._scheduled.discard(key)
111
108
  if not items:
112
109
  return
113
110
  collected = [i for i, _ in items]
@@ -507,7 +507,7 @@ def _maybe_rewrite_scp_style(value: str, check_config: bool = True) -> str:
507
507
  return value
508
508
  if not _discover_ssh_config():
509
509
  return value
510
- resolved_host, _, _, _ = _resolve_alias(host, None, None)
510
+ resolved_host = _resolve_alias(host, None, None)[0]
511
511
  if resolved_host == host:
512
512
  # No Host block matched — leave alone (don't probe DNS).
513
513
  return value
@@ -2606,6 +2606,18 @@ def auth_show(path: str | None):
2606
2606
  console.print(
2607
2607
  f" ARTIFACTORY_IDENTITY_TOKEN: {mask_token(getenv('ARTIFACTORY_IDENTITY_TOKEN'))}"
2608
2608
  )
2609
+ base_url = getenv("ARTIFACTORY_BASE_URL") or getenv("ART_BASE_URL") or "(not set)"
2610
+ console.print(f" ARTIFACTORY_BASE_URL: {base_url}")
2611
+
2612
+ # HTTP env vars (only sent to HTTP_AUTH_URL's origin)
2613
+ if scheme is None or scheme in ("http", "https"):
2614
+ console.print("\n[cyan]HTTP(S):[/cyan]")
2615
+ console.print(f" HTTP_AUTH_URL: {getenv('HTTP_AUTH_URL', '(not set)')}")
2616
+ console.print(f" HTTP_AUTH_USER: {getenv('HTTP_AUTH_USER', '(not set)')}")
2617
+ console.print(
2618
+ f" HTTP_AUTH_PASSWORD: {'(set)' if getenv('HTTP_AUTH_PASSWORD') else '(not set)'}"
2619
+ )
2620
+ console.print(f" HTTP_AUTH_TOKEN: {mask_token(getenv('HTTP_AUTH_TOKEN'))}")
2609
2621
 
2610
2622
  # SSH env vars + ssh_config
2611
2623
  if scheme is None or scheme == "ssh":