asanypath-native 2.4.0__tar.gz → 2.6.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.
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/Cargo.lock +29 -18
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/Cargo.toml +3 -2
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/PKG-INFO +1 -1
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/asanypath_native.pyi +3 -0
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/src/artifactory.rs +15 -1
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/src/azure.rs +159 -31
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/src/backend.rs +100 -0
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/src/gcs.rs +117 -40
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/src/http.rs +81 -3
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/src/lib.rs +4 -0
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/src/listing.rs +109 -28
- asanypath_native-2.6.0/src/multipart.rs +173 -0
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/src/s3.rs +236 -28
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/src/xml.rs +15 -0
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/pyproject.toml +0 -0
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/src/cache.rs +0 -0
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/src/ssh.rs +0 -0
- {asanypath_native-2.4.0 → asanypath_native-2.6.0}/uv.lock +0 -0
|
@@ -96,7 +96,7 @@ dependencies = [
|
|
|
96
96
|
|
|
97
97
|
[[package]]
|
|
98
98
|
name = "asanypath-native"
|
|
99
|
-
version = "2.
|
|
99
|
+
version = "2.6.0"
|
|
100
100
|
dependencies = [
|
|
101
101
|
"anyhow",
|
|
102
102
|
"aws-config",
|
|
@@ -108,6 +108,7 @@ dependencies = [
|
|
|
108
108
|
"futures",
|
|
109
109
|
"hmac",
|
|
110
110
|
"http 1.5.0",
|
|
111
|
+
"md-5",
|
|
111
112
|
"pem",
|
|
112
113
|
"pyo3",
|
|
113
114
|
"pyo3-async-runtimes",
|
|
@@ -892,7 +893,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
|
892
893
|
checksum = "d045de693cb712d0b22c6a64be5b953f67b3ce00ab5ad3dd5d8b441886ab8e1a"
|
|
893
894
|
dependencies = [
|
|
894
895
|
"quote",
|
|
895
|
-
"syn
|
|
896
|
+
"syn 2.0.119",
|
|
896
897
|
]
|
|
897
898
|
|
|
898
899
|
[[package]]
|
|
@@ -1195,7 +1196,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
|
1195
1196
|
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
|
1196
1197
|
dependencies = [
|
|
1197
1198
|
"libc",
|
|
1198
|
-
"windows-sys 0.
|
|
1199
|
+
"windows-sys 0.52.0",
|
|
1199
1200
|
]
|
|
1200
1201
|
|
|
1201
1202
|
[[package]]
|
|
@@ -1984,6 +1985,16 @@ dependencies = [
|
|
|
1984
1985
|
"web_atoms",
|
|
1985
1986
|
]
|
|
1986
1987
|
|
|
1988
|
+
[[package]]
|
|
1989
|
+
name = "md-5"
|
|
1990
|
+
version = "0.11.0"
|
|
1991
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1992
|
+
checksum = "69b6441f590336821bb897fb28fc622898ccceb1d6cea3fde5ea86b090c4de98"
|
|
1993
|
+
dependencies = [
|
|
1994
|
+
"cfg-if",
|
|
1995
|
+
"digest 0.11.3",
|
|
1996
|
+
]
|
|
1997
|
+
|
|
1987
1998
|
[[package]]
|
|
1988
1999
|
name = "md5"
|
|
1989
2000
|
version = "0.8.1"
|
|
@@ -2183,9 +2194,9 @@ dependencies = [
|
|
|
2183
2194
|
|
|
2184
2195
|
[[package]]
|
|
2185
2196
|
name = "pageant"
|
|
2186
|
-
version = "0.2.
|
|
2197
|
+
version = "0.2.5"
|
|
2187
2198
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2188
|
-
checksum = "
|
|
2199
|
+
checksum = "e0bc922d9aa8cfcf598de27b3c6122cb2eeda9d6fe71527a22ebcb7f633540ff"
|
|
2189
2200
|
dependencies = [
|
|
2190
2201
|
"base16ct",
|
|
2191
2202
|
"byteorder",
|
|
@@ -2627,7 +2638,7 @@ dependencies = [
|
|
|
2627
2638
|
"once_cell",
|
|
2628
2639
|
"socket2",
|
|
2629
2640
|
"tracing",
|
|
2630
|
-
"windows-sys 0.
|
|
2641
|
+
"windows-sys 0.52.0",
|
|
2631
2642
|
]
|
|
2632
2643
|
|
|
2633
2644
|
[[package]]
|
|
@@ -2878,9 +2889,9 @@ dependencies = [
|
|
|
2878
2889
|
|
|
2879
2890
|
[[package]]
|
|
2880
2891
|
name = "russh"
|
|
2881
|
-
version = "0.
|
|
2892
|
+
version = "0.65.0"
|
|
2882
2893
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2883
|
-
checksum = "
|
|
2894
|
+
checksum = "3bb77a4b259312b2abbc541bca1c13cb4e9b61c560a7fd894068c3b92e0c9dc3"
|
|
2884
2895
|
dependencies = [
|
|
2885
2896
|
"aes",
|
|
2886
2897
|
"aws-lc-rs",
|
|
@@ -3008,9 +3019,9 @@ dependencies = [
|
|
|
3008
3019
|
|
|
3009
3020
|
[[package]]
|
|
3010
3021
|
name = "rustls"
|
|
3011
|
-
version = "0.23.
|
|
3022
|
+
version = "0.23.46"
|
|
3012
3023
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
3013
|
-
checksum = "
|
|
3024
|
+
checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf"
|
|
3014
3025
|
dependencies = [
|
|
3015
3026
|
"aws-lc-rs",
|
|
3016
3027
|
"once_cell",
|
|
@@ -3288,9 +3299,9 @@ dependencies = [
|
|
|
3288
3299
|
|
|
3289
3300
|
[[package]]
|
|
3290
3301
|
name = "sha2"
|
|
3291
|
-
version = "0.11.
|
|
3302
|
+
version = "0.11.1"
|
|
3292
3303
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
3293
|
-
checksum = "
|
|
3304
|
+
checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19"
|
|
3294
3305
|
dependencies = [
|
|
3295
3306
|
"cfg-if",
|
|
3296
3307
|
"cpufeatures 0.3.1",
|
|
@@ -3512,9 +3523,9 @@ dependencies = [
|
|
|
3512
3523
|
|
|
3513
3524
|
[[package]]
|
|
3514
3525
|
name = "ssh2-config"
|
|
3515
|
-
version = "0.8.
|
|
3526
|
+
version = "0.8.2"
|
|
3516
3527
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
3517
|
-
checksum = "
|
|
3528
|
+
checksum = "7220846f1080bafaf80204d7268f7e2a1fb0609e34520d2edc3e75cfc55f4c38"
|
|
3518
3529
|
dependencies = [
|
|
3519
3530
|
"bitflags",
|
|
3520
3531
|
"dirs",
|
|
@@ -3685,9 +3696,9 @@ checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee"
|
|
|
3685
3696
|
|
|
3686
3697
|
[[package]]
|
|
3687
3698
|
name = "tokio"
|
|
3688
|
-
version = "1.53.
|
|
3699
|
+
version = "1.53.2"
|
|
3689
3700
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
3690
|
-
checksum = "
|
|
3701
|
+
checksum = "e95f91fcc7a621e8b030f6aa23c71fe9838ae2fb4d8118b75602a328f5144044"
|
|
3691
3702
|
dependencies = [
|
|
3692
3703
|
"bytes",
|
|
3693
3704
|
"libc",
|
|
@@ -3722,9 +3733,9 @@ dependencies = [
|
|
|
3722
3733
|
|
|
3723
3734
|
[[package]]
|
|
3724
3735
|
name = "tokio-util"
|
|
3725
|
-
version = "0.7.
|
|
3736
|
+
version = "0.7.20"
|
|
3726
3737
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
3727
|
-
checksum = "
|
|
3738
|
+
checksum = "e464cf451ba96ebfc6f9b6542f17ee8b8956e33f1e40d9690624e59d7a7f8a4b"
|
|
3728
3739
|
dependencies = [
|
|
3729
3740
|
"bytes",
|
|
3730
3741
|
"futures-core",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "asanypath-native"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.6.0"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
license = "MIT"
|
|
6
6
|
publish = false
|
|
@@ -32,12 +32,13 @@ ring = "0.17"
|
|
|
32
32
|
pem = "4"
|
|
33
33
|
scraper = { version = "0.27", default-features = false }
|
|
34
34
|
url = "2"
|
|
35
|
-
russh = "0.
|
|
35
|
+
russh = "0.65"
|
|
36
36
|
russh-sftp = "3"
|
|
37
37
|
tokio-util = { version = "0.7", features = ["io"] }
|
|
38
38
|
anyhow = "1"
|
|
39
39
|
ssh2-config = { version = "0.8", default-features = false, features = ["nolog"] }
|
|
40
40
|
rusqlite = { version = "0.40", features = ["bundled"] }
|
|
41
|
+
md-5 = "0.11"
|
|
41
42
|
|
|
42
43
|
[profile.release]
|
|
43
44
|
strip = "symbols"
|
|
@@ -27,6 +27,7 @@ async def s3_complete_multipart(*args: Any, **kwargs: Any) -> Any: ...
|
|
|
27
27
|
async def s3_abort_multipart(*args: Any, **kwargs: Any) -> Any: ...
|
|
28
28
|
async def s3_copy_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
29
29
|
async def s3_delete_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
30
|
+
async def s3_delete_tree(*args: Any, **kwargs: Any) -> list[str]: ...
|
|
30
31
|
async def s3_exists_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
31
32
|
async def s3_list_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
32
33
|
async def s3_head_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
@@ -60,6 +61,7 @@ async def gcs_start_resumable(*args: Any, **kwargs: Any) -> Any: ...
|
|
|
60
61
|
async def gcs_upload_chunk(*args: Any, **kwargs: Any) -> Any: ...
|
|
61
62
|
async def gcs_copy_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
62
63
|
async def gcs_delete_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
64
|
+
async def gcs_delete_tree(*args: Any, **kwargs: Any) -> list[str]: ...
|
|
63
65
|
async def gcs_exists_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
64
66
|
async def gcs_list_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
65
67
|
async def gcs_head(*args: Any, **kwargs: Any) -> Any: ...
|
|
@@ -81,6 +83,7 @@ async def az_put_block(*args: Any, **kwargs: Any) -> Any: ...
|
|
|
81
83
|
async def az_put_block_list(*args: Any, **kwargs: Any) -> Any: ...
|
|
82
84
|
async def az_copy_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
83
85
|
async def az_delete_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
86
|
+
async def az_delete_tree(*args: Any, **kwargs: Any) -> list[str]: ...
|
|
84
87
|
async def az_exists_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
85
88
|
async def az_list_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
86
89
|
async def az_head_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
@@ -65,6 +65,15 @@ pub(crate) struct ArtCreds {
|
|
|
65
65
|
mod endpoint_tests {
|
|
66
66
|
use super::ArtCreds;
|
|
67
67
|
|
|
68
|
+
#[test]
|
|
69
|
+
fn empty_token_sends_no_authorization() {
|
|
70
|
+
let anonymous = ArtCreds::new("example.com/artifactory".into(), String::new());
|
|
71
|
+
assert!(anonymous.auth_headers().is_empty());
|
|
72
|
+
let authenticated = ArtCreds::new("example.com/artifactory".into(), "t".into());
|
|
73
|
+
assert_eq!(authenticated.auth_headers().len(), 1);
|
|
74
|
+
assert_eq!(authenticated.auth_headers()[0].0, "authorization");
|
|
75
|
+
}
|
|
76
|
+
|
|
68
77
|
#[test]
|
|
69
78
|
fn complete_and_legacy_endpoints_build_the_same_urls() {
|
|
70
79
|
for endpoint in [
|
|
@@ -121,7 +130,12 @@ impl ArtCreds {
|
|
|
121
130
|
}
|
|
122
131
|
|
|
123
132
|
fn auth_headers(&self) -> Vec<(String, String)> {
|
|
124
|
-
|
|
133
|
+
// An empty token means anonymous access.
|
|
134
|
+
if self.token.is_empty() {
|
|
135
|
+
Vec::new()
|
|
136
|
+
} else {
|
|
137
|
+
bearer_headers(&self.token)
|
|
138
|
+
}
|
|
125
139
|
}
|
|
126
140
|
|
|
127
141
|
fn content_url(&self, path: &str) -> String {
|
|
@@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize};
|
|
|
23
23
|
use sha2::Sha256;
|
|
24
24
|
|
|
25
25
|
use crate::http::{do_request, do_request_light, status_to_pyerr};
|
|
26
|
-
use crate::listing::{ListEntry, Listing};
|
|
26
|
+
use crate::listing::{Keys, ListEntry, ListSink, Listing};
|
|
27
27
|
use crate::xml::local_name;
|
|
28
28
|
|
|
29
29
|
type HmacSha256 = Hmac<Sha256>;
|
|
@@ -111,7 +111,18 @@ impl AzCreds {
|
|
|
111
111
|
let now = chrono_now_rfc2822();
|
|
112
112
|
headers.push(("x-ms-date".to_string(), now));
|
|
113
113
|
headers.push(("x-ms-version".to_string(), API_VERSION.to_string()));
|
|
114
|
+
self.sign_headers(method, url, headers, params);
|
|
115
|
+
}
|
|
114
116
|
|
|
117
|
+
/// Add the SharedKey `authorization` for `headers` as given (batch
|
|
118
|
+
/// sub-requests carry `x-ms-date` but no `x-ms-version`).
|
|
119
|
+
fn sign_headers(
|
|
120
|
+
&self,
|
|
121
|
+
method: &str,
|
|
122
|
+
url: &str,
|
|
123
|
+
headers: &mut Vec<(String, String)>,
|
|
124
|
+
params: Option<&[(&str, &str)]>,
|
|
125
|
+
) {
|
|
115
126
|
let key_bytes = match &self.key_bytes {
|
|
116
127
|
Some(kb) => kb,
|
|
117
128
|
None => return, // SAS auth or no key, no signing needed
|
|
@@ -428,47 +439,131 @@ async fn do_az_is_dir(creds: &AzCreds, prefix: &str, use_h2: bool) -> Result<boo
|
|
|
428
439
|
Ok(false)
|
|
429
440
|
}
|
|
430
441
|
|
|
442
|
+
/// Fetch one List Blobs page into `sink`; returns the next marker.
|
|
443
|
+
/// Without `delimiter` the page holds every blob at any depth.
|
|
444
|
+
async fn az_list_page(
|
|
445
|
+
creds: &AzCreds,
|
|
446
|
+
search_prefix: &str,
|
|
447
|
+
delimiter: bool,
|
|
448
|
+
marker: Option<String>,
|
|
449
|
+
use_h2: bool,
|
|
450
|
+
sink: &mut impl ListSink,
|
|
451
|
+
) -> Result<Option<String>, PyErr> {
|
|
452
|
+
let mut params: Vec<(&str, &str)> = vec![
|
|
453
|
+
("restype", "container"),
|
|
454
|
+
("comp", "list"),
|
|
455
|
+
("prefix", search_prefix),
|
|
456
|
+
];
|
|
457
|
+
if delimiter {
|
|
458
|
+
params.push(("delimiter", "/"));
|
|
459
|
+
}
|
|
460
|
+
if let Some(marker) = marker.as_deref().filter(|m| !m.is_empty()) {
|
|
461
|
+
params.push(("marker", marker));
|
|
462
|
+
}
|
|
463
|
+
let url = creds.list_url(¶ms);
|
|
464
|
+
let mut headers = Vec::new();
|
|
465
|
+
creds.sign("GET", &url, &mut headers, Some(¶ms));
|
|
466
|
+
let (status, body) = do_request_light("GET", &url, &headers, None, use_h2)
|
|
467
|
+
.await
|
|
468
|
+
.map_err(PyRuntimeError::new_err)?;
|
|
469
|
+
if !status.is_success() {
|
|
470
|
+
return Err(status_to_pyerr(
|
|
471
|
+
status,
|
|
472
|
+
&format!("az://{}/{}", creds.container, search_prefix),
|
|
473
|
+
&body,
|
|
474
|
+
));
|
|
475
|
+
}
|
|
476
|
+
Ok(parse_az_listing_page(&body, sink))
|
|
477
|
+
}
|
|
478
|
+
|
|
431
479
|
async fn do_az_list(creds: &AzCreds, prefix: &str, use_h2: bool) -> Result<Vec<ListEntry>, PyErr> {
|
|
432
480
|
let mut listing = Listing::new(format!("az://{}", creds.container), prefix);
|
|
433
481
|
let search_prefix = listing.search_prefix().to_string();
|
|
434
|
-
let mut marker
|
|
435
|
-
|
|
482
|
+
let mut marker = None;
|
|
436
483
|
loop {
|
|
437
|
-
|
|
438
|
-
let mut params: Vec<(&str, &str)> = vec![
|
|
439
|
-
("restype", "container"),
|
|
440
|
-
("comp", "list"),
|
|
441
|
-
("prefix", &search_prefix),
|
|
442
|
-
("delimiter", "/"),
|
|
443
|
-
];
|
|
444
|
-
if !marker_str.is_empty() {
|
|
445
|
-
params.push(("marker", &marker_str));
|
|
446
|
-
}
|
|
447
|
-
let url = creds.list_url(¶ms);
|
|
448
|
-
let mut headers = Vec::new();
|
|
449
|
-
creds.sign("GET", &url, &mut headers, Some(¶ms));
|
|
450
|
-
let (status, body) = do_request_light("GET", &url, &headers, None, use_h2)
|
|
451
|
-
.await
|
|
452
|
-
.map_err(|e| PyRuntimeError::new_err(e))?;
|
|
453
|
-
if !status.is_success() {
|
|
454
|
-
return Err(status_to_pyerr(
|
|
455
|
-
status,
|
|
456
|
-
&format!("az://{}/{}", creds.container, search_prefix),
|
|
457
|
-
&body,
|
|
458
|
-
));
|
|
459
|
-
}
|
|
460
|
-
marker = parse_az_listing_page(&body, &mut listing);
|
|
484
|
+
marker = az_list_page(creds, &search_prefix, true, marker, use_h2, &mut listing).await?;
|
|
461
485
|
if marker.is_none() {
|
|
462
|
-
|
|
486
|
+
return Ok(listing.finish());
|
|
463
487
|
}
|
|
464
488
|
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
impl crate::backend::TreeDelete for AzCreds {
|
|
492
|
+
async fn list_keys_page(
|
|
493
|
+
&self,
|
|
494
|
+
search_prefix: &str,
|
|
495
|
+
token: Option<String>,
|
|
496
|
+
use_h2: bool,
|
|
497
|
+
) -> Result<(Vec<String>, Option<String>), PyErr> {
|
|
498
|
+
let mut keys = Keys::default();
|
|
499
|
+
let next = az_list_page(self, search_prefix, false, token, use_h2, &mut keys).await?;
|
|
500
|
+
Ok((keys.0, next))
|
|
501
|
+
}
|
|
465
502
|
|
|
466
|
-
|
|
503
|
+
/// One Blob Batch request per 256 blobs.
|
|
504
|
+
async fn delete_keys(&self, keys: Vec<String>, use_h2: bool) -> Result<(), PyErr> {
|
|
505
|
+
let batches: Vec<_> = keys
|
|
506
|
+
.chunks(AZ_BATCH_MAX)
|
|
507
|
+
.map(|blobs| az_batch_delete(self, blobs, use_h2))
|
|
508
|
+
.collect();
|
|
509
|
+
crate::backend::run_batches(batches).await
|
|
510
|
+
}
|
|
467
511
|
}
|
|
468
512
|
|
|
469
|
-
|
|
513
|
+
/// Sub-requests per Blob Batch request (the Azure maximum).
|
|
514
|
+
const AZ_BATCH_MAX: usize = 256;
|
|
515
|
+
|
|
516
|
+
/// Delete up to 256 blobs with one container-scoped Blob Batch request.
|
|
517
|
+
/// Each sub-request is authorized on its own and carries no `x-ms-version`:
|
|
518
|
+
/// the batch's version applies.
|
|
519
|
+
async fn az_batch_delete(creds: &AzCreds, blobs: &[String], use_h2: bool) -> Result<(), PyErr> {
|
|
520
|
+
let requests: Vec<String> = blobs
|
|
521
|
+
.iter()
|
|
522
|
+
.map(|blob| {
|
|
523
|
+
let url = creds.blob_url(blob);
|
|
524
|
+
let mut headers = vec![
|
|
525
|
+
("x-ms-date".to_string(), chrono_now_rfc2822()),
|
|
526
|
+
("content-length".to_string(), "0".to_string()),
|
|
527
|
+
];
|
|
528
|
+
creds.sign_headers("DELETE", &url, &mut headers, None);
|
|
529
|
+
let mut request = format!("DELETE {} HTTP/1.1", crate::multipart::path_of(&url));
|
|
530
|
+
for (name, value) in &headers {
|
|
531
|
+
request.push_str(&format!("\r\n{name}: {value}"));
|
|
532
|
+
}
|
|
533
|
+
request
|
|
534
|
+
})
|
|
535
|
+
.collect();
|
|
536
|
+
let boundary = crate::multipart::boundary();
|
|
537
|
+
let body = crate::multipart::body(&boundary, &requests);
|
|
538
|
+
let params = [("restype", "container"), ("comp", "batch")];
|
|
539
|
+
let url = creds.list_url(¶ms);
|
|
540
|
+
let mut headers = vec![
|
|
541
|
+
(
|
|
542
|
+
"content-type".to_string(),
|
|
543
|
+
format!("multipart/mixed; boundary={boundary}"),
|
|
544
|
+
),
|
|
545
|
+
("content-length".to_string(), body.len().to_string()),
|
|
546
|
+
];
|
|
547
|
+
creds.sign("POST", &url, &mut headers, Some(¶ms));
|
|
548
|
+
let (status, response) =
|
|
549
|
+
do_request_light("POST", &url, &headers, Some(Bytes::from(body)), use_h2)
|
|
550
|
+
.await
|
|
551
|
+
.map_err(PyRuntimeError::new_err)?;
|
|
552
|
+
if !status.is_success() {
|
|
553
|
+
return Err(status_to_pyerr(
|
|
554
|
+
status,
|
|
555
|
+
&format!("az://{}", creds.container),
|
|
556
|
+
&response,
|
|
557
|
+
));
|
|
558
|
+
}
|
|
559
|
+
let statuses = crate::multipart::statuses(&response);
|
|
560
|
+
crate::multipart::check_deletes(statuses, blobs, |blob| creds.error_path(blob))
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
fn parse_az_listing_page(body: &[u8], listing: &mut impl ListSink) -> Option<String> {
|
|
564
|
+
// Untrimmed: blob names may start or end with spaces. Text is only read
|
|
565
|
+
// inside leaf elements, so whitespace between elements is never used.
|
|
470
566
|
let mut reader = Reader::from_reader(body);
|
|
471
|
-
reader.config_mut().trim_text(true);
|
|
472
567
|
let mut buf = Vec::new();
|
|
473
568
|
let mut text = String::new();
|
|
474
569
|
let mut in_blob = false;
|
|
@@ -495,6 +590,7 @@ fn parse_az_listing_page(body: &[u8], listing: &mut Listing) -> Option<String> {
|
|
|
495
590
|
text.clear();
|
|
496
591
|
}
|
|
497
592
|
Ok(Event::Text(e)) => text.push_str(&e.xml10_content()),
|
|
593
|
+
Ok(Event::GeneralRef(e)) => crate::xml::push_reference(&mut text, &e),
|
|
498
594
|
Ok(Event::End(e)) => {
|
|
499
595
|
let tag = e.name();
|
|
500
596
|
match local_name(tag.as_ref()) {
|
|
@@ -1039,6 +1135,25 @@ pub fn az_delete_batch<'py>(
|
|
|
1039
1135
|
})
|
|
1040
1136
|
}
|
|
1041
1137
|
|
|
1138
|
+
/// Delete every blob under `prefix`.
|
|
1139
|
+
#[pyfunction]
|
|
1140
|
+
pub fn az_delete_tree<'py>(
|
|
1141
|
+
py: Python<'py>,
|
|
1142
|
+
endpoint: String,
|
|
1143
|
+
container: String,
|
|
1144
|
+
prefix: String,
|
|
1145
|
+
account_name: String,
|
|
1146
|
+
account_key: Option<String>,
|
|
1147
|
+
sas_token: Option<String>,
|
|
1148
|
+
use_h2: Option<bool>,
|
|
1149
|
+
) -> PyResult<Bound<'py, PyAny>> {
|
|
1150
|
+
let h2 = use_h2.unwrap_or(false);
|
|
1151
|
+
pyo3_async_runtimes::tokio::future_into_py(py, async move {
|
|
1152
|
+
let creds = az_creds!(endpoint, container, account_name, account_key, sas_token);
|
|
1153
|
+
crate::backend::TreeDelete::delete_tree(&creds, &prefix, h2).await
|
|
1154
|
+
})
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1042
1157
|
#[pyfunction]
|
|
1043
1158
|
pub fn az_exists_batch<'py>(
|
|
1044
1159
|
py: Python<'py>,
|
|
@@ -1190,4 +1305,17 @@ mod tests {
|
|
|
1190
1305
|
]
|
|
1191
1306
|
);
|
|
1192
1307
|
}
|
|
1308
|
+
|
|
1309
|
+
#[test]
|
|
1310
|
+
fn listing_keeps_escaped_characters_and_edge_spaces() {
|
|
1311
|
+
let body = br#"<EnumerationResults><Blobs>
|
|
1312
|
+
<Blob><Name>dir/a & b.txt</Name></Blob>
|
|
1313
|
+
<Blob>
|
|
1314
|
+
<Name> dir/ lead "x" </Name>
|
|
1315
|
+
</Blob>
|
|
1316
|
+
</Blobs><NextMarker /></EnumerationResults>"#;
|
|
1317
|
+
let mut keys = super::Keys::default();
|
|
1318
|
+
assert_eq!(parse_az_listing_page(body, &mut keys), None);
|
|
1319
|
+
assert_eq!(keys.0, vec!["dir/a & b.txt", " dir/ lead \"x\" "]);
|
|
1320
|
+
}
|
|
1193
1321
|
}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* https://opensource.org/licenses/MIT.
|
|
14
14
|
*/
|
|
15
15
|
use bytes::Bytes;
|
|
16
|
+
use futures::{StreamExt, TryStreamExt};
|
|
16
17
|
use pyo3::PyErr;
|
|
17
18
|
use pyo3::exceptions::PyRuntimeError;
|
|
18
19
|
use pyo3::exceptions::PyValueError;
|
|
@@ -281,6 +282,105 @@ pub trait CloudBackend {
|
|
|
281
282
|
) -> impl std::future::Future<Output = Result<(), PyErr>>;
|
|
282
283
|
}
|
|
283
284
|
|
|
285
|
+
/// Object DELETEs in flight per tree delete. An unbounded fan-out opens one
|
|
286
|
+
/// connection per object; at a 20 ms round trip, 64 deletes about 3,200 keys a
|
|
287
|
+
/// second, under S3's 3,500 writes per second per prefix.
|
|
288
|
+
pub const TREE_DELETE_CONCURRENCY: usize = 64;
|
|
289
|
+
|
|
290
|
+
/// Batch requests in flight per tree-delete page: a 1,000-key GCS page is 10
|
|
291
|
+
/// batches of 100. 1/2/4/8 in flight took 0.37/0.21/0.17/0.15 s for 1,000
|
|
292
|
+
/// objects at a 20 ms round trip; 4 keeps at most 400 deletes in flight.
|
|
293
|
+
pub const BATCHES_IN_FLIGHT: usize = 4;
|
|
294
|
+
|
|
295
|
+
/// Run `batches` (one future per batch request), at most
|
|
296
|
+
/// [`BATCHES_IN_FLIGHT`] at a time.
|
|
297
|
+
pub async fn run_batches<Fut>(batches: Vec<Fut>) -> Result<(), PyErr>
|
|
298
|
+
where
|
|
299
|
+
Fut: std::future::Future<Output = Result<(), PyErr>>,
|
|
300
|
+
{
|
|
301
|
+
futures::stream::iter(batches)
|
|
302
|
+
.buffer_unordered(BATCHES_IN_FLIGHT)
|
|
303
|
+
.try_for_each(|()| async { Ok(()) })
|
|
304
|
+
.await
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/// One DELETE per key, at most [`TREE_DELETE_CONCURRENCY`] in flight; a key
|
|
308
|
+
/// that is already gone counts as deleted.
|
|
309
|
+
pub async fn delete_each<B: CloudBackend + ?Sized>(
|
|
310
|
+
backend: &B,
|
|
311
|
+
keys: Vec<String>,
|
|
312
|
+
use_h2: bool,
|
|
313
|
+
) -> Result<(), PyErr> {
|
|
314
|
+
futures::stream::iter(keys)
|
|
315
|
+
.map(|key| async move {
|
|
316
|
+
let (status, body) = backend
|
|
317
|
+
.do_request("DELETE", &key, None, use_h2, &[])
|
|
318
|
+
.await
|
|
319
|
+
.map_err(PyRuntimeError::new_err)?;
|
|
320
|
+
if status.is_success() || status == StatusCode::NOT_FOUND {
|
|
321
|
+
Ok(())
|
|
322
|
+
} else {
|
|
323
|
+
Err(status_to_pyerr(status, &backend.error_path(&key), &body))
|
|
324
|
+
}
|
|
325
|
+
})
|
|
326
|
+
.buffer_unordered(TREE_DELETE_CONCURRENCY)
|
|
327
|
+
.try_for_each(|()| async { Ok(()) })
|
|
328
|
+
.await
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/// Recursive delete for object stores addressed by key prefix.
|
|
332
|
+
pub trait TreeDelete: CloudBackend {
|
|
333
|
+
/// One page of every object key under `search_prefix`, listed without a
|
|
334
|
+
/// delimiter, and the token of the next page.
|
|
335
|
+
fn list_keys_page(
|
|
336
|
+
&self,
|
|
337
|
+
search_prefix: &str,
|
|
338
|
+
token: Option<String>,
|
|
339
|
+
use_h2: bool,
|
|
340
|
+
) -> impl std::future::Future<Output = Result<(Vec<String>, Option<String>), PyErr>>;
|
|
341
|
+
|
|
342
|
+
/// Delete `keys`; a key that is already gone counts as deleted.
|
|
343
|
+
fn delete_keys(
|
|
344
|
+
&self,
|
|
345
|
+
keys: Vec<String>,
|
|
346
|
+
use_h2: bool,
|
|
347
|
+
) -> impl std::future::Future<Output = Result<(), PyErr>> {
|
|
348
|
+
delete_each(self, keys, use_h2)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/// Delete every object under `prefix` (marker keys included), deleting
|
|
352
|
+
/// each listing page while the next one is fetched. Returns the keys left
|
|
353
|
+
/// in place because a request path could not address them (see
|
|
354
|
+
/// [`crate::listing::plain_key`]).
|
|
355
|
+
fn delete_tree(
|
|
356
|
+
&self,
|
|
357
|
+
prefix: &str,
|
|
358
|
+
use_h2: bool,
|
|
359
|
+
) -> impl std::future::Future<Output = Result<Vec<String>, PyErr>> {
|
|
360
|
+
async move {
|
|
361
|
+
let search = crate::listing::search_prefix(prefix);
|
|
362
|
+
let mut skipped = Vec::new();
|
|
363
|
+
let (mut keys, mut token) = self.list_keys_page(&search, None, use_h2).await?;
|
|
364
|
+
loop {
|
|
365
|
+
let (plain, other): (Vec<_>, Vec<_>) = std::mem::take(&mut keys)
|
|
366
|
+
.into_iter()
|
|
367
|
+
.partition(|key| crate::listing::plain_key(key, &search));
|
|
368
|
+
skipped.extend(other);
|
|
369
|
+
let Some(next) = token.take() else {
|
|
370
|
+
self.delete_keys(plain, use_h2).await?;
|
|
371
|
+
return Ok(skipped);
|
|
372
|
+
};
|
|
373
|
+
let (deleted, listed) = tokio::join!(
|
|
374
|
+
self.delete_keys(plain, use_h2),
|
|
375
|
+
self.list_keys_page(&search, Some(next), use_h2),
|
|
376
|
+
);
|
|
377
|
+
deleted?;
|
|
378
|
+
(keys, token) = listed?;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
284
384
|
// ---------------------------------------------------------------------------
|
|
285
385
|
// Batch macros — eliminate repetitive join_all boilerplate in pyfunctions
|
|
286
386
|
// ---------------------------------------------------------------------------
|