object-storage-client 0.2.2__tar.gz → 0.2.3__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 (161) hide show
  1. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/Cargo.lock +1 -1
  2. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/Cargo.toml +1 -1
  3. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/PKG-INFO +1 -1
  4. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/docs/CONFIGURATION.md +6 -0
  5. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/backend/s3.rs +159 -11
  6. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/.cargo/config.toml +0 -0
  7. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/.docker/garage.toml +0 -0
  8. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/.gitattributes +0 -0
  9. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/.github/dependabot.yml +0 -0
  10. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/.github/workflows/ci.yaml +0 -0
  11. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/.github/workflows/perf.yaml +0 -0
  12. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/.github/workflows/tests.yaml +0 -0
  13. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/.gitignore +0 -0
  14. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/.python-version +0 -0
  15. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/LICENSE +0 -0
  16. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/README.md +0 -0
  17. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/benches/alloc-counter/Cargo.toml +0 -0
  18. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/benches/alloc-counter/src/lib.rs +0 -0
  19. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/benches/common/mod.rs +0 -0
  20. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/benches/throughput.rs +0 -0
  21. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/compose.yml +0 -0
  22. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/deny.toml +0 -0
  23. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/docs/BEHAVIOR.md +0 -0
  24. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/docs/DEVELOPMENT.md +0 -0
  25. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/docs/ENCRYPTION.md +0 -0
  26. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/docs/TESTING.md +0 -0
  27. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/docs/UPGRADING.md +0 -0
  28. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/proptest-regressions/encryption/context.txt +0 -0
  29. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/pyproject.toml +0 -0
  30. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/python/object_storage_client/__init__.py +0 -0
  31. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/python/object_storage_client/__init__.pyi +0 -0
  32. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/python/object_storage_client/_stream.py +0 -0
  33. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/python/object_storage_client/py.typed +0 -0
  34. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/scripts/esdk_oracle.py +0 -0
  35. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/scripts/hostile-env.sh +0 -0
  36. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/scripts/perf_smoke.py +0 -0
  37. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/backend/aws_profile.rs +0 -0
  38. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/backend/azure.rs +0 -0
  39. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/backend/body.rs +0 -0
  40. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/backend/connector.rs +0 -0
  41. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/backend/gcs.rs +0 -0
  42. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/backend/http.rs +0 -0
  43. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/backend/local.rs +0 -0
  44. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/backend/mod.rs +0 -0
  45. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/backend/stub.rs +0 -0
  46. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/cli/args.rs +0 -0
  47. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/cli/enc.rs +0 -0
  48. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/cli/keyring.rs +0 -0
  49. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/cli/output/tests.rs +0 -0
  50. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/cli/output.rs +0 -0
  51. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/cli/tests.rs +0 -0
  52. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/cli/transfer/tests.rs +0 -0
  53. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/cli/transfer.rs +0 -0
  54. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/cli/tree/tests.rs +0 -0
  55. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/cli/tree.rs +0 -0
  56. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/cli.rs +0 -0
  57. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/client/local_delete.rs +0 -0
  58. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/client.rs +0 -0
  59. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/codec.rs +0 -0
  60. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/encryption/context.rs +0 -0
  61. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/encryption/envelope.rs +0 -0
  62. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/encryption/fixtures.rs +0 -0
  63. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/encryption/frame.rs +0 -0
  64. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/encryption/fuzzing.rs +0 -0
  65. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/encryption/header.rs +0 -0
  66. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/encryption/keys/keyring/tests.rs +0 -0
  67. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/encryption/keys/keyring.rs +0 -0
  68. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/encryption/keys/mod.rs +0 -0
  69. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/encryption/keys/raw_aes.rs +0 -0
  70. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/encryption/mod.rs +0 -0
  71. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/encryption/suite.rs +0 -0
  72. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/encryption/tamper_tests.rs +0 -0
  73. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/fsmode.rs +0 -0
  74. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/hex.rs +0 -0
  75. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/lib.rs +0 -0
  76. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/main.rs +0 -0
  77. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/python/client.rs +0 -0
  78. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/python/encryption.rs +0 -0
  79. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/python/mod.rs +0 -0
  80. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/python/stream.rs +0 -0
  81. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/registry.rs +0 -0
  82. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/sign.rs +0 -0
  83. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/text.rs +0 -0
  84. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/src/upload.rs +0 -0
  85. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/functional/aws_profile.rs +0 -0
  86. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/functional/cli.rs +0 -0
  87. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/functional/client.rs +0 -0
  88. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/functional/encryption.rs +0 -0
  89. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/functional/golden.rs +0 -0
  90. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/functional/suite.rs +0 -0
  91. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/functional.rs +0 -0
  92. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/integration/azure_storage_ops.rs +0 -0
  93. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/integration/common/azurite.rs +0 -0
  94. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/integration/common/gcs.rs +0 -0
  95. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/integration/common/mod.rs +0 -0
  96. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/integration/common/provider.rs +0 -0
  97. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/integration/encryption.rs +0 -0
  98. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/integration/file_roundtrip.rs +0 -0
  99. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/integration/gcs_storage_ops.rs +0 -0
  100. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/integration/reencrypt.rs +0 -0
  101. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/integration/s3_storage_ops.rs +0 -0
  102. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/integration/storage_ops.rs +0 -0
  103. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/integration.rs +0 -0
  104. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/perf_guards.rs +0 -0
  105. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/conftest.py +0 -0
  106. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/test_abort_at_exit.py +0 -0
  107. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/test_encrypted_client.py +0 -0
  108. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/test_encryption_runtime.py +0 -0
  109. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/test_free_threading.py +0 -0
  110. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/test_gil_contention.py +0 -0
  111. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/test_list_stream.py +0 -0
  112. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/test_plain_client.py +0 -0
  113. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/test_profile.py +0 -0
  114. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/test_roundtrip.py +0 -0
  115. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/test_shared_client.py +0 -0
  116. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/test_stream_leak.py +0 -0
  117. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/test_stream_sticky.py +0 -0
  118. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/test_stub_conformance.py +0 -0
  119. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/test_subinterpreter.py +0 -0
  120. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/python/test_worker_threads.py +0 -0
  121. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/support/mock.rs +0 -0
  122. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/support/mod.rs +0 -0
  123. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/unit/sign.rs +0 -0
  124. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/unit.rs +0 -0
  125. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/README.md +0 -0
  126. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/ctx_long.bin +0 -0
  127. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/ctx_min.bin +0 -0
  128. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/ctx_utf8.bin +0 -0
  129. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/manifest.json +0 -0
  130. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p0_f4096.bin +0 -0
  131. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p0_f65536.bin +0 -0
  132. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p1_f4096.bin +0 -0
  133. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p1_f65536.bin +0 -0
  134. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p200000_f4096.bin +0 -0
  135. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p200000_f65536.bin +0 -0
  136. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p4095_f4096.bin +0 -0
  137. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p4095_f65536.bin +0 -0
  138. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p4096_f4096.bin +0 -0
  139. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p4096_f65536.bin +0 -0
  140. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p4097_f4096.bin +0 -0
  141. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p4097_f65536.bin +0 -0
  142. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p65535_f4096.bin +0 -0
  143. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p65535_f65536.bin +0 -0
  144. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p65536_f4096.bin +0 -0
  145. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p65536_f65536.bin +0 -0
  146. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p65537_f4096.bin +0 -0
  147. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/esdk/p65537_f65536.bin +0 -0
  148. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/golden/README.md +0 -0
  149. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/golden/v1/context.bin +0 -0
  150. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/golden/v1/keyring +0 -0
  151. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/golden/v1/manifest.json +0 -0
  152. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/golden/v1/old_key.bin +0 -0
  153. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/golden/v1/size_0.bin +0 -0
  154. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/golden/v1/size_1.bin +0 -0
  155. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/golden/v1/size_200000.bin +0 -0
  156. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/golden/v1/size_65536.bin +0 -0
  157. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/keyrings/README.md +0 -0
  158. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/keyrings/one.keyring +0 -0
  159. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/keyrings/other.keyring +0 -0
  160. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/tests/vectors/keyrings/two.keyring +0 -0
  161. {object_storage_client-0.2.2 → object_storage_client-0.2.3}/uv.lock +0 -0
