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    pub profile_storages: Option<config::StoragesConfig>,
44    pub profile_lineage: Option<config::LineageConfig>,
45}
46
47#[derive(Debug, Default)]
48pub struct RunOptions {
49    pub run_id: Option<String>,
50    pub entities: Vec<String>,
51    pub dry_run: bool,
52    pub profile: Option<ProfileConfig>,
53}
54
55pub fn validate(config_path: &Path, options: ValidateOptions) -> FloeResult<()> {
56    let config_base = config::ConfigBase::local_from_path(config_path);
57    validate_with_base(config_path, config_base, options)
58}
59
60pub fn validate_with_base(
61    config_path: &Path,
62    _config_base: config::ConfigBase,
63    options: ValidateOptions,
64) -> FloeResult<()> {
65    let mut config = config::parse_config_with_vars(config_path, &options.profile_vars)?;
66    apply_profile_catalogs(&mut config, options.profile_catalogs.as_ref());
67    apply_profile_storages(&mut config, options.profile_storages.as_ref());
68    apply_profile_lineage(&mut config, options.profile_lineage.as_ref());
69    config::validate_config(&config)?;
70
71    if !options.entities.is_empty() {
72        run::validate_entities(&config, &options.entities)?;
73    }
74
75    Ok(())
76}
77
78pub fn load_config(config_path: &Path) -> FloeResult<config::RootConfig> {
79    config::parse_config(config_path)
80}
81
82pub fn load_config_with_profile_vars(
83    config_path: &Path,
84    profile_vars: &std::collections::HashMap<String, String>,
85) -> FloeResult<config::RootConfig> {
86    config::parse_config_with_vars(config_path, profile_vars)
87}
88
89pub fn load_config_with_profile_overrides(
90    config_path: &Path,
91    profile_vars: &std::collections::HashMap<String, String>,
92    profile_catalogs: Option<&config::CatalogsConfig>,
93    profile_storages: Option<&config::StoragesConfig>,
94    profile_lineage: Option<&config::LineageConfig>,
95) -> FloeResult<config::RootConfig> {
96    let mut config = config::parse_config_with_vars(config_path, profile_vars)?;
97    apply_profile_catalogs(&mut config, profile_catalogs);
98    apply_profile_storages(&mut config, profile_storages);
99    apply_profile_lineage(&mut config, profile_lineage);
100    Ok(config)
101}
102
103pub fn validate_profile_file(profile_path: &Path) -> FloeResult<ProfileConfig> {
104    let profile = parse_profile(profile_path)?;
105    validate_profile(&profile)?;
106    Ok(profile)
107}
108
109pub(crate) fn apply_profile_catalogs(
110    config: &mut config::RootConfig,
111    profile_catalogs: Option<&config::CatalogsConfig>,
112) {
113    if let Some(catalogs) = profile_catalogs {
114        config.catalogs = Some(catalogs.clone());
115    }
116}
117
118pub(crate) fn apply_profile_storages(
119    config: &mut config::RootConfig,
120    profile_storages: Option<&config::StoragesConfig>,
121) {
122    if let Some(storages) = profile_storages {
123        config.storages = Some(storages.clone());
124    }
125}
126
127pub(crate) fn apply_profile_lineage(
128    config: &mut config::RootConfig,
129    profile_lineage: Option<&config::LineageConfig>,
130) {
131    if let Some(lineage) = profile_lineage {
132        config.lineage = Some(lineage.clone());
133    }
134}
135
136pub fn extract_config_env_vars(
137    config_path: &Path,
138) -> FloeResult<std::collections::HashMap<String, String>> {
139    Ok(config::extract_raw_env_vars(config_path).unwrap_or_default())
140}
141
142pub fn validate_config_for_tests(config: &config::RootConfig) -> FloeResult<()> {
143    config::validate_config(config)
144}