Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect service type in environment and pipeline variable patching, add dry run #37

Merged
merged 18 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/clap_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ pub async fn init_cli() {
"🚀 Patching environment variables from input file {}\n",
input
);
set_env_vars_from_file(input, &mut cm_client, cli.ci_mode).await;
set_env_vars_from_file(input, &mut cm_client, cli.ci_mode, cli.dry_run_mode)
.await;
process::exit(0);
}
}
Expand Down Expand Up @@ -206,7 +207,13 @@ pub async fn init_cli() {
{
if let PipelineVarsCommands::Set { input } = &pipeline_vars_command {
println!("🚀 Patching pipeline variables from input file {}\n", input);
set_pipeline_vars_from_file(input, &mut cm_client, cli.ci_mode).await;
set_pipeline_vars_from_file(
input,
&mut cm_client,
cli.ci_mode,
cli.dry_run_mode,
)
.await;
process::exit(0);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/clap_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pub struct Cli {
#[clap(long = "ci", global = true, action = ArgAction::SetTrue )]
pub ci_mode: bool,

/// Only log but to not apply any changes
#[clap(long = "dry-run", global = true, action = ArgAction::SetTrue )]
pub dry_run_mode: bool,

#[clap(subcommand)]
pub command: Option<Commands>,
}
Expand Down
92 changes: 82 additions & 10 deletions src/models.rs
BerSomBen marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
use std::fmt;
use strum_macros::{EnumString, IntoStaticStr};

// Common models used across multiple modules
Expand Down Expand Up @@ -30,29 +31,42 @@ pub struct DomainConfig {
#[derive(Debug, Deserialize, Serialize)]
pub struct EnvironmentsConfig {
pub id: u32,
pub variables: Vec<Variable>,
pub variables: Vec<EnvironmentVariable>,
pub domains: Option<Vec<DomainConfig>>,
}

/// Model for a pipeline's ID and all its variables that will be read from the configuration YAML
#[derive(Debug, Deserialize, Serialize)]
pub struct PipelinesConfig {
pub id: u32,
pub variables: Vec<Variable>,
pub variables: Vec<PipelineVariable>,
}

/// Model for all information about a Cloud Manager environment variable
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Variable {
pub struct PipelineVariable {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<String>,
#[serde(rename(deserialize = "type", serialize = "type"))]
pub variable_type: VariableType,
#[serde(default = "PipelineVariableServiceType::default")]
pub service: PipelineVariableServiceType,
}

/// Model for all information about a Cloud Manager environment variable
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct EnvironmentVariable {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub service: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
pub value: Option<String>,
#[serde(rename(deserialize = "type", serialize = "type"))]
pub variable_type: VariableType,
#[serde(
default = "EnvironmentVariableServiceType::default",
skip_serializing_if = "env_var_service_type_is_default"
)]
pub service: EnvironmentVariableServiceType,
}

/// Possible types that a variable can have
Expand All @@ -63,6 +77,51 @@ pub enum VariableType {
SecretString,
}

/// Possible service types that an environment variable can have
#[derive(Clone, Debug, Deserialize, Serialize, IntoStaticStr, EnumString, PartialEq, Eq)]
#[strum(serialize_all = "lowercase")]
#[serde(rename_all = "lowercase")]
pub enum EnvironmentVariableServiceType {
All,
Author,
Publish,
Preview,
}

impl fmt::Display for EnvironmentVariableServiceType {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "{}", format!("{:?}", self).to_lowercase())
}
}
fn env_var_service_type_is_default(t: &EnvironmentVariableServiceType) -> bool {
*t == EnvironmentVariableServiceType::All
}

impl EnvironmentVariableServiceType {
fn default() -> Self {
EnvironmentVariableServiceType::All
}
}
/// Possible service types that an environment variable can have
#[derive(Clone, Debug, Deserialize, Serialize, IntoStaticStr, EnumString, PartialEq, Eq)]
#[strum(serialize_all = "lowercase")]
#[serde(rename_all = "lowercase")]
pub enum PipelineVariableServiceType {
Build,
}

impl fmt::Display for crate::models::PipelineVariableServiceType {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "{}", format!("{:?}", self).to_lowercase())
}
}

impl PipelineVariableServiceType {
fn default() -> Self {
PipelineVariableServiceType::Build
}
}

/// Model for the necessary JWT claims to retrieve an Adobe access token
#[derive(Deserialize, Serialize)]
pub struct JwtClaims {
Expand Down Expand Up @@ -139,15 +198,28 @@ pub struct Environment {

/// Struct to serialize the response of requesting /api/program/{id}/environment/{id}/variables
#[derive(Debug, Deserialize, Serialize)]
pub struct VariablesResponse {
pub struct EnvironmentVariablesResponse {
#[serde(rename(deserialize = "_embedded", serialize = "_embedded"))]
pub variables_list: VariablesList,
pub variables_list: EnvironmentVariablesList,
}

/// Struct to serialize the response of requesting /api/program/{id}/environment/{id}/variables
#[derive(Debug, Deserialize, Serialize)]
pub struct PipelineVariablesResponse {
#[serde(rename(deserialize = "_embedded", serialize = "_embedded"))]
pub variables_list: PipelineVariablesList,
}

/// Struct that holds a list of variables
#[derive(Debug, Deserialize, Serialize)]
pub struct EnvironmentVariablesList {
pub variables: Vec<EnvironmentVariable>,
}

/// Struct that holds a list of variables
#[derive(Debug, Deserialize, Serialize)]
pub struct VariablesList {
pub variables: Vec<Variable>,
pub struct PipelineVariablesList {
pub variables: Vec<PipelineVariable>,
}

// Models for representing Cloud Manager pipelines and descendant objects
Expand Down
Loading
Loading