@@ -2024,7 +2024,7 @@ dependencies = [
2024
2024
 
2025
2025
  [[package]]
2026
2026
  name = "object-storage-client"
2027
- version = "0.2.2"
2027
+ version = "0.2.3"
2028
2028
  dependencies = [
2029
2029
  "alloc-counter",
2030
2030
  "async-trait",
@@ -9,7 +9,7 @@ license = "GPL-3.0-only"
9
9
  name = "object-storage-client"
10
10
  readme = "README.md"
11
11
  repository = "https://github.com/bixority/object-storage-client"
12
- version = "0.2.2"
12
+ version = "0.2.3"
13
13
 
14
14
  [lib]
15
15
  crate-type = ["cdylib", "rlib"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: object-storage-client
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: 3
@@ -36,6 +36,12 @@ and `AWS_PROFILE` is never read (see [AWS profiles and SSO](#aws-profiles-and-ss
36
36
  `AWS_ENDPOINT` and `AWS_ENDPOINT_URL` that is set and not empty, then, with a
37
37
  profile, the profile's S3 `endpoint_url`. Without any, requests go to AWS,
38
38
  and bucket calls to `https://s3.<region>.amazonaws.com`, always over https.
39
+ - Addressing: `S3_ADDRESSING_STYLE=path` (the default) puts the bucket in the
40
+ path, `S3_ADDRESSING_STYLE=virtual` puts it in the host. The value is
41
+ case-insensitive, and any other value is an error. When it is unset,
42
+ `AWS_VIRTUAL_HOSTED_STYLE_REQUEST` decides. Object and bucket requests use
43
+ the same style. With a custom endpoint, `virtual` sends requests to the
44
+ endpoint as is, so the endpoint must already be scoped to the bucket.
39
45
  - An `http://` endpoint enables plain HTTP by itself. Plain HTTP exposes every
40
46
  request header to the network, including `x-amz-security-token`, so use it
41
47
  only for a local or otherwise trusted store.
@@ -20,6 +20,31 @@ use std::sync::Arc;
20
20
  use std::time::Duration;
21
21
  use url::Url;
22
22
 
23
+ /// How requests address the bucket. `S3_ADDRESSING_STYLE` sets it; when that is
24
+ /// unset, `AWS_VIRTUAL_HOSTED_STYLE_REQUEST` decides, and path is the default.
25
+ #[derive(Clone, Copy, Debug, PartialEq, Eq)]
26
+ enum AddressingStyle {
27
+ /// `https://<endpoint>/<bucket>/<key>`: the bucket is in the path.
28
+ Path,
29
+ /// `https://<bucket>.<endpoint>/<key>`: the bucket is in the host.
30
+ Virtual,
31
+ }
32
+
33
+ impl AddressingStyle {
34
+ /// Parses `path` or `virtual`, ignoring case.
35
+ fn parse(value: &str) -> Option<Self> {
36
+ match value.to_ascii_lowercase().as_str() {
37
+ "path" => Some(Self::Path),
38
+ "virtual" => Some(Self::Virtual),
39
+ _ => None,
40
+ }
41
+ }
42
+
43
+ const fn is_virtual(self) -> bool {
44
+ matches!(self, Self::Virtual)
45
+ }
46
+ }
47
+
23
48
  /// S3 backend. Retains the concrete [`AmazonS3`] store so credentials can be
24
49
  /// read for header-bound signing and `CreateBucket`, alongside the type-erased
25
50
  /// store used for generic object operations.
@@ -35,8 +60,8 @@ pub struct S3Backend {
35
60
  region: String,
36
61
  /// The configured custom endpoint; `None` means AWS.
37
62
  endpoint: Option<String>,
38
- /// Virtual-hosted addressing: the bucket is in the host, not the path.
39
- virtual_hosted: bool,
63
+ /// How the bucket is addressed, for object and bucket requests alike.
64
+ addressing: AddressingStyle,
40
65
  }
41
66
 
42
67
  impl S3Backend {
@@ -76,6 +101,7 @@ impl S3Backend {
76
101
  let get_var = |k: &str| vars.get(k);
77
102
  let s3_allow_http = get_var("S3_ALLOW_HTTP").unwrap_or_else(|| "false".into());
78
103
  let bucket = host.ok_or_else(|| Error::InvalidInput("Missing bucket in S3 URL".into()))?;
104
+ let addressing_override = Self::addressing_override(vars)?;
79
105
  // One boolean decides both this check and whether the profile signs. An
80
106
  // explicit profile is the only credential source.
81
107
  let uses_profile = profile.is_some();
@@ -123,10 +149,23 @@ impl S3Backend {
123
149
  if let Some(ep) = endpoint.as_deref() {
124
150
  builder = builder.with_config(AmazonS3ConfigKey::S3Endpoint, ep);
125
151
  }
126
- let virtual_hosted = builder
127
- .get_config_value(&AmazonS3ConfigKey::VirtualHostedStyleRequest)
128
- .and_then(|v| parse_bool(&v))
129
- .unwrap_or(false);
152
+ // The store reads the same setting for object calls, so writing the
153
+ // resolved style back keeps bucket and object requests in agreement.
154
+ let addressing = addressing_override.unwrap_or_else(|| {
155
+ let virtual_hosted = builder
156
+ .get_config_value(&AmazonS3ConfigKey::VirtualHostedStyleRequest)
157
+ .and_then(|v| parse_bool(&v))
158
+ .unwrap_or(false);
159
+ if virtual_hosted {
160
+ AddressingStyle::Virtual
161
+ } else {
162
+ AddressingStyle::Path
163
+ }
164
+ });
165
+ builder = builder.with_config(
166
+ AmazonS3ConfigKey::VirtualHostedStyleRequest,
167
+ addressing.is_virtual().to_string(),
168
+ );
130
169
 
131
170
  if let Some(access_key_id) = get_var("S3_ACCESS_KEY_ID") {
132
171
  builder = builder.with_token("").with_access_key_id(access_key_id);
@@ -167,7 +206,21 @@ impl S3Backend {
167
206
  bucket: bucket.to_string(),
168
207
  region,
169
208
  endpoint,
170
- virtual_hosted,
209
+ addressing,
210
+ })
211
+ }
212
+
213
+ /// The addressing style `S3_ADDRESSING_STYLE` names, if it is set. Empty is
214
+ /// unset. Any other value is an error, so a typo cannot silently fall back
215
+ /// to the default.
216
+ fn addressing_override(vars: &Vars) -> Result<Option<AddressingStyle>> {
217
+ let Some(value) = vars.get("S3_ADDRESSING_STYLE").filter(|v| !v.is_empty()) else {
218
+ return Ok(None);
219
+ };
220
+ AddressingStyle::parse(&value).map(Some).ok_or_else(|| {
221
+ Error::InvalidInput(format!(
222
+ "S3_ADDRESSING_STYLE must be \"path\" or \"virtual\", not \"{value}\""
223
+ ))
171
224
  })
172
225
  }
173
226
 
@@ -259,13 +312,15 @@ impl S3Backend {
259
312
  async fn bucket_request(&self, method: Method, body: Bytes) -> Result<HttpRequest> {
260
313
  let (endpoint, region) = self.endpoint_and_region();
261
314
  let endpoint = endpoint.trim_end_matches('/');
262
- let uri = match (self.virtual_hosted, &self.endpoint) {
315
+ let uri = match (self.addressing, &self.endpoint) {
263
316
  // The store uses a custom endpoint as is in this mode.
264
- (true, Some(_)) => format!("{endpoint}/"),
265
- (true, None) => format!("https://{}.s3.{region}.amazonaws.com/", self.bucket),
317
+ (AddressingStyle::Virtual, Some(_)) => format!("{endpoint}/"),
318
+ (AddressingStyle::Virtual, None) => {
319
+ format!("https://{}.s3.{region}.amazonaws.com/", self.bucket)
320
+ }
266
321
  // Path-style addressing keeps the request endpoint-agnostic, which
267
322
  // is what MinIO / SeaweedFS expect and AWS also accepts.
268
- (false, _) => format!("{endpoint}/{}", self.bucket),
323
+ (AddressingStyle::Path, _) => format!("{endpoint}/{}", self.bucket),
269
324
  };
270
325
  let mut request: HttpRequest = http::Request::builder()
271
326
  .method(method)
@@ -919,6 +974,99 @@ mod tests {
919
974
  assert_eq!(request.uri(), "https://bkt.s3.eu-west-1.amazonaws.com/");
920
975
  }
921
976
 
977
+ /// The bucket-level URI a store with `pairs` sends to, against a custom
978
+ /// endpoint.
979
+ async fn bucket_uri(pairs: &[(&str, &str)]) -> String {
980
+ let mut all = vec![("S3_ENDPOINT", "http://127.0.0.1:1")];
981
+ all.extend_from_slice(pairs);
982
+ let request = keyed(&all)
983
+ .bucket_request(Method::PUT, Bytes::new())
984
+ .await
985
+ .expect("request");
986
+ request.uri().to_string()
987
+ }
988
+
989
+ #[tokio::test]
990
+ async fn addressing_style_defaults_to_path() {
991
+ assert_eq!(bucket_uri(&[]).await, "http://127.0.0.1:1/bkt");
992
+ }
993
+
994
+ #[tokio::test]
995
+ async fn s3_addressing_style_selects_the_style_case_insensitively() {
996
+ assert_eq!(
997
+ bucket_uri(&[("S3_ADDRESSING_STYLE", "virtual")]).await,
998
+ "http://127.0.0.1:1/"
999
+ );
1000
+ assert_eq!(
1001
+ bucket_uri(&[("S3_ADDRESSING_STYLE", "PATH")]).await,
1002
+ "http://127.0.0.1:1/bkt"
1003
+ );
1004
+ }
1005
+
1006
+ #[tokio::test]
1007
+ async fn s3_addressing_style_overrides_virtual_hosted_style_request() {
1008
+ assert_eq!(
1009
+ bucket_uri(&[
1010
+ ("S3_ADDRESSING_STYLE", "path"),
1011
+ ("AWS_VIRTUAL_HOSTED_STYLE_REQUEST", "true"),
1012
+ ])
1013
+ .await,
1014
+ "http://127.0.0.1:1/bkt"
1015
+ );
1016
+ assert_eq!(
1017
+ bucket_uri(&[
1018
+ ("S3_ADDRESSING_STYLE", "virtual"),
1019
+ ("AWS_VIRTUAL_HOSTED_STYLE_REQUEST", "false"),
1020
+ ])
1021
+ .await,
1022
+ "http://127.0.0.1:1/"
1023
+ );
1024
+ }
1025
+
1026
+ #[tokio::test]
1027
+ async fn empty_s3_addressing_style_is_unset() {
1028
+ assert_eq!(
1029
+ bucket_uri(&[
1030
+ ("S3_ADDRESSING_STYLE", ""),
1031
+ ("AWS_VIRTUAL_HOSTED_STYLE_REQUEST", "true")
1032
+ ])
1033
+ .await,
1034
+ "http://127.0.0.1:1/"
1035
+ );
1036
+ }
1037
+
1038
+ #[tokio::test]
1039
+ async fn object_requests_follow_s3_addressing_style() {
1040
+ let path = signed(&keyed(&[("S3_ENDPOINT", "http://127.0.0.1:1")])).await;
1041
+ assert_eq!(path.path(), "/bkt/o");
1042
+
1043
+ let virtual_hosted = signed(&keyed(&[
1044
+ ("S3_ENDPOINT", "http://127.0.0.1:1"),
1045
+ ("S3_ADDRESSING_STYLE", "virtual"),
1046
+ ]))
1047
+ .await;
1048
+ // A custom endpoint is used as is in this mode: the bucket is not in the
1049
+ // path, and the endpoint is expected to be scoped to it.
1050
+ assert_eq!(virtual_hosted.host_str(), Some("127.0.0.1"));
1051
+ assert_eq!(virtual_hosted.path(), "/o");
1052
+ }
1053
+
1054
+ #[test]
1055
+ fn unknown_s3_addressing_style_is_rejected() {
1056
+ let all = [
1057
+ ("S3_ACCESS_KEY_ID", "k"),
1058
+ ("S3_SECRET_ACCESS_KEY", "s"),
1059
+ ("S3_ADDRESSING_STYLE", "hostname"),
1060
+ ];
1061
+ let err = S3Backend::new(Some("bkt"), &Vars::from_pairs(&all), None)
1062
+ .err()
1063
+ .expect("rejected");
1064
+ assert!(
1065
+ matches!(&err, Error::InvalidInput(msg) if msg.contains("S3_ADDRESSING_STYLE")),
1066
+ "{err:?}"
1067
+ );
1068
+ }
1069
+
922
1070
  /// Whether a store with `pairs` and a custom endpoint runs unsigned.
923
1071
  fn unsigned(pairs: &[(&str, &str)]) -> bool {
924
1072
  let mut all = vec![("S3_ENDPOINT", "http://127.0.0.1:1")];