Skip to content

Commit

Permalink
Feat/enabletraits (#6)
Browse files Browse the repository at this point in the history
Signed-off-by: Howard <[email protected]>
  • Loading branch information
howard-oc authored Apr 25, 2024
1 parent ab0f360 commit fd7ab70
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
toml = "0.5"
log4rs = "1.3.0"
53 changes: 47 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) {
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<impl ResourceRequest>) -> 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
Expand All @@ -26,10 +62,10 @@ pub fn run_pipeline(args: Vec<String>) {
}
}

if args.len() < 2 {
log::warn!("Usage: <command> [build, pipeline, load, push, rmi, pull]");
process::exit(1);
}
// if request.args().len() < 2 {
// log::warn!("Usage: <command> [build, pipeline, load, push, rmi, pull]");
// process::exit(1);
// }

// Extract validated environment variables
let workflow_type = env::var("KRATIX_WORKFLOW_TYPE").unwrap();
Expand Down Expand Up @@ -61,7 +97,11 @@ pub fn run_pipeline(args: Vec<String>) {
}
}
"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(),
Expand Down Expand Up @@ -90,6 +130,7 @@ pub fn run_pipeline(args: Vec<String>) {
//pipeline::list_files_recursively(_kratix_output_dir);

log::debug!("<- End Pipeline ->");
return config;
}

// validation function
Expand Down

0 comments on commit fd7ab70

Please sign in to comment.