From 1d1cade504f722d70e81da3e9b441ba92ac86559 Mon Sep 17 00:00:00 2001 From: Tobias Richter Date: Mon, 14 Oct 2024 14:48:48 +0200 Subject: [PATCH 1/9] Add invalid variable service type for environments and pipelines --- src/models.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/models.rs b/src/models.rs index 7d9e747..d06da1e 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,6 +76,8 @@ pub enum EnvironmentVariableServiceType { Author, Publish, Preview, + #[serde(other)] + Invalid, } impl fmt::Display for EnvironmentVariableServiceType { @@ -83,7 +85,7 @@ impl fmt::Display for EnvironmentVariableServiceType { write!(formatter, "{}", format!("{:?}", self).to_lowercase()) } } -fn env_var_service_type_is_default(t: &EnvironmentVariableServiceType) -> bool { +fn environment_variable_skip_serializing(t: &EnvironmentVariableServiceType) -> bool { *t == EnvironmentVariableServiceType::All } @@ -102,7 +104,9 @@ pub struct PipelineVariable { pub value: Option, #[serde(rename(deserialize = "type", serialize = "type"))] pub variable_type: VariableType, - #[serde(default = "PipelineVariableServiceType::default")] + #[serde( + default = "PipelineVariableServiceType::default" + )] pub service: PipelineVariableServiceType, } @@ -112,6 +116,8 @@ pub struct PipelineVariable { #[serde(rename_all = "lowercase")] pub enum PipelineVariableServiceType { Build, + #[serde(other)] + Invalid } impl fmt::Display for PipelineVariableServiceType { From 44f7d1262a1f792e6f62adf64473a135945497dd Mon Sep 17 00:00:00 2001 From: Tobias Richter Date: Mon, 14 Oct 2024 15:49:24 +0200 Subject: [PATCH 2/9] Ensure formatting is performed using serde settings --- src/models.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/models.rs b/src/models.rs index d06da1e..d7260bd 100644 --- a/src/models.rs +++ b/src/models.rs @@ -82,7 +82,11 @@ pub enum EnvironmentVariableServiceType { 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 environment_variable_skip_serializing(t: &EnvironmentVariableServiceType) -> bool { @@ -122,7 +126,11 @@ pub enum PipelineVariableServiceType { 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()) + ) } } From ba547cbc5fd605ab5814976b7ccc48fcd474c9ad Mon Sep 17 00:00:00 2001 From: Tobias Richter Date: Mon, 14 Oct 2024 15:49:58 +0200 Subject: [PATCH 3/9] Add more service types for pipeline variables --- src/models.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/models.rs b/src/models.rs index d7260bd..7175656 100644 --- a/src/models.rs +++ b/src/models.rs @@ -116,12 +116,14 @@ 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 + Invalid, } impl fmt::Display for PipelineVariableServiceType { From 62fe9f2cbc6e878403391be3cb53a7cc728240c3 Mon Sep 17 00:00:00 2001 From: Tobias Richter Date: Mon, 14 Oct 2024 15:50:18 +0200 Subject: [PATCH 4/9] formatting --- src/models.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/models.rs b/src/models.rs index 7175656..26b406a 100644 --- a/src/models.rs +++ b/src/models.rs @@ -108,9 +108,7 @@ pub struct PipelineVariable { pub value: Option, #[serde(rename(deserialize = "type", serialize = "type"))] pub variable_type: VariableType, - #[serde( - default = "PipelineVariableServiceType::default" - )] + #[serde(default = "PipelineVariableServiceType::default")] pub service: PipelineVariableServiceType, } From 8165d0302184c60ed4c27fb34c3ec849a91a6b0b Mon Sep 17 00:00:00 2001 From: Tobias Richter Date: Mon, 14 Oct 2024 15:51:04 +0200 Subject: [PATCH 5/9] Check for invalid service types for pipeline and environment variables and exit with error if found --- src/variables.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/variables.rs b/src/variables.rs index 1ebc9e5..b4c25f6 100644 --- a/src/variables.rs +++ b/src/variables.rs @@ -198,6 +198,17 @@ pub async fn set_env_vars_from_file( } for vf in &vars_final { + // check if service is invalid and error exit when this is the case. + if vf.service == EnvironmentVariableServiceType::Invalid { + eprintln!( + "{:>8} {} '{}'", + "❌".red(), + "Error, invalid service type detected for variable ".red(), + vf.name + ); + process::exit(3); + } + match vf.value { None => { println!( @@ -428,6 +439,17 @@ pub async fn set_pipeline_vars_from_file( } for vf in &vars_final { + // check if service is invalid and error exit when this is the case. + if vf.service == PipelineVariableServiceType::Invalid { + eprintln!( + "{:>8} {} '{}'", + "❌".red(), + "Error, invalid service type detected for variable ".red(), + vf.name + ); + process::exit(3); + } + match vf.value { None => { println!( From cae84e3dc279ec469ff0a43b54d066fca2d27d97 Mon Sep 17 00:00:00 2001 From: Tobias Richter Date: Mon, 14 Oct 2024 15:51:15 +0200 Subject: [PATCH 6/9] Formatting --- src/variables.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/variables.rs b/src/variables.rs index b4c25f6..a23bef9 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; From 9fb7a5f742e45deaed8bfe645e3bbbafeac465c1 Mon Sep 17 00:00:00 2001 From: Benjamin Sommerfeld Date: Mon, 14 Oct 2024 16:51:08 +0200 Subject: [PATCH 7/9] feat: check complete list for invalid entries, instead each individual entry. Add warn message, if there are any invalid entries on CM already --- src/clap_app.rs | 16 +++++++++++++++- src/variables.rs | 50 +++++++++++++++++++++++++++--------------------- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/clap_app.rs b/src/clap_app.rs index 8c08c03..58c4781 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, ServiceType}; use crate::variables::{ get_env_vars, get_pipeline_vars, set_env_vars_from_file, set_pipeline_vars_from_file, }; @@ -283,10 +283,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/variables.rs b/src/variables.rs index a23bef9..13df0d5 100644 --- a/src/variables.rs +++ b/src/variables.rs @@ -198,18 +198,21 @@ pub async fn set_env_vars_from_file( } } - for vf in &vars_final { - // check if service is invalid and error exit when this is the case. - if vf.service == EnvironmentVariableServiceType::Invalid { - eprintln!( - "{:>8} {} '{}'", - "❌".red(), - "Error, invalid service type detected for variable ".red(), - vf.name - ); - process::exit(3); - } + 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 => { println!( @@ -439,18 +442,21 @@ pub async fn set_pipeline_vars_from_file( } } - for vf in &vars_final { - // check if service is invalid and error exit when this is the case. - if vf.service == PipelineVariableServiceType::Invalid { - eprintln!( - "{:>8} {} '{}'", - "❌".red(), - "Error, invalid service type detected for variable ".red(), - vf.name - ); - process::exit(3); - } + 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 => { println!( From 3a6913c569d73c28d4ecdbe77dc88bf5626c5c56 Mon Sep 17 00:00:00 2001 From: Benjamin Sommerfeld Date: Tue, 15 Oct 2024 08:18:02 +0200 Subject: [PATCH 8/9] feat: add warn log for environment, if invalid types are present on CM --- src/clap_app.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/clap_app.rs b/src/clap_app.rs index 58c4781..357ca20 100644 --- a/src/clap_app.rs +++ b/src/clap_app.rs @@ -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!"); From dd02ce9596c8d58cee8ebe2e208df143b328caf5 Mon Sep 17 00:00:00 2001 From: Benjamin Sommerfeld Date: Tue, 15 Oct 2024 08:45:36 +0200 Subject: [PATCH 9/9] fix: use crate --- src/clap_app.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clap_app.rs b/src/clap_app.rs index 357ca20..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, PipelineVariableServiceType, 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, };