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 read_manifest_text(uri: &str) -> FloeResult<String> {
91 let location = config::resolve_config_location(uri)?;
92 let text = std::fs::read_to_string(&location.path)?;
93 Ok(text)
94}
95
96pub fn load_config_with_profile_vars(
97 config_path: &Path,
98 profile_vars: &std::collections::HashMap<String, String>,
99) -> FloeResult<config::RootConfig> {
100 config::parse_config_with_vars(config_path, profile_vars)
101}
102
103pub fn load_config_with_profile_overrides(
104 config_path: &Path,
105 profile_vars: &std::collections::HashMap<String, String>,
106 profile_catalogs: Option<&config::CatalogsConfig>,
107 profile_storages: Option<&config::StoragesConfig>,
108 profile_lineage: Option<&config::LineageConfig>,
109) -> FloeResult<config::RootConfig> {
110 let mut config = config::parse_config_with_vars(config_path, profile_vars)?;
111 apply_profile_catalogs(&mut config, profile_catalogs);
112 apply_profile_storages(&mut config, profile_storages);
113 apply_profile_lineage(&mut config, profile_lineage);
114 Ok(config)
115}
116
117pub fn validate_profile_file(profile_path: &Path) -> FloeResult<ProfileConfig> {
118 let profile = parse_profile(profile_path)?;
119 validate_profile(&profile)?;
120 Ok(profile)
121}
122
123pub(crate) fn apply_profile_catalogs(
124 config: &mut config::RootConfig,
125 profile_catalogs: Option<&config::CatalogsConfig>,
126) {
127 if let Some(catalogs) = profile_catalogs {
128 config.catalogs = Some(catalogs.clone());
129 }
130}
131
132pub(crate) fn apply_profile_storages(
133 config: &mut config::RootConfig,
134 profile_storages: Option<&config::StoragesConfig>,
135) {
136 if let Some(storages) = profile_storages {
137 config.storages = Some(storages.clone());
138 }
139}
140
141pub(crate) fn apply_profile_lineage(
142 config: &mut config::RootConfig,
143 profile_lineage: Option<&config::LineageConfig>,
144) {
145 if let Some(lineage) = profile_lineage {
146 config.lineage = Some(lineage.clone());
147 }
148}
149
150pub fn extract_config_env_vars(
151 config_path: &Path,
152) -> FloeResult<std::collections::HashMap<String, String>> {
153 Ok(config::extract_raw_env_vars(config_path).unwrap_or_default())
154}
155
156pub fn validate_config_for_tests(config: &config::RootConfig) -> FloeResult<()> {
157 config::validate_config(config)
158}