1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Configuration for the Transfer Family Connector TUI CLI.
use std::path::PathBuf;
/// Runtime configuration derived from CLI args and env.
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct Config {
/// AWS Transfer Family connector ID (e.g. `c-01234567890abcdef`).
pub connector_id: String,
/// S3 location for transfer CLI data: bucket and optional prefix, format `bucket/prefix`.
/// Listings, retrieve, and send use subpaths under this root.
pub s3_root: String,
/// AWS region (e.g. `us-east-1`).
pub region: Option<String>,
/// AWS profile name for credentials.
pub profile: Option<String>,
/// Local directory for downloads (get). Default: current directory.
pub download_dir: PathBuf,
}
impl Config {
/// Builds config from individual fields (for use with `#[non_exhaustive]`).
#[allow(clippy::missing_const_for_fn)] // String/PathBuf not const
#[must_use]
pub fn new(
connector_id: String,
s3_root: String,
region: Option<String>,
profile: Option<String>,
download_dir: PathBuf,
) -> Self {
Self {
connector_id,
s3_root,
region,
profile,
download_dir,
}
}
fn s3_base(&self) -> String {
self.s3_root.trim_end_matches('/').to_string()
}
/// S3 path for directory listing results: `bucket/prefix/listings/`.
#[must_use]
pub fn listings_prefix(&self) -> String {
format!("{}/listings/", self.s3_base())
}
/// S3 path for retrieve (get): `bucket/prefix/retrieve/`.
#[must_use]
pub fn retrieve_prefix(&self) -> String {
format!("{}/retrieve/", self.s3_base())
}
/// S3 path for send (put): `bucket/prefix/send/`.
#[must_use]
pub fn send_prefix(&self) -> String {
format!("{}/send/", self.s3_base())
}
}