diff --git a/src/clap_app.rs b/src/clap_app.rs index 8c08c03..39bbab0 100644 --- a/src/clap_app.rs +++ b/src/clap_app.rs @@ -12,7 +12,7 @@ use crate::client::CloudManagerClient; use crate::config::CloudManagerConfig; use crate::encryption::{decrypt, encrypt}; use crate::logs::{download_log, tail_log}; -use crate::models::{Domain, LogType, ServiceType}; +use crate::models::{Domain, LogType, PipelineVariableServiceType, EnvironmentVariableServiceType, ServiceType}; use crate::variables::{ get_env_vars, get_pipeline_vars, set_env_vars_from_file, set_pipeline_vars_from_file, }; @@ -95,6 +95,17 @@ pub async fn init_cli() { .await .unwrap(); println!("{}", serde_json::to_string_pretty(&env_vars).unwrap()); + if let Some(vf) = env_vars.variables.iter().find(|vf| { + vf.service == EnvironmentVariableServiceType::Invalid + }) { + eprintln!( + "{:>8} {} '{}: {}'", + "⚠".yellow(), + "WARN, invalid service type detected for variable".yellow(), + vf.name, + vf.service + ); + } } } else { eprintln!("❌ You have to provide a valid Cloud Manager environment ID to run this command!"); @@ -283,10 +294,24 @@ pub async fn init_cli() { get_pipeline_vars(&mut cm_client, program_id, &pipeline_id) .await .unwrap(); + println!( "{}", serde_json::to_string_pretty(&pipeline_vars).unwrap() ); + if let Some(vf) = pipeline_vars + .variables + .iter() + .find(|vf| vf.service == PipelineVariableServiceType::Invalid) + { + eprintln!( + "{:>8} {} '{}: {}'", + "⚠".yellow(), + "WARN, invalid service type detected for variable".yellow(), + vf.name, + vf.service + ); + } } } else { eprintln!("❌ You have to provide a valid Cloud Manager pipeline ID to run this command!"); diff --git a/src/models.rs b/src/models.rs index 7d9e747..26b406a 100644 --- a/src/models.rs +++ b/src/models.rs @@ -62,7 +62,7 @@ pub struct EnvironmentVariable { pub variable_type: VariableType, #[serde( default = "EnvironmentVariableServiceType::default", - skip_serializing_if = "env_var_service_type_is_default" + skip_serializing_if = "environment_variable_skip_serializing" )] pub service: EnvironmentVariableServiceType, } @@ -76,14 +76,20 @@ pub enum EnvironmentVariableServiceType { Author, Publish, Preview, + #[serde(other)] + Invalid, } impl fmt::Display for EnvironmentVariableServiceType { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - write!(formatter, "{}", format!("{:?}", self).to_lowercase()) + write!( + formatter, + "{}", + format!("{}", serde_json::to_string(self).unwrap().to_string()) + ) } } -fn env_var_service_type_is_default(t: &EnvironmentVariableServiceType) -> bool { +fn environment_variable_skip_serializing(t: &EnvironmentVariableServiceType) -> bool { *t == EnvironmentVariableServiceType::All } @@ -108,15 +114,23 @@ pub struct PipelineVariable { /// Possible service types that an pipeline variable can have #[derive(Clone, Debug, Deserialize, Serialize, IntoStaticStr, EnumString, PartialEq, Eq)] -#[strum(serialize_all = "lowercase")] -#[serde(rename_all = "lowercase")] +#[strum(serialize_all = "camelCase")] +#[serde(rename_all = "camelCase")] pub enum PipelineVariableServiceType { Build, + UiTest, + FunctionalTest, + #[serde(other)] + Invalid, } impl fmt::Display for PipelineVariableServiceType { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - write!(formatter, "{}", format!("{:?}", self).to_lowercase()) + write!( + formatter, + "{}", + format!("{}", serde_json::to_string(self).unwrap().to_string()) + ) } } diff --git a/src/variables.rs b/src/variables.rs index 1ebc9e5..13df0d5 100644 --- a/src/variables.rs +++ b/src/variables.rs @@ -3,7 +3,8 @@ use crate::encryption::decrypt; use crate::environments::get_environment; use crate::errors::throw_adobe_api_error; use crate::models::{ - EnvironmentVariable, EnvironmentVariablesList, EnvironmentVariablesResponse, PipelineVariable, + EnvironmentVariable, EnvironmentVariableServiceType, EnvironmentVariablesList, + EnvironmentVariablesResponse, PipelineVariable, PipelineVariableServiceType, PipelineVariablesList, PipelineVariablesResponse, VariableType, YamlConfig, }; use crate::pipelines::get_pipeline; @@ -197,6 +198,20 @@ pub async fn set_env_vars_from_file( } } + if let Some(vf) = vars_final + .iter() + .find(|vf| vf.service == EnvironmentVariableServiceType::Invalid) + { + eprintln!( + "{:>8} {} '{}: {}'", + "❌".red(), + "ERROR, invalid service type detected for variable".red(), + vf.name, + vf.service + ); + process::exit(3); + } + for vf in &vars_final { match vf.value { None => { @@ -427,6 +442,20 @@ pub async fn set_pipeline_vars_from_file( } } + if let Some(vf) = vars_final + .iter() + .find(|vf| vf.service == PipelineVariableServiceType::Invalid) + { + eprintln!( + "{:>8} {} '{}: {}'", + "❌".red(), + "ERROR, invalid service type detected for variable".red(), + vf.name, + vf.service + ); + process::exit(3); + } + for vf in &vars_final { match vf.value { None => {