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::{
21    inspect_entity_state, inspect_entity_state_with_base, reset_entity_state,
22    reset_entity_state_with_base,
23};
24pub use add_entity::{add_entity_to_config, AddEntityOptions, AddEntityOutcome};
25pub use checks as check;
26pub use config::{resolve_config_location, ConfigLocation};
27pub use errors::ConfigError;
28pub use manifest::{build_common_manifest_json, config_from_manifest_json};
29pub use profile::{
30    detect_malformed_placeholder, detect_unresolved_placeholders, parse_profile,
31    parse_profile_from_str, validate_merged_vars, validate_profile, ProfileConfig,
32};
33pub use run::events::{set_observer, MultiObserver, RunEvent, RunObserver};
34pub use run::{
35    run, run_with_base, run_with_manifest_path, DryRunEntityPreview, EntityOutcome, RunOutcome,
36};
37pub use runner::{parse_run_status_from_logs, ConnectorRunStatus};
38pub use runtime::{DefaultRuntime, Runtime};
39pub use vars::{resolve_vars, VarSources};
40
41pub type FloeResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync>>;
42
43#[derive(Debug, Default)]
44pub struct ValidateOptions {
45    pub entities: Vec<String>,
46    pub profile_vars: std::collections::HashMap<String, String>,
47    pub profile_catalogs: Option<config::CatalogsConfig>,
48    pub profile_storages: Option<config::StoragesConfig>,
49    pub profile_lineage: Option<config::LineageConfig>,
50}
51
52#[derive(Debug, Default)]
53pub struct RunOptions {
54    pub run_id: Option<String>,
55    pub entities: Vec<String>,
56    pub dry_run: bool,
57    pub profile: Option<ProfileConfig>,
58}
59
60pub fn validate(config_path: &Path, options: ValidateOptions) -> FloeResult<()> {
61    let config_base = config::ConfigBase::local_from_path(config_path);
62    validate_with_base(config_path, config_base, options)
63}
64
65pub fn validate_with_base(
66    config_path: &Path,
67    _config_base: config::ConfigBase,
68    options: ValidateOptions,
69) -> FloeResult<()> {
70    let mut config = config::parse_config_with_vars(config_path, &options.profile_vars)?;
71    apply_profile_catalogs(&mut config, options.profile_catalogs.as_ref());
72    apply_profile_storages(&mut config, options.profile_storages.as_ref());
73    apply_profile_lineage(&mut config, options.profile_lineage.as_ref());
74    config::validate_config(&config)?;
75
76    if !options.entities.is_empty() {
77        run::validate_entities(&config, &options.entities)?;
78    }
79
80    Ok(())
81}
82
83pub fn load_config(config_path: &Path) -> FloeResult<config::RootConfig> {
84    config::parse_config(config_path)
85}
86
87pub fn load_config_with_profile_vars(
88    config_path: &Path,
89    profile_vars: &std::collections::HashMap<String, String>,
90) -> FloeResult<config::RootConfig> {
91    config::parse_config_with_vars(config_path, profile_vars)
92}
93
94pub fn load_config_with_profile_overrides(
95    config_path: &Path,
96    profile_vars: &std::collections::HashMap<String, String>,
97    profile_catalogs: Option<&config::CatalogsConfig>,
98    profile_storages: Option<&config::StoragesConfig>,
99    profile_lineage: Option<&config::LineageConfig>,
100) -> FloeResult<config::RootConfig> {
101    let mut config = config::parse_config_with_vars(config_path, profile_vars)?;
102    apply_profile_catalogs(&mut config, profile_catalogs);
103    apply_profile_storages(&mut config, profile_storages);
104    apply_profile_lineage(&mut config, profile_lineage);
105    Ok(config)
106}
107
108pub fn validate_profile_file(profile_path: &Path) -> FloeResult<ProfileConfig> {
109    let profile = parse_profile(profile_path)?;
110    validate_profile(&profile)?;
111    Ok(profile)
112}
113
114pub(crate) fn apply_profile_catalogs(
115    config: &mut config::RootConfig,
116    profile_catalogs: Option<&config::CatalogsConfig>,
117) {
118    if let Some(catalogs) = profile_catalogs {
119        config.catalogs = Some(catalogs.clone());
120    }
121}
122
123pub(crate) fn apply_profile_storages(
124    config: &mut config::RootConfig,
125    profile_storages: Option<&config::StoragesConfig>,
126) {
127    if let Some(storages) = profile_storages {
128        config.storages = Some(storages.clone());
129    }
130}
131
132pub(crate) fn apply_profile_lineage(
133    config: &mut config::RootConfig,
134    profile_lineage: Option<&config::LineageConfig>,
135) {
136    if let Some(lineage) = profile_lineage {
137        config.lineage = Some(lineage.clone());
138    }
139}
140
141pub fn extract_config_env_vars(
142    config_path: &Path,
143) -> FloeResult<std::collections::HashMap<String, String>> {
144    Ok(config::extract_raw_env_vars(config_path).unwrap_or_default())
145}
146
147pub fn validate_config_for_tests(config: &config::RootConfig) -> FloeResult<()> {
148    config::validate_config(config)
149}