• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

getdozer / dozer / 5853938297

pending completion
5853938297

push

github

web-flow
fix: Support uploading empty multipart file to s3 (#1846)

* fix: Support uploading empty multipart file to s3

* chore: Use `NonZeroU16` as `part_number` to better conform to s3 requirement

57 of 57 new or added lines in 4 files covered. (100.0%)

45637 of 62725 relevant lines covered (72.76%)

52011.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

23.08
/dozer-cli/src/cli/helper.rs
1
use crate::config_helper::combine_config;
2
use crate::errors::CliError;
3
use crate::errors::CliError::{ConfigurationFilePathNotProvided, FailedToFindConfigurationFiles};
4
use crate::errors::ConfigCombineError::CannotReadConfig;
5
use crate::errors::OrchestrationError;
6
use crate::simple::SimpleOrchestrator as Dozer;
7
use atty::Stream;
8
use dozer_types::models::config::default_cache_max_map_size;
9
use dozer_types::prettytable::{row, Table};
10
use dozer_types::{models::config::Config, serde_yaml};
11
use handlebars::Handlebars;
12
use std::collections::BTreeMap;
13
use std::io::{self, Read};
14
use std::path::PathBuf;
15
use std::sync::Arc;
×
16
use tokio::runtime::Runtime;
×
17

×
18
pub fn init_dozer(
×
19
    config_paths: Vec<String>,
×
20
    config_token: Option<String>,
×
21
    config_overrides: Vec<(String, serde_json::Value)>,
×
22
    ignore_pipe: bool,
×
23
) -> Result<Dozer, CliError> {
×
24
    let runtime = Runtime::new().map_err(CliError::FailedToCreateTokioRuntime)?;
×
25
    let mut config = runtime.block_on(load_config(config_paths, config_token, ignore_pipe))?;
×
26

×
27
    config = apply_overrides(&config, config_overrides)?;
×
28

×
29
    let cache_max_map_size = config
×
30
        .cache_max_map_size
×
31
        .unwrap_or_else(default_cache_max_map_size);
×
32
    let page_size = page_size::get() as u64;
×
33
    config.cache_max_map_size = Some(cache_max_map_size / page_size * page_size);
×
34

×
35
    Ok(Dozer::new(config, Arc::new(runtime)))
×
36
}
×
37

×
38
pub fn list_sources(
×
39
    config_paths: Vec<String>,
×
40
    config_token: Option<String>,
×
41
    config_overrides: Vec<(String, serde_json::Value)>,
×
42
    ignore_pipe: bool,
×
43
    filter: Option<String>,
×
44
) -> Result<(), OrchestrationError> {
×
45
    let dozer = init_dozer(config_paths, config_token, config_overrides, ignore_pipe)?;
×
46
    let connection_map = dozer.list_connectors()?;
×
47
    let mut table_parent = Table::new();
×
48
    for (connection_name, (tables, schemas)) in connection_map {
×
49
        let mut first_table_found = false;
×
50

×
51
        for (table, schema) in tables.into_iter().zip(schemas) {
×
52
            let name = table.schema.map_or(table.name.clone(), |schema_name| {
×
53
                format!("{schema_name}.{}", table.name)
×
54
            });
×
55

×
56
            if filter
×
57
                .as_ref()
×
58
                .map_or(true, |name_part| name.contains(name_part))
×
59
            {
×
60
                if !first_table_found {
×
61
                    table_parent.add_row(row!["Connection", "Table", "Columns"]);
×
62
                    first_table_found = true;
×
63
                }
×
64
                let schema_table = schema.schema.print();
×
65

×
66
                table_parent.add_row(row![connection_name, name, schema_table]);
×
67
            }
×
68
        }
69

×
70
        if first_table_found {
×
71
            table_parent.add_empty_row();
×
72
        }
×
73
    }
×
74
    table_parent.printstd();
×
75
    Ok(())
×
76
}
×
77

×
78
async fn load_config(
×
79
    config_url_or_paths: Vec<String>,
×
80
    config_token: Option<String>,
×
81
    ignore_pipe: bool,
×
82
) -> Result<Config, CliError> {
×
83
    let read_stdin = atty::isnt(Stream::Stdin) && !ignore_pipe;
×
84
    let first_config_path = config_url_or_paths.get(0);
×
85
    match first_config_path {
×
86
        None => Err(ConfigurationFilePathNotProvided),
×
87
        Some(path) => {
×
88
            if path.starts_with("https://") || path.starts_with("http://") {
×
89
                load_config_from_http_url(path, config_token).await
×
90
            } else {
×
91
                load_config_from_file(config_url_or_paths, read_stdin)
×
92
            }
×
93
        }
×
94
    }
×
95
}
×
96

×
97
async fn load_config_from_http_url(
×
98
    config_url: &str,
×
99
    config_token: Option<String>,
×
100
) -> Result<Config, CliError> {
×
101
    let client = reqwest::Client::new();
×
102
    let mut get_request = client.get(config_url);
×
103
    if let Some(token) = config_token {
×
104
        get_request = get_request.bearer_auth(token);
×
105
    }
×
106
    let response: reqwest::Response = get_request.send().await?.error_for_status()?;
×
107
    let contents = response.text().await?;
×
108
    parse_config(&contents)
×
109
}
×
110

×
111
pub fn load_config_from_file(
×
112
    config_path: Vec<String>,
×
113
    read_stdin: bool,
×
114
) -> Result<Config, CliError> {
×
115
    let stdin_path = PathBuf::from("<stdin>");
×
116
    let input = if read_stdin {
×
117
        let mut input = String::new();
×
118
        io::stdin()
×
119
            .read_to_string(&mut input)
×
120
            .map_err(|e| CannotReadConfig(stdin_path, e))?;
×
121
        Some(input)
×
122
    } else {
×
123
        None
×
124
    };
×
125

×
126
    let config_template = combine_config(config_path.clone(), input)?;
×
127
    match config_template {
×
128
        Some(template) => parse_config(&template),
×
129
        None => Err(FailedToFindConfigurationFiles(config_path.join(", "))),
×
130
    }
×
131
}
×
132

×
133
fn parse_config(config_template: &str) -> Result<Config, CliError> {
×
134
    let mut handlebars = Handlebars::new();
×
135
    handlebars
×
136
        .register_template_string("config", config_template)
×
137
        .map_err(|e| CliError::FailedToParseYaml(Box::new(e)))?;
×
138

×
139
    let mut data = BTreeMap::new();
×
140

×
141
    for (key, value) in std::env::vars() {
×
142
        data.insert(key, value);
×
143
    }
×
144

×
145
    let config_str = handlebars
×
146
        .render("config", &data)
×
147
        .map_err(|e| CliError::FailedToParseYaml(Box::new(e)))?;
×
148

149
    let config: Config = serde_yaml::from_str(&config_str)
×
150
        .map_err(|e: serde_yaml::Error| CliError::FailedToParseYaml(Box::new(e)))?;
×
151

×
152
    Ok(config)
×
153
}
×
154

×
155
/// Convert `config` to JSON, apply JSON pointer overrides, then convert back to `Config`.
×
156
fn apply_overrides(
2✔
157
    config: &Config,
2✔
158
    config_overrides: Vec<(String, serde_json::Value)>,
2✔
159
) -> Result<Config, CliError> {
2✔
160
    let mut config_json = serde_json::to_value(config).map_err(CliError::SerializeConfigToJson)?;
2✔
161

×
162
    for (pointer, value) in config_overrides {
4✔
163
        if let Some(pointee) = config_json.pointer_mut(&pointer) {
2✔
164
            *pointee = value;
2✔
165
        } else {
2✔
166
            return Err(CliError::MissingConfigOverride(pointer));
×
167
        }
×
168
    }
×
169

×
170
    // Directly convert `config_json` to `Config` fails, not sure why.
×
171
    let config_json_string =
2✔
172
        serde_json::to_string(&config_json).map_err(CliError::SerializeConfigToJson)?;
2✔
173
    let config: Config =
2✔
174
        serde_json::from_str(&config_json_string).map_err(CliError::DeserializeConfigFromJson)?;
2✔
175

×
176
    Ok(config)
2✔
177
}
2✔
178

×
179
pub const LOGO: &str = r"
×
180
.____   ___ __________ ____
×
181
|  _ \ / _ \__  / ____|  _ \
×
182
| | | | | | |/ /|  _| | |_) |
×
183
| |_| | |_| / /_| |___|  _ <
×
184
|____/ \___/____|_____|_| \_\
×
185
";
×
186

