Skip to content

Commit c30e324

Browse files
committed
Reserve paths instead of fields
1 parent c75dcd7 commit c30e324

File tree

1 file changed

+14
-14
lines changed
  • rs/ic_os/config_types/src

1 file changed

+14
-14
lines changed

rs/ic_os/config_types/src/lib.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//!
1414
//! - **Adding Enum Variants (Forward Compatibility)**: When adding new variants to an enum, ensure older versions can handle unknown variants gracefully by using `#[serde(other)]` on a fallback variant.
1515
//!
16-
//! - **Removing Fields**: To prevent backwards compatibility deserialization errors, required fields must not be removed directly: In a first step, they have to be given a default attribute and all IC-OS references to them have to be removed. In a second step, after the first step has rolled out to all OSes (HostOS and GuestOS) and there is no risk of a rollback, the field can be removed. Additionally, to avoid reintroducing a previously removed field, add your removed field to the RESERVED_FIELD_NAMES list.
16+
//! - **Removing Fields**: To prevent backwards compatibility deserialization errors, required fields must not be removed directly: In a first step, they have to be given a default attribute and all IC-OS references to them have to be removed. In a second step, after the first step has rolled out to all OSes (HostOS and GuestOS) and there is no risk of a rollback, the field can be removed. Additionally, to avoid reintroducing a previously removed field, add your removed field to the RESERVED_FIELD_PATHS list.
1717
//!
1818
//! - **Renaming Fields**: Avoid renaming fields unless absolutely necessary. If you must rename a field, use `#[serde(rename = "old_name")]`.
1919
//!
@@ -33,8 +33,8 @@ use url::Url;
3333

3434
pub const CONFIG_VERSION: &str = "1.8.0";
3535

36-
/// List of field names that have been removed and should not be reused.
37-
pub static RESERVED_FIELD_NAMES: &[&str] = &[];
36+
/// List of field paths that have been removed and should not be reused.
37+
pub static RESERVED_FIELD_PATHS: &[&str] = &[];
3838

3939
pub type ConfigMap = HashMap<String, String>;
4040

@@ -407,8 +407,8 @@ mod tests {
407407
}
408408

409409
#[test]
410-
fn test_no_reserved_field_names_used() -> Result<(), Box<dyn std::error::Error>> {
411-
let reserved_field_names: HashSet<&str> = RESERVED_FIELD_NAMES.iter().cloned().collect();
410+
fn test_no_reserved_field_paths_used() -> Result<(), Box<dyn std::error::Error>> {
411+
let reserved_field_paths: HashSet<&str> = RESERVED_FIELD_PATHS.iter().cloned().collect();
412412

413413
let setupos_config = SetupOSConfig {
414414
config_version: CONFIG_VERSION.to_string(),
@@ -434,17 +434,17 @@ mod tests {
434434
guestos_settings: GuestOSSettings::default(),
435435
};
436436

437-
fn get_all_field_names(value: &Value, field_names: &mut HashSet<String>) {
437+
fn get_all_field_paths(prefix: &str, value: &Value, field_names: &mut HashSet<String>) {
438438
match value {
439439
Value::Object(map) => {
440440
for (key, val) in map {
441-
field_names.insert(key.clone());
442-
get_all_field_names(val, field_names);
441+
field_names.insert(format!("{prefix}{key}"));
442+
get_all_field_paths(&format!("{prefix}{key}."), val, field_names);
443443
}
444444
}
445445
Value::Array(arr) => {
446446
for val in arr {
447-
get_all_field_names(val, field_names);
447+
get_all_field_paths(&format!("{prefix}[]."), val, field_names);
448448
}
449449
}
450450
_ => {}
@@ -453,12 +453,12 @@ mod tests {
453453

454454
let setupos_config = serde_json::to_value(&setupos_config)?;
455455

456-
let mut field_names = HashSet::new();
457-
get_all_field_names(&setupos_config, &mut field_names);
458-
for field in field_names {
456+
let mut field_paths = HashSet::new();
457+
get_all_field_paths("", &setupos_config, &mut field_paths);
458+
for field in field_paths {
459459
assert!(
460-
!reserved_field_names.contains(field.as_str()),
461-
"Field name '{field}' is reserved and should not be used."
460+
!reserved_field_paths.contains(field.as_str()),
461+
"Field path '{field}' is reserved and should not be used."
462462
);
463463
}
464464

0 commit comments

Comments
 (0)