Log individual setting changes between two snapshots.
(
old: &std::collections::HashMap<String, openshell_core::proto::EffectiveSetting>,
new: &std::collections::HashMap<String, openshell_core::proto::EffectiveSetting>,
)
| 1884 | |
| 1885 | /// Log individual setting changes between two snapshots. |
| 1886 | fn log_setting_changes( |
| 1887 | old: &std::collections::HashMap<String, openshell_core::proto::EffectiveSetting>, |
| 1888 | new: &std::collections::HashMap<String, openshell_core::proto::EffectiveSetting>, |
| 1889 | ) { |
| 1890 | for (key, new_es) in new { |
| 1891 | let new_val = format_setting_value(new_es); |
| 1892 | match old.get(key) { |
| 1893 | Some(old_es) => { |
| 1894 | let old_val = format_setting_value(old_es); |
| 1895 | if old_val != new_val { |
| 1896 | ocsf_emit!( |
| 1897 | ConfigStateChangeBuilder::new(ocsf_ctx()) |
| 1898 | .severity(SeverityId::Informational) |
| 1899 | .status(StatusId::Success) |
| 1900 | .state(StateId::Enabled, "updated") |
| 1901 | .unmapped("key", serde_json::json!(key)) |
| 1902 | .unmapped("old", serde_json::json!(old_val.clone())) |
| 1903 | .unmapped("new", serde_json::json!(new_val.clone())) |
| 1904 | .message(format!( |
| 1905 | "Setting changed [key:{key} old:{old_val} new:{new_val}]" |
| 1906 | )) |
| 1907 | .build() |
| 1908 | ); |
| 1909 | } |
| 1910 | } |
| 1911 | None => { |
| 1912 | ocsf_emit!( |
| 1913 | ConfigStateChangeBuilder::new(ocsf_ctx()) |
| 1914 | .severity(SeverityId::Informational) |
| 1915 | .status(StatusId::Success) |
| 1916 | .state(StateId::Enabled, "enabled") |
| 1917 | .unmapped("key", serde_json::json!(key)) |
| 1918 | .unmapped("value", serde_json::json!(new_val.clone())) |
| 1919 | .message(format!("Setting added [key:{key} value:{new_val}]")) |
| 1920 | .build() |
| 1921 | ); |
| 1922 | } |
| 1923 | } |
| 1924 | } |
| 1925 | for key in old.keys() { |
| 1926 | if !new.contains_key(key) { |
| 1927 | ocsf_emit!( |
| 1928 | ConfigStateChangeBuilder::new(ocsf_ctx()) |
| 1929 | .severity(SeverityId::Informational) |
| 1930 | .status(StatusId::Success) |
| 1931 | .state(StateId::Disabled, "disabled") |
| 1932 | .unmapped("key", serde_json::json!(key)) |
| 1933 | .message(format!("Setting removed [key:{key}]")) |
| 1934 | .build() |
| 1935 | ); |
| 1936 | } |
| 1937 | } |
| 1938 | } |
| 1939 | |
| 1940 | /// Format an `EffectiveSetting` value for log display. |
| 1941 | fn format_setting_value(es: &openshell_core::proto::EffectiveSetting) -> String { |
no test coverage detected