×
187
pub const DESCRIPTION: &str = r#"Open-source platform to build, publish and manage blazing-fast real-time data APIs in minutes. 
×
188

×
189
 If no sub commands are passed, dozer will bring up both app and api services.
×
190
"#;
×
191

×
192
#[cfg(test)]
193
mod tests {
×
194
    use dozer_types::models::{api_config::ApiConfig, api_security::ApiSecurity};
×
195

×
196
    use super::*;
×
197

×
198
    #[test]
1✔
199
    fn test_override_top_level() {
1✔
200
        let mut config = Config {
1✔
201
            app_name: "test_override_top_level".to_string(),
1✔
202
            ..Default::default()
1✔
203
        };
1✔
204
        config.sql = Some("sql1".to_string());
1✔
205
        let sql = "sql2".to_string();
1✔
206
        let config = apply_overrides(
1✔
207
            &config,
1✔
208
            vec![("/sql".to_string(), serde_json::to_value(&sql).unwrap())],
1✔
209
        )
1✔
210
        .unwrap();
1✔
211
        assert_eq!(config.sql.unwrap(), sql);
1✔
212
    }
1✔
213

×
214
    #[test]
1✔
215
    fn test_override_nested() {
1✔
216
        let mut config = Config {
1✔
217
            app_name: "test_override_nested".to_string(),
1✔
218
            ..Default::default()
1✔
219
        };
1✔
220
        config.api = Some(ApiConfig {
1✔
221
            api_security: Some(ApiSecurity::Jwt("secret1".to_string())),
1✔
222
            ..Default::default()
1✔
223
        });
1✔
224
        let api_security = ApiSecurity::Jwt("secret2".to_string());
1✔
225
        let config = apply_overrides(
1✔
226
            &config,
1✔
227
            vec![(
1✔
228
                "/api/api_security".to_string(),
1✔
229
                serde_json::to_value(&api_security).unwrap(),
1✔
230
            )],
1✔
231
        )
1✔
232
        .unwrap();
1✔
233
        assert_eq!(config.api.unwrap().api_security.unwrap(), api_security);
1✔
234
    }
1✔
235
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc