diff --git a/Cargo.toml b/Cargo.toml index ae3639f..c690d04 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,4 +11,5 @@ yaml-rust2 = "0.7.0" dotenv = "0.15.0" log = "0.4.21" serde_yaml = "0.9.34" -toml = "0.5" \ No newline at end of file +toml = "0.5" +log4rs = "1.3.0" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 6ab90fd..4e32cce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,15 +5,51 @@ use dotenv::dotenv; use log; use std::{env, process}; +use log::LevelFilter; +use log4rs::append::console::ConsoleAppender; +use log4rs::config::{Appender, Root}; +use log4rs::Config; + // Structure to hold potential errors #[derive(Debug)] struct EnvVarError { var_name: String, } -pub fn run_pipeline(args: Vec) { +pub trait ResourceRequest { + fn transform(&self, conf: &PipelineConfig) -> String; +} + +pub fn run_pipeline() -> PipelineConfig { + #[derive(Clone)] + pub struct MyPromise { + pub params: String, + } + + impl ResourceRequest for MyPromise { + fn transform(&self, _conf: &PipelineConfig) -> String { + format!("{}", self.params) + } + } + + let request = MyPromise { + params: String::from("(default)"), + }; + + return run_custom_pipeline(Some(request)); +} + +pub fn run_custom_pipeline(_request: Option) -> PipelineConfig { dotenv().ok(); + let stdout = ConsoleAppender::builder().build(); + let config = Config::builder() + .appender(Appender::builder().build("stdout", Box::new(stdout))) + .build(Root::builder().appender("stdout").build(LevelFilter::Trace)) + .unwrap(); + + let _handle = log4rs::init_config(config).unwrap(); + // Validate environment variables up front match validate_env_vars() { Ok(()) => (), // Everything is good, proceed @@ -26,10 +62,10 @@ pub fn run_pipeline(args: Vec) { } } - if args.len() < 2 { - log::warn!("Usage: [build, pipeline, load, push, rmi, pull]"); - process::exit(1); - } + // if request.args().len() < 2 { + // log::warn!("Usage: [build, pipeline, load, push, rmi, pull]"); + // process::exit(1); + // } // Extract validated environment variables let workflow_type = env::var("KRATIX_WORKFLOW_TYPE").unwrap(); @@ -61,7 +97,11 @@ pub fn run_pipeline(args: Vec) { } } "resource" => { - log::debug!(" 1. transform resource"); + log::debug!( + " 1. transform resource {}", + _request.expect("R").transform(&config) + ); + // Fullfil resource_request.yaml promise::transform( config.res_dir(), @@ -90,6 +130,7 @@ pub fn run_pipeline(args: Vec) { //pipeline::list_files_recursively(_kratix_output_dir); log::debug!("<- End Pipeline ->"); + return config; } // validation function