asanypath-native 2.3.1__tar.gz → 2.4.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.3.1 → asanypath_native-2.4.0}/Cargo.lock +13 -13
- {asanypath_native-2.3.1 → asanypath_native-2.4.0}/Cargo.toml +2 -2
- {asanypath_native-2.3.1 → asanypath_native-2.4.0}/PKG-INFO +1 -1
- {asanypath_native-2.3.1 → asanypath_native-2.4.0}/asanypath_native.pyi +4 -4
- {asanypath_native-2.3.1 → asanypath_native-2.4.0}/pyproject.toml +10 -0
- {asanypath_native-2.3.1 → asanypath_native-2.4.0}/src/artifactory.rs +77 -30
- {asanypath_native-2.3.1 → asanypath_native-2.4.0}/src/azure.rs +100 -136
- {asanypath_native-2.3.1 → asanypath_native-2.4.0}/src/cache.rs +40 -5
- {asanypath_native-2.3.1 → asanypath_native-2.4.0}/src/gcs.rs +17 -67
- {asanypath_native-2.3.1 → asanypath_native-2.4.0}/src/http.rs +129 -23
- {asanypath_native-2.3.1 → asanypath_native-2.4.0}/src/lib.rs +4 -3
- asanypath_native-2.4.0/src/listing.rs +131 -0
- {asanypath_native-2.3.1 → asanypath_native-2.4.0}/src/s3.rs +73 -140
- {asanypath_native-2.3.1 → asanypath_native-2.4.0}/src/ssh.rs +295 -293
- {asanypath_native-2.3.1 → asanypath_native-2.4.0}/src/backend.rs +0 -0
- {asanypath_native-2.3.1 → asanypath_native-2.4.0}/src/xml.rs +0 -0
- {asanypath_native-2.3.1 → asanypath_native-2.4.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.4.0"
|
|
100
100
|
dependencies = [
|
|
101
101
|
"anyhow",
|
|
102
102
|
"aws-config",
|
|
@@ -2496,9 +2496,9 @@ dependencies = [
|
|
|
2496
2496
|
|
|
2497
2497
|
[[package]]
|
|
2498
2498
|
name = "pyo3"
|
|
2499
|
-
version = "0.29.
|
|
2499
|
+
version = "0.29.3"
|
|
2500
2500
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2501
|
-
checksum = "
|
|
2501
|
+
checksum = "700d18fa267b73b9b521fd7e13580e2f446916f176cacee1ab63fcc8191f1655"
|
|
2502
2502
|
dependencies = [
|
|
2503
2503
|
"libc",
|
|
2504
2504
|
"once_cell",
|
|
@@ -2524,18 +2524,18 @@ dependencies = [
|
|
|
2524
2524
|
|
|
2525
2525
|
[[package]]
|
|
2526
2526
|
name = "pyo3-build-config"
|
|
2527
|
-
version = "0.29.
|
|
2527
|
+
version = "0.29.3"
|
|
2528
2528
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2529
|
-
checksum = "
|
|
2529
|
+
checksum = "7b3fc0c4d08f6bb10e71fe39dfb9e2f59c6eb6854e22ec8092f50c69a4499adb"
|
|
2530
2530
|
dependencies = [
|
|
2531
2531
|
"target-lexicon",
|
|
2532
2532
|
]
|
|
2533
2533
|
|
|
2534
2534
|
[[package]]
|
|
2535
2535
|
name = "pyo3-ffi"
|
|
2536
|
-
version = "0.29.
|
|
2536
|
+
version = "0.29.3"
|
|
2537
2537
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2538
|
-
checksum = "
|
|
2538
|
+
checksum = "dfc0b8e19df29aad7086cf977bb0c2a2f143e30567eb113e9cf72b62ca698330"
|
|
2539
2539
|
dependencies = [
|
|
2540
2540
|
"libc",
|
|
2541
2541
|
"pyo3-build-config",
|
|
@@ -2543,9 +2543,9 @@ dependencies = [
|
|
|
2543
2543
|
|
|
2544
2544
|
[[package]]
|
|
2545
2545
|
name = "pyo3-macros"
|
|
2546
|
-
version = "0.29.
|
|
2546
|
+
version = "0.29.3"
|
|
2547
2547
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2548
|
-
checksum = "
|
|
2548
|
+
checksum = "6100e8a4b5eba53afaa5ed078364851a0b2499c553a44c31026b929049b49dc6"
|
|
2549
2549
|
dependencies = [
|
|
2550
2550
|
"proc-macro2",
|
|
2551
2551
|
"pyo3-macros-backend",
|
|
@@ -2555,9 +2555,9 @@ dependencies = [
|
|
|
2555
2555
|
|
|
2556
2556
|
[[package]]
|
|
2557
2557
|
name = "pyo3-macros-backend"
|
|
2558
|
-
version = "0.29.
|
|
2558
|
+
version = "0.29.3"
|
|
2559
2559
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2560
|
-
checksum = "
|
|
2560
|
+
checksum = "6143877a16e82b5a727b7127ff4cd86858a24a28d745d72f43e6f227c7b1bdb3"
|
|
2561
2561
|
dependencies = [
|
|
2562
2562
|
"heck",
|
|
2563
2563
|
"proc-macro2",
|
|
@@ -2878,9 +2878,9 @@ dependencies = [
|
|
|
2878
2878
|
|
|
2879
2879
|
[[package]]
|
|
2880
2880
|
name = "russh"
|
|
2881
|
-
version = "0.
|
|
2881
|
+
version = "0.64.1"
|
|
2882
2882
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2883
|
-
checksum = "
|
|
2883
|
+
checksum = "ba61e87b9ec9a39a59a6bbed4c0b8ff7fb07073405b24a767a1f2c8560ac8f58"
|
|
2884
2884
|
dependencies = [
|
|
2885
2885
|
"aes",
|
|
2886
2886
|
"aws-lc-rs",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "asanypath-native"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.4.0"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
license = "MIT"
|
|
6
6
|
publish = false
|
|
@@ -32,7 +32,7 @@ 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.64"
|
|
36
36
|
russh-sftp = "3"
|
|
37
37
|
tokio-util = { version = "0.7", features = ["io"] }
|
|
38
38
|
anyhow = "1"
|
|
@@ -31,7 +31,6 @@ async def s3_exists_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
|
31
31
|
async def s3_list_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
32
32
|
async def s3_head_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
33
33
|
async def s3_is_dir(*args: Any, **kwargs: Any) -> Any: ...
|
|
34
|
-
async def s3_is_dir_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
35
34
|
async def s3_list_buckets(*args: Any, **kwargs: Any) -> Any: ...
|
|
36
35
|
async def s3_get_acl(*args: Any, **kwargs: Any) -> Any: ...
|
|
37
36
|
async def s3_put_acl(*args: Any, **kwargs: Any) -> Any: ...
|
|
@@ -66,7 +65,6 @@ async def gcs_list_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
|
66
65
|
async def gcs_head(*args: Any, **kwargs: Any) -> Any: ...
|
|
67
66
|
async def gcs_head_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
68
67
|
async def gcs_is_dir(*args: Any, **kwargs: Any) -> Any: ...
|
|
69
|
-
async def gcs_is_dir_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
70
68
|
async def gcs_list_buckets(*args: Any, **kwargs: Any) -> Any: ...
|
|
71
69
|
def gcs_presign(
|
|
72
70
|
bucket: str,
|
|
@@ -87,7 +85,6 @@ async def az_exists_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
|
87
85
|
async def az_list_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
88
86
|
async def az_head_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
89
87
|
async def az_is_dir(*args: Any, **kwargs: Any) -> Any: ...
|
|
90
|
-
async def az_is_dir_batch(*args: Any, **kwargs: Any) -> Any: ...
|
|
91
88
|
async def az_list_containers(*args: Any, **kwargs: Any) -> Any: ...
|
|
92
89
|
def az_presign(
|
|
93
90
|
endpoint: str,
|
|
@@ -142,5 +139,8 @@ async def ssh_unlink(*args: Any, **kwargs: Any) -> None: ...
|
|
|
142
139
|
async def ssh_rename(*args: Any, **kwargs: Any) -> None: ...
|
|
143
140
|
def ssh_resolve_config(
|
|
144
141
|
host: str, config_paths: list[str]
|
|
145
|
-
) -> tuple[str | None, int | None, str | None, str | None]: ...
|
|
142
|
+
) -> tuple[str | None, int | None, str | None, str | None, str | None, str | None]: ...
|
|
146
143
|
def ssh_disconnect_all() -> None: ...
|
|
144
|
+
def ssh_known_host(host: str, port: int, known_hosts: str) -> bool: ...
|
|
145
|
+
async def ssh_scan_host_key(host: str, port: int) -> tuple[str, str]: ...
|
|
146
|
+
def ssh_learn_host_key(host: str, port: int, public_key: str, known_hosts: str) -> None: ...
|
|
@@ -13,3 +13,13 @@ license = "MIT"
|
|
|
13
13
|
manifest-path = "Cargo.toml"
|
|
14
14
|
module-name = "asanypath_native"
|
|
15
15
|
features = ["pyo3/extension-module"]
|
|
16
|
+
|
|
17
|
+
[tool.uv]
|
|
18
|
+
# Rebuild local installs when native sources change; the version alone does not.
|
|
19
|
+
cache-keys = [
|
|
20
|
+
{ file = "pyproject.toml" },
|
|
21
|
+
{ file = "Cargo.toml" },
|
|
22
|
+
{ file = "Cargo.lock" },
|
|
23
|
+
{ file = "asanypath_native.pyi" },
|
|
24
|
+
{ file = "src/**/*.rs" },
|
|
25
|
+
]
|
|
@@ -56,40 +56,95 @@ struct RepoEntry {
|
|
|
56
56
|
// ---------------------------------------------------------------------------
|
|
57
57
|
|
|
58
58
|
pub(crate) struct ArtCreds {
|
|
59
|
-
///
|
|
60
|
-
|
|
59
|
+
/// Complete service URL, e.g. "https://artifacts.example.com/artifactory".
|
|
60
|
+
endpoint_url: String,
|
|
61
61
|
token: String,
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
#[cfg(test)]
|
|
65
|
+
mod endpoint_tests {
|
|
66
|
+
use super::ArtCreds;
|
|
67
|
+
|
|
68
|
+
#[test]
|
|
69
|
+
fn complete_and_legacy_endpoints_build_the_same_urls() {
|
|
70
|
+
for endpoint in [
|
|
71
|
+
"example.com/artifactory",
|
|
72
|
+
"https://example.com/artifactory",
|
|
73
|
+
"https://example.com/artifactory/",
|
|
74
|
+
] {
|
|
75
|
+
let creds = ArtCreds::new(endpoint.into(), "token".into());
|
|
76
|
+
assert_eq!(
|
|
77
|
+
creds.content_url("/repo/key"),
|
|
78
|
+
"https://example.com/artifactory/repo/key"
|
|
79
|
+
);
|
|
80
|
+
assert_eq!(
|
|
81
|
+
creds.storage_url("/repo/key"),
|
|
82
|
+
"https://example.com/artifactory/api/storage/repo/key"
|
|
83
|
+
);
|
|
84
|
+
assert_eq!(
|
|
85
|
+
creds.permission_target_url("read all"),
|
|
86
|
+
"https://example.com/artifactory/api/security/permissions/read%20all"
|
|
87
|
+
);
|
|
88
|
+
assert_eq!(
|
|
89
|
+
creds.path_url("repo/key"),
|
|
90
|
+
"art://example.com/artifactory/repo/key"
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#[test]
|
|
96
|
+
fn explicit_http_endpoint_is_preserved() {
|
|
97
|
+
let creds = ArtCreds::new("http://localhost:8080/artifactory".into(), "token".into());
|
|
98
|
+
assert_eq!(
|
|
99
|
+
creds.content_url("repo/key"),
|
|
100
|
+
"http://localhost:8080/artifactory/repo/key"
|
|
101
|
+
);
|
|
102
|
+
assert_eq!(
|
|
103
|
+
creds.path_url("repo/key"),
|
|
104
|
+
"art://localhost:8080/artifactory/repo/key"
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
64
109
|
impl ArtCreds {
|
|
65
110
|
pub(crate) fn new(base_url: String, token: String) -> Self {
|
|
66
|
-
|
|
111
|
+
// Accept legacy native callers passing a scheme-less base_url.
|
|
112
|
+
let endpoint_url = if base_url.starts_with("https://") || base_url.starts_with("http://") {
|
|
113
|
+
base_url
|
|
114
|
+
} else {
|
|
115
|
+
format!("https://{}", base_url)
|
|
116
|
+
};
|
|
117
|
+
Self {
|
|
118
|
+
endpoint_url: endpoint_url.trim_end_matches('/').to_string(),
|
|
119
|
+
token,
|
|
120
|
+
}
|
|
67
121
|
}
|
|
68
122
|
|
|
69
123
|
fn auth_headers(&self) -> Vec<(String, String)> {
|
|
70
124
|
bearer_headers(&self.token)
|
|
71
125
|
}
|
|
72
126
|
|
|
73
|
-
/// Build the content URL: https://{base_url}/{path}
|
|
74
127
|
fn content_url(&self, path: &str) -> String {
|
|
75
|
-
format!("
|
|
128
|
+
format!("{}/{}", self.endpoint_url, path.trim_start_matches('/'))
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
fn path_url(&self, path: &str) -> String {
|
|
132
|
+
let base = self.endpoint_url.split_once("://").unwrap().1;
|
|
133
|
+
format!("art://{}/{}", base, path.trim_start_matches('/'))
|
|
76
134
|
}
|
|
77
135
|
|
|
78
136
|
/// Build the storage API URL: https://{base}/api/storage/{repo_path}
|
|
79
137
|
/// Input path is like "repo/folder/file.txt"
|
|
80
138
|
fn storage_url(&self, path: &str) -> String {
|
|
81
|
-
|
|
82
|
-
// base_url = "host/artifactory", path = "repo/path"
|
|
83
|
-
// result = "https://host/artifactory/api/storage/repo/path"
|
|
84
|
-
let base = self.base_url.trim_end_matches('/');
|
|
139
|
+
let base = &self.endpoint_url;
|
|
85
140
|
let trimmed_path = path.trim_start_matches('/');
|
|
86
|
-
format!("
|
|
141
|
+
format!("{}/api/storage/{}", base, trimmed_path)
|
|
87
142
|
}
|
|
88
143
|
|
|
89
144
|
fn permission_target_url(&self, name: &str) -> String {
|
|
90
|
-
let base = self.
|
|
145
|
+
let base = &self.endpoint_url;
|
|
91
146
|
format!(
|
|
92
|
-
"
|
|
147
|
+
"{}/api/security/permissions/{}",
|
|
93
148
|
base,
|
|
94
149
|
urlencoding::encode(name)
|
|
95
150
|
)
|
|
@@ -98,10 +153,7 @@ impl ArtCreds {
|
|
|
98
153
|
|
|
99
154
|
macro_rules! art_creds {
|
|
100
155
|
($base_url:expr, $token:expr) => {
|
|
101
|
-
ArtCreds
|
|
102
|
-
base_url: $base_url,
|
|
103
|
-
token: $token,
|
|
104
|
-
}
|
|
156
|
+
ArtCreds::new($base_url, $token)
|
|
105
157
|
};
|
|
106
158
|
}
|
|
107
159
|
|
|
@@ -148,7 +200,7 @@ impl CloudBackend for ArtCreds {
|
|
|
148
200
|
}
|
|
149
201
|
|
|
150
202
|
fn error_path(&self, path: &str) -> String {
|
|
151
|
-
|
|
203
|
+
self.path_url(path)
|
|
152
204
|
}
|
|
153
205
|
|
|
154
206
|
fn put(
|
|
@@ -189,11 +241,11 @@ impl CloudBackend for ArtCreds {
|
|
|
189
241
|
let options = options.clone();
|
|
190
242
|
async move {
|
|
191
243
|
crate::backend::require_empty_provider(&options)?;
|
|
192
|
-
let base = self.
|
|
244
|
+
let base = &self.endpoint_url;
|
|
193
245
|
let src_trim = src.trim_start_matches('/');
|
|
194
246
|
let dst_trim = dst.trim_start_matches('/');
|
|
195
247
|
let url = crate::backend::append_query(
|
|
196
|
-
&format!("
|
|
248
|
+
&format!("{}/api/copy/{}?to=/{}", base, src_trim, dst_trim),
|
|
197
249
|
&options.query,
|
|
198
250
|
);
|
|
199
251
|
let mut headers = self.auth_headers();
|
|
@@ -285,11 +337,7 @@ async fn do_art_storage_info(
|
|
|
285
337
|
.await
|
|
286
338
|
.map_err(|e| PyRuntimeError::new_err(e))?;
|
|
287
339
|
if !status.is_success() {
|
|
288
|
-
return Err(status_to_pyerr(
|
|
289
|
-
status,
|
|
290
|
-
&format!("art://{}/{}", creds.base_url, path),
|
|
291
|
-
&body,
|
|
292
|
-
));
|
|
340
|
+
return Err(status_to_pyerr(status, &creds.path_url(path), &body));
|
|
293
341
|
}
|
|
294
342
|
let info: StorageInfo = sonic_rs::from_slice(&body)
|
|
295
343
|
.map_err(|e| PyRuntimeError::new_err(format!("JSON parse error: {e}")))?;
|
|
@@ -304,7 +352,7 @@ async fn do_art_list(
|
|
|
304
352
|
let info = do_art_storage_info(creds, path, use_h2).await?;
|
|
305
353
|
match info.children {
|
|
306
354
|
Some(children) => {
|
|
307
|
-
let base =
|
|
355
|
+
let base = creds.path_url(path.trim_end_matches('/'));
|
|
308
356
|
let results: Vec<(String, bool)> = children
|
|
309
357
|
.iter()
|
|
310
358
|
.map(|child| {
|
|
@@ -315,16 +363,15 @@ async fn do_art_list(
|
|
|
315
363
|
Ok(results)
|
|
316
364
|
}
|
|
317
365
|
None => Err(pyo3::exceptions::PyNotADirectoryError::new_err(format!(
|
|
318
|
-
"Not a directory: '
|
|
319
|
-
creds.
|
|
366
|
+
"Not a directory: '{}'",
|
|
367
|
+
creds.path_url(path)
|
|
320
368
|
))),
|
|
321
369
|
}
|
|
322
370
|
}
|
|
323
371
|
|
|
324
372
|
/// List all repositories (GET /api/repositories). Returns bare repository keys.
|
|
325
373
|
async fn do_art_list_repos(creds: &ArtCreds, use_h2: bool) -> Result<Vec<String>, PyErr> {
|
|
326
|
-
let
|
|
327
|
-
let url = format!("https://{}/api/repositories", base);
|
|
374
|
+
let url = format!("{}/api/repositories", creds.endpoint_url);
|
|
328
375
|
let headers = creds.auth_headers();
|
|
329
376
|
let (status, body) = do_request_light("GET", &url, &headers, None, use_h2)
|
|
330
377
|
.await
|
|
@@ -332,7 +379,7 @@ async fn do_art_list_repos(creds: &ArtCreds, use_h2: bool) -> Result<Vec<String>
|
|
|
332
379
|
if !status.is_success() {
|
|
333
380
|
return Err(status_to_pyerr(
|
|
334
381
|
status,
|
|
335
|
-
|
|
382
|
+
creds.path_url("").trim_end_matches('/'),
|
|
336
383
|
&body,
|
|
337
384
|
));
|
|
338
385
|
}
|
|
@@ -21,9 +21,9 @@ use quick_xml::Reader;
|
|
|
21
21
|
use quick_xml::events::Event;
|
|
22
22
|
use serde::{Deserialize, Serialize};
|
|
23
23
|
use sha2::Sha256;
|
|
24
|
-
use std::collections::HashSet;
|
|
25
24
|
|
|
26
25
|
use crate::http::{do_request, do_request_light, status_to_pyerr};
|
|
26
|
+
use crate::listing::{ListEntry, Listing};
|
|
27
27
|
use crate::xml::local_name;
|
|
28
28
|
|
|
29
29
|
type HmacSha256 = Hmac<Sha256>;
|
|
@@ -428,16 +428,9 @@ async fn do_az_is_dir(creds: &AzCreds, prefix: &str, use_h2: bool) -> Result<boo
|
|
|
428
428
|
Ok(false)
|
|
429
429
|
}
|
|
430
430
|
|
|
431
|
-
async fn do_az_list(creds: &AzCreds, prefix: &str, use_h2: bool) -> Result<Vec<
|
|
432
|
-
let
|
|
433
|
-
let search_prefix =
|
|
434
|
-
String::new()
|
|
435
|
-
} else {
|
|
436
|
-
format!("{}/", current_key)
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
let mut found_all = HashSet::new();
|
|
440
|
-
let mut uris = Vec::new();
|
|
431
|
+
async fn do_az_list(creds: &AzCreds, prefix: &str, use_h2: bool) -> Result<Vec<ListEntry>, PyErr> {
|
|
432
|
+
let mut listing = Listing::new(format!("az://{}", creds.container), prefix);
|
|
433
|
+
let search_prefix = listing.search_prefix().to_string();
|
|
441
434
|
let mut marker: Option<String> = None;
|
|
442
435
|
|
|
443
436
|
loop {
|
|
@@ -464,100 +457,68 @@ async fn do_az_list(creds: &AzCreds, prefix: &str, use_h2: bool) -> Result<Vec<S
|
|
|
464
457
|
&body,
|
|
465
458
|
));
|
|
466
459
|
}
|
|
460
|
+
marker = parse_az_listing_page(&body, &mut listing);
|
|
461
|
+
if marker.is_none() {
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
467
465
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
reader.config_mut().trim_text(true);
|
|
471
|
-
let mut buf = Vec::new();
|
|
472
|
-
let mut next_marker: Option<String> = None;
|
|
473
|
-
let mut in_blob_prefix = false;
|
|
466
|
+
Ok(listing.finish())
|
|
467
|
+
}
|
|
474
468
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
} else {
|
|
499
|
-
// Regular blob
|
|
500
|
-
let name = &text;
|
|
501
|
-
if name.is_empty() || name.trim_end_matches('/') == current_key {
|
|
502
|
-
// skip
|
|
503
|
-
} else {
|
|
504
|
-
let relative = if !search_prefix.is_empty()
|
|
505
|
-
&& name.starts_with(&search_prefix)
|
|
506
|
-
{
|
|
507
|
-
&name[search_prefix.len()..]
|
|
508
|
-
} else {
|
|
509
|
-
name.as_str()
|
|
510
|
-
};
|
|
511
|
-
let relative = relative.trim_start_matches('/');
|
|
512
|
-
let resolved = if !relative.is_empty() {
|
|
513
|
-
let first = relative.split('/').next().unwrap_or(relative);
|
|
514
|
-
format!("{}{}", search_prefix, first)
|
|
515
|
-
} else {
|
|
516
|
-
name.to_string()
|
|
517
|
-
};
|
|
518
|
-
let value = resolved.trim_end_matches('/').to_string();
|
|
519
|
-
if !value.is_empty()
|
|
520
|
-
&& value != current_key
|
|
521
|
-
&& found_all.insert(value.clone())
|
|
522
|
-
{
|
|
523
|
-
uris.push(format!("az://{}/{}", creds.container, value));
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
"NextMarker" => {
|
|
529
|
-
let text = reader
|
|
530
|
-
.read_text(e.name())
|
|
531
|
-
.ok()
|
|
532
|
-
.map(|text| text.xml10_content().into_owned())
|
|
533
|
-
.unwrap_or_default();
|
|
534
|
-
if !text.is_empty() {
|
|
535
|
-
next_marker = Some(text);
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
_ => {}
|
|
469
|
+
fn parse_az_listing_page(body: &[u8], listing: &mut Listing) -> Option<String> {
|
|
470
|
+
let mut reader = Reader::from_reader(body);
|
|
471
|
+
reader.config_mut().trim_text(true);
|
|
472
|
+
let mut buf = Vec::new();
|
|
473
|
+
let mut text = String::new();
|
|
474
|
+
let mut in_blob = false;
|
|
475
|
+
let mut in_prefix = false;
|
|
476
|
+
let mut name = String::new();
|
|
477
|
+
let mut size = None;
|
|
478
|
+
let mut modified = None;
|
|
479
|
+
let mut next_marker = None;
|
|
480
|
+
|
|
481
|
+
loop {
|
|
482
|
+
match reader.read_event_into(&mut buf) {
|
|
483
|
+
Ok(Event::Start(e)) => {
|
|
484
|
+
let tag = e.name();
|
|
485
|
+
match local_name(tag.as_ref()) {
|
|
486
|
+
"Blob" => {
|
|
487
|
+
in_blob = true;
|
|
488
|
+
name.clear();
|
|
489
|
+
size = None;
|
|
490
|
+
modified = None;
|
|
539
491
|
}
|
|
492
|
+
"BlobPrefix" => in_prefix = true,
|
|
493
|
+
_ => {}
|
|
540
494
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
495
|
+
text.clear();
|
|
496
|
+
}
|
|
497
|
+
Ok(Event::Text(e)) => text.push_str(&e.xml10_content()),
|
|
498
|
+
Ok(Event::End(e)) => {
|
|
499
|
+
let tag = e.name();
|
|
500
|
+
match local_name(tag.as_ref()) {
|
|
501
|
+
"Name" if in_prefix => listing.add_prefix(&text),
|
|
502
|
+
"Name" if in_blob => name = std::mem::take(&mut text),
|
|
503
|
+
"Content-Length" if in_blob => size = text.parse().ok(),
|
|
504
|
+
"Last-Modified" if in_blob => modified = Some(std::mem::take(&mut text)),
|
|
505
|
+
"Blob" => {
|
|
506
|
+
in_blob = false;
|
|
507
|
+
listing.add_object(&name, size, modified.take());
|
|
545
508
|
}
|
|
509
|
+
"BlobPrefix" => in_prefix = false,
|
|
510
|
+
"NextMarker" if !text.is_empty() => {
|
|
511
|
+
next_marker = Some(std::mem::take(&mut text));
|
|
512
|
+
}
|
|
513
|
+
_ => {}
|
|
546
514
|
}
|
|
547
|
-
Ok(Event::Eof) => break,
|
|
548
|
-
Err(_) => break,
|
|
549
|
-
_ => {}
|
|
550
515
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
marker = next_marker;
|
|
555
|
-
if marker.is_none() {
|
|
556
|
-
break;
|
|
516
|
+
Ok(Event::Eof) | Err(_) => break,
|
|
517
|
+
_ => {}
|
|
557
518
|
}
|
|
519
|
+
buf.clear();
|
|
558
520
|
}
|
|
559
|
-
|
|
560
|
-
Ok(uris)
|
|
521
|
+
next_marker
|
|
561
522
|
}
|
|
562
523
|
|
|
563
524
|
/// List all containers in the account (GET /?comp=list). Returns bare names.
|
|
@@ -1096,41 +1057,16 @@ pub fn az_exists_batch<'py>(
|
|
|
1096
1057
|
})
|
|
1097
1058
|
}
|
|
1098
1059
|
|
|
1099
|
-
#[pyfunction]
|
|
1100
|
-
pub fn az_is_dir_batch<'py>(
|
|
1101
|
-
py: Python<'py>,
|
|
1102
|
-
endpoint: String,
|
|
1103
|
-
container: String,
|
|
1104
|
-
prefixes: Vec<String>,
|
|
1105
|
-
account_name: String,
|
|
1106
|
-
account_key: Option<String>,
|
|
1107
|
-
sas_token: Option<String>,
|
|
1108
|
-
use_h2: Option<bool>,
|
|
1109
|
-
) -> PyResult<Bound<'py, PyAny>> {
|
|
1110
|
-
let h2 = use_h2.unwrap_or(false);
|
|
1111
|
-
pyo3_async_runtimes::tokio::future_into_py(py, async move {
|
|
1112
|
-
let creds = az_creds!(endpoint, container, account_name, account_key, sas_token);
|
|
1113
|
-
let futs: Vec<_> = prefixes
|
|
1114
|
-
.iter()
|
|
1115
|
-
.map(|p| do_az_is_dir(&creds, p, h2))
|
|
1116
|
-
.collect();
|
|
1117
|
-
let results = join_all(futs).await;
|
|
1118
|
-
let mut out = Vec::with_capacity(results.len());
|
|
1119
|
-
for r in results {
|
|
1120
|
-
out.push(r?);
|
|
1121
|
-
}
|
|
1122
|
-
Ok(out)
|
|
1123
|
-
})
|
|
1124
|
-
}
|
|
1125
|
-
|
|
1126
1060
|
// ---------------------------------------------------------------------------
|
|
1127
1061
|
// Presigned URL generation (Service SAS)
|
|
1128
1062
|
// ---------------------------------------------------------------------------
|
|
1129
1063
|
|
|
1130
1064
|
/// Generate a presigned URL for an Azure blob using a Service SAS token.
|
|
1131
1065
|
///
|
|
1132
|
-
///
|
|
1133
|
-
///
|
|
1066
|
+
/// The SAS is signed with `account_key`, scoped to this blob, `method` and
|
|
1067
|
+
/// `expires`. A configured `sas_token` is a credential that may grant far
|
|
1068
|
+
/// more (other blobs, write access, a longer lifetime), so it is never handed
|
|
1069
|
+
/// out as a presigned URL.
|
|
1134
1070
|
#[pyfunction]
|
|
1135
1071
|
pub fn az_presign(
|
|
1136
1072
|
endpoint: String,
|
|
@@ -1151,21 +1087,18 @@ pub fn az_presign(
|
|
|
1151
1087
|
format!("{}/{}/{}", base, container, blob_path)
|
|
1152
1088
|
};
|
|
1153
1089
|
|
|
1154
|
-
// If SAS token already exists, just append it
|
|
1155
|
-
if let Some(ref sas) = sas_token {
|
|
1156
|
-
if !sas.is_empty() {
|
|
1157
|
-
let sep = if blob_url.contains('?') { "&" } else { "?" };
|
|
1158
|
-
return Ok(format!("{}{}{}", blob_url, sep, sas));
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
1090
|
let key_str = account_key
|
|
1163
1091
|
.as_ref()
|
|
1164
1092
|
.filter(|k| !k.is_empty())
|
|
1165
1093
|
.ok_or_else(|| {
|
|
1166
|
-
|
|
1167
|
-
"
|
|
1168
|
-
|
|
1094
|
+
let hint = if sas_token.as_deref().is_some_and(|s| !s.is_empty()) {
|
|
1095
|
+
"; the configured SAS token is a credential and is not shared"
|
|
1096
|
+
} else {
|
|
1097
|
+
""
|
|
1098
|
+
};
|
|
1099
|
+
pyo3::exceptions::PyValueError::new_err(format!(
|
|
1100
|
+
"presign requires account_key to sign a blob-scoped SAS{hint}"
|
|
1101
|
+
))
|
|
1169
1102
|
})?;
|
|
1170
1103
|
|
|
1171
1104
|
let key_bytes = B64
|
|
@@ -1227,3 +1160,34 @@ fn format_iso8601(secs: u64) -> String {
|
|
|
1227
1160
|
year, month, day, hours, minutes, seconds
|
|
1228
1161
|
)
|
|
1229
1162
|
}
|
|
1163
|
+
|
|
1164
|
+
#[cfg(test)]
|
|
1165
|
+
mod tests {
|
|
1166
|
+
use super::{Listing, parse_az_listing_page};
|
|
1167
|
+
|
|
1168
|
+
#[test]
|
|
1169
|
+
fn parses_listing_page_metadata() {
|
|
1170
|
+
let body = br#"<?xml version="1.0" encoding="utf-8"?>
|
|
1171
|
+
<EnumerationResults ContainerName="c"><Prefix>dir/</Prefix><Blobs>
|
|
1172
|
+
<Blob><Name>dir/a.txt</Name><Properties>
|
|
1173
|
+
<Last-Modified>Tue, 02 Jan 2024 03:04:05 GMT</Last-Modified>
|
|
1174
|
+
<Content-Length>42</Content-Length>
|
|
1175
|
+
</Properties></Blob>
|
|
1176
|
+
<BlobPrefix><Name>dir/sub/</Name></BlobPrefix>
|
|
1177
|
+
</Blobs><NextMarker /></EnumerationResults>"#;
|
|
1178
|
+
let mut listing = Listing::new("az://c".into(), "dir");
|
|
1179
|
+
assert_eq!(parse_az_listing_page(body, &mut listing), None);
|
|
1180
|
+
assert_eq!(
|
|
1181
|
+
listing.finish(),
|
|
1182
|
+
vec![
|
|
1183
|
+
(
|
|
1184
|
+
"az://c/dir/a.txt".into(),
|
|
1185
|
+
false,
|
|
1186
|
+
Some(42),
|
|
1187
|
+
Some("Tue, 02 Jan 2024 03:04:05 GMT".into())
|
|
1188
|
+
),
|
|
1189
|
+
("az://c/dir/sub".into(), true, None, None),
|
|
1190
|
+
]
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
}
|