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

Fixes #23568: Mark yaml format as 1.0 #5094

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions policies/rudderc/src/frontends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use format_serde_error::SerdeError;
use rudder_commons::methods::{self, Methods};
use tracing::{error, trace};

use crate::{compiler::user_error, ir::Technique};
use crate::{
compiler::user_error,
ir::{technique::TECHNIQUE_FORMAT_VERSION, Technique},
};

/// Rudder technique represented in YAML file
pub fn read(input: &str) -> Result<Technique> {
Expand All @@ -27,7 +30,7 @@ pub fn read(input: &str) -> Result<Technique> {
trace!("Parsed input:\n{:#?}", policy);

// Stop if unknown format
if policy.format != 0 {
if policy.format != TECHNIQUE_FORMAT_VERSION {
error!("Unknown policy format version: {}", policy.format);
user_error()
}
Expand Down
12 changes: 9 additions & 3 deletions policies/rudderc/src/ir/technique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use uuid::Uuid;

use crate::ir::condition::Condition;

pub const TECHNIQUE_FORMAT_VERSION: usize = 1;

/// Valid id for techniques, methods, etc.
///
/// Lowest common denominator between target platforms.
Expand Down Expand Up @@ -232,7 +234,7 @@ impl Display for PasswordType {
impl Default for Technique {
fn default() -> Self {
Self {
format: 0,
format: TECHNIQUE_FORMAT_VERSION,
id: Id::from_str("my_technique").unwrap(),
name: "My technique".to_string(),
version: "1.0".to_string(),
Expand All @@ -249,7 +251,7 @@ impl Default for Technique {
/// A Rudder technique (based on methods and/or modules)
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Technique {
#[serde(default)]
#[serde(default = "Technique::default_format")]
#[serde(skip_serializing_if = "Technique::format_is_default")]
pub format: usize,
pub id: Id,
Expand All @@ -271,7 +273,11 @@ pub struct Technique {

impl Technique {
fn format_is_default(format: &usize) -> bool {
*format == 0
*format == TECHNIQUE_FORMAT_VERSION
}

fn default_format() -> usize {
TECHNIQUE_FORMAT_VERSION
}
}

Expand Down