Skip to main content

floe_core/
lib.rs

1use std::path::Path;
2
3mod add_entity;
4pub mod checks;
5pub mod config;
6pub mod errors;
7pub mod io;
8pub(crate) mod log;
9pub mod manifest;
10pub mod profile;
11pub mod report;
12pub mod run;
13pub mod runner;
14pub mod runtime;
15pub mod state;
16pub mod vars;
17pub mod warnings;
18
19pub use crate::state::{inspect_entity_state_with_base, reset_entity_state_with_base};
20pub use add_entity::{add_entity_to_config, AddEntityOptions, AddEntityOutcome};
21pub use checks as check;
22pub use config::{resolve_config_location, ConfigLocation};
23pub use errors::ConfigError;
24pub use manifest::build_common_manifest_json;
25pub use profile::{
26    detect_malformed_placeholder, detect_unresolved_placeholders, parse_profile,
27    parse_profile_from_str, validate_merged_vars, validate_profile, ProfileConfig,
28};
29pub use run::events::{set_observer, RunEvent, RunObserver};
30pub use run::{run, run_with_base, DryRunEntityPreview, EntityOutcome, RunOutcome};
31pub use runner::{parse_run_status_from_logs, ConnectorRunStatus};
32pub use runtime::{DefaultRuntime, Runtime};
33pub use vars::{resolve_vars, VarSources};
34
35pub type FloeResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync>>;
36
37#[derive(Debug, Default)]
38pub struct ValidateOptions {
39    pub entities: Vec<String>,
40    pub profile_vars: std::collections::HashMap<String, String>,
41}
42
43#[derive(Debug, Default)]
44pub struct RunOptions {
45    pub run_id: Option<String>,
46    pub entities: Vec<String>,
47    pub dry_run: bool,
48    pub profile: Option<ProfileConfig>,
49}
50
51pub fn validate(config_path: &Path, options: ValidateOptions) -> FloeResult<()> {
52    let config_base = config::ConfigBase::local_from_path(config_path);
53    validate_with_base(config_path, config_base, options)
54}
55
56pub fn validate_with_base(
57    config_path: &Path,
58    _config_base: config::ConfigBase,
59    options: ValidateOptions,
60) -> FloeResult<()> {
61    let config = config::parse_config_with_vars(config_path, &options.profile_vars)?;
62    config::validate_config(&config)?;
63
64    if !options.entities.is_empty() {
65        run::validate_entities(&config, &options.entities)?;
66    }
67
68    Ok(())
69}
70
71pub fn load_config(config_path: &Path) -> FloeResult<config::RootConfig> {
72    config::parse_config(config_path)
73}
74
75pub fn validate_config_for_tests(config: &config::RootConfig) -> FloeResult<()> {
76    config::validate_config(config)
77}