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 full_refresh: bool,
58 pub profile: Option<ProfileConfig>,
59}
60
61pub fn validate(config_path: &Path, options: ValidateOptions) -> FloeResult<()> {
62 let config_base = config::ConfigBase::local_from_path(config_path);
63 validate_with_base(config_path, config_base, options)
64}
65
66pub fn validate_with_base(
67 config_path: &Path,
68 _config_base: config::ConfigBase,
69 options: ValidateOptions,
70) -> FloeResult<()> {
71 let mut config = config::parse_config_with_vars(config_path, &options.profile_vars)?;
72 apply_profile_catalogs(&mut config, options.profile_catalogs.as_ref());
73 apply_profile_storages(&mut config, options.profile_storages.as_ref());
74 apply_profile_lineage(&mut config, options.profile_lineage.as_ref());
75 config::validate_config(&config)?;
76
77 if !options.entities.is_empty() {
78 run::validate_entities(&config, &options.entities)?;
79 }
80
81 Ok(())
82}
83
84pub fn load_config(config_path: &Path) -> FloeResult<config::RootConfig> {
85 config::parse_config(config_path)
86}
87
88pub fn read_manifest_text(uri: &str) -> FloeResult<String> {
92 let location = config::resolve_config_location(uri)?;
93 let text = std::fs::read_to_string(&location.path)?;
94 Ok(text)
95}
96
97pub fn load_config_with_profile_vars(
98 config_path: &Path,
99 profile_vars: &std::collections::HashMap<String, String>,
100) -> FloeResult<config::RootConfig> {
101 config::parse_config_with_vars(config_path, profile_vars)
102}
103
104pub fn load_config_with_profile_overrides(
105 config_path: &Path,
106 profile_vars: &std::collections::HashMap<String, String>,
107 profile_catalogs: Option<&config::CatalogsConfig>,
108 profile_storages: Option<&config::StoragesConfig>,
109 profile_lineage: Option<&config::LineageConfig>,
110) -> FloeResult<config::RootConfig> {
111 let mut config = config::parse_config_with_vars(config_path, profile_vars)?;
112 apply_profile_catalogs(&mut config, profile_catalogs);
113 apply_profile_storages(&mut config, profile_storages);
114 apply_profile_lineage(&mut config, profile_lineage);
115 Ok(config)
116}
117
118pub fn validate_profile_file(profile_path: &Path) -> FloeResult<ProfileConfig> {
119 let profile = parse_profile(profile_path)?;
120 validate_profile(&profile)?;
121 Ok(profile)
122}
123
124pub(crate) fn apply_profile_catalogs(
125 config: &mut config::RootConfig,
126 profile_catalogs: Option<&config::CatalogsConfig>,
127) {
128 if let Some(catalogs) = profile_catalogs {
129 config.catalogs = Some(catalogs.clone());
130 }
131}
132
133pub(crate) fn apply_profile_storages(
134 config: &mut config::RootConfig,
135 profile_storages: Option<&config::StoragesConfig>,
136) {
137 if let Some(storages) = profile_storages {
138 config.storages = Some(storages.clone());
139 }
140}
141
142pub(crate) fn apply_profile_lineage(
143 config: &mut config::RootConfig,
144 profile_lineage: Option<&config::LineageConfig>,
145) {
146 if let Some(lineage) = profile_lineage {
147 config.lineage = Some(lineage.clone());
148 }
149}
150
151pub fn extract_config_env_vars(
152 config_path: &Path,
153) -> FloeResult<std::collections::HashMap<String, String>> {
154 Ok(config::extract_raw_env_vars(config_path).unwrap_or_default())
155}
156
157pub fn validate_config_for_tests(config: &config::RootConfig) -> FloeResult<()> {
158 config::validate_config(config)
159}