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 mod lineage;
9pub(crate) mod log;
10pub mod manifest;
11pub mod profile;
12pub mod report;
13pub mod run;
14pub mod runner;
15pub mod runtime;
16pub mod state;
17pub mod vars;
18pub mod warnings;
19
20pub use crate::state::{inspect_entity_state_with_base, reset_entity_state_with_base};
21pub use add_entity::{add_entity_to_config, AddEntityOptions, AddEntityOutcome};
22pub use checks as check;
23pub use config::{resolve_config_location, ConfigLocation};
24pub use errors::ConfigError;
25pub use manifest::build_common_manifest_json;
26pub use profile::{
27    detect_malformed_placeholder, detect_unresolved_placeholders, parse_profile,
28    parse_profile_from_str, validate_merged_vars, validate_profile, ProfileConfig,
29};
30pub use run::events::{set_observer, MultiObserver, RunEvent, RunObserver};
31pub use run::{run, run_with_base, DryRunEntityPreview, EntityOutcome, RunOutcome};
32pub use runner::{parse_run_status_from_logs, ConnectorRunStatus};
33pub use runtime::{DefaultRuntime, Runtime};
34pub use vars::{resolve_vars, VarSources};
35
36pub type FloeResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync>>;
37
38#[derive(Debug, Default)]
39pub struct ValidateOptions {
40    pub entities: Vec<String>,
41    pub profile_vars: std::collections::HashMap<String, String>,
42    pub profile_catalogs: Option<config::CatalogsConfig>,
43}
44
45#[derive(Debug, Default)]
46pub struct RunOptions {
47    pub run_id: Option<String>,
48    pub entities: Vec<String>,
49    pub dry_run: bool,
50    pub profile: Option<ProfileConfig>,
51}
52
53pub fn validate(config_path: &Path, options: ValidateOptions) -> FloeResult<()> {
54    let config_base = config::ConfigBase::local_from_path(config_path);
55    validate_with_base(config_path, config_base, options)
56}
57
58pub fn validate_with_base(
59    config_path: &Path,
60    _config_base: config::ConfigBase,
61    options: ValidateOptions,
62) -> FloeResult<()> {
63    let mut config = config::parse_config_with_vars(config_path, &options.profile_vars)?;
64    apply_profile_catalogs(&mut config, options.profile_catalogs.as_ref());
65    config::validate_config(&config)?;
66
67    if !options.entities.is_empty() {
68        run::validate_entities(&config, &options.entities)?;
69    }
70
71    Ok(())
72}
73
74pub fn load_config(config_path: &Path) -> FloeResult<config::RootConfig> {
75    config::parse_config(config_path)
76}
77
78pub fn load_config_with_profile_vars(
79    config_path: &Path,
80    profile_vars: &std::collections::HashMap<String, String>,
81) -> FloeResult<config::RootConfig> {
82    config::parse_config_with_vars(config_path, profile_vars)
83}
84
85pub fn load_config_with_profile_overrides(
86    config_path: &Path,
87    profile_vars: &std::collections::HashMap<String, String>,
88    profile_catalogs: Option<&config::CatalogsConfig>,
89) -> FloeResult<config::RootConfig> {
90    let mut config = config::parse_config_with_vars(config_path, profile_vars)?;
91    apply_profile_catalogs(&mut config, profile_catalogs);
92    Ok(config)
93}
94
95pub fn validate_profile_file(profile_path: &Path) -> FloeResult<ProfileConfig> {
96    let profile = parse_profile(profile_path)?;
97    validate_profile(&profile)?;
98    Ok(profile)
99}
100
101pub(crate) fn apply_profile_catalogs(
102    config: &mut config::RootConfig,
103    profile_catalogs: Option<&config::CatalogsConfig>,
104) {
105    if let Some(catalogs) = profile_catalogs {
106        config.catalogs = Some(catalogs.clone());
107    }
108}
109
110pub fn extract_config_env_vars(
111    config_path: &Path,
112) -> FloeResult<std::collections::HashMap<String, String>> {
113    Ok(config::extract_raw_env_vars(config_path).unwrap_or_default())
114}
115
116pub fn validate_config_for_tests(config: &config::RootConfig) -> FloeResult<()> {
117    config::validate_config(config)
118}