mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
config: add cloud-managed layer provenance
This commit is contained in:
@@ -1,5 +1,24 @@
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use serde_json::Value as JsonValue;
|
||||
use std::fmt;
|
||||
|
||||
/// Position of a fragment within the cloud-managed configuration contract.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum CloudManagedLayer {
|
||||
/// Lowest-precedence defaults supplied by the cloud bundle.
|
||||
Baseline,
|
||||
/// Managed overrides applied above system configuration.
|
||||
SystemOverlay,
|
||||
}
|
||||
|
||||
impl fmt::Display for CloudManagedLayer {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
CloudManagedLayer::Baseline => f.write_str("baseline"),
|
||||
CloudManagedLayer::SystemOverlay => f.write_str("system-overlay"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Provenance for one layer in the effective Codex configuration.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -10,6 +29,12 @@ pub enum ConfigLayerSource {
|
||||
System { file: AbsolutePathBuf },
|
||||
/// Configuration delivered by an enterprise cloud bundle.
|
||||
EnterpriseManaged { id: String, name: String },
|
||||
/// Configuration delivered through the generic cloud-managed layer contract.
|
||||
CloudManaged {
|
||||
layer: CloudManagedLayer,
|
||||
id: String,
|
||||
name: String,
|
||||
},
|
||||
/// User configuration, optionally augmented by a selected profile.
|
||||
User {
|
||||
file: AbsolutePathBuf,
|
||||
@@ -33,6 +58,10 @@ impl ConfigLayerSource {
|
||||
ConfigLayerSource::Mdm { .. } => 0,
|
||||
ConfigLayerSource::System { .. } => 10,
|
||||
ConfigLayerSource::EnterpriseManaged { .. } => 15,
|
||||
ConfigLayerSource::CloudManaged { layer, .. } => match layer {
|
||||
CloudManagedLayer::Baseline => -10,
|
||||
CloudManagedLayer::SystemOverlay => 15,
|
||||
},
|
||||
ConfigLayerSource::User { profile, .. } => {
|
||||
if profile.is_some() {
|
||||
21
|
||||
@@ -83,6 +112,9 @@ pub fn format_config_layer_source(source: &ConfigLayerSource, config_toml_file:
|
||||
ConfigLayerSource::EnterpriseManaged { id, name } => {
|
||||
format!("enterprise-managed ({name}, {id})")
|
||||
}
|
||||
ConfigLayerSource::CloudManaged { layer, id, name } => {
|
||||
format!("cloud-managed {layer} ({name}, {id})")
|
||||
}
|
||||
ConfigLayerSource::User { file, .. } => {
|
||||
format!("user ({})", file.as_path().display())
|
||||
}
|
||||
@@ -101,3 +133,7 @@ pub fn format_config_layer_source(source: &ConfigLayerSource, config_toml_file:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "config_layer_source_tests.rs"]
|
||||
mod tests;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
use super::CloudManagedLayer;
|
||||
use super::ConfigLayerSource;
|
||||
use codex_utils_absolute_path::test_support::PathBufExt;
|
||||
use codex_utils_absolute_path::test_support::test_path_buf;
|
||||
|
||||
#[test]
|
||||
fn cloud_managed_layers_have_their_contract_precedence() {
|
||||
let baseline = ConfigLayerSource::CloudManaged {
|
||||
layer: CloudManagedLayer::Baseline,
|
||||
id: "baseline-1".to_string(),
|
||||
name: "Baseline".to_string(),
|
||||
};
|
||||
let mdm = ConfigLayerSource::Mdm {
|
||||
domain: "com.openai.codex".to_string(),
|
||||
key: "config".to_string(),
|
||||
};
|
||||
let system = ConfigLayerSource::System {
|
||||
file: test_path_buf("/etc/codex/config.toml").abs(),
|
||||
};
|
||||
let overlay = ConfigLayerSource::CloudManaged {
|
||||
layer: CloudManagedLayer::SystemOverlay,
|
||||
id: "overlay-1".to_string(),
|
||||
name: "System overlay".to_string(),
|
||||
};
|
||||
let user = ConfigLayerSource::User {
|
||||
file: test_path_buf("/home/test/.codex/config.toml").abs(),
|
||||
profile: None,
|
||||
};
|
||||
|
||||
assert!(baseline < mdm);
|
||||
assert!(mdm < system);
|
||||
assert!(system < overlay);
|
||||
assert!(overlay < user);
|
||||
}
|
||||
@@ -17,6 +17,7 @@ use wildmatch::WildMatchPattern;
|
||||
|
||||
use super::requirements_exec_policy::RequirementsExecPolicy;
|
||||
use super::requirements_exec_policy::RequirementsExecPolicyToml;
|
||||
use crate::CloudManagedLayer;
|
||||
use crate::Constrained;
|
||||
use crate::ConstraintError;
|
||||
use crate::ManagedHooksRequirementsToml;
|
||||
@@ -43,6 +44,12 @@ pub enum RequirementSource {
|
||||
id: String,
|
||||
name: String,
|
||||
},
|
||||
/// A fragment delivered through the generic cloud-managed layer contract.
|
||||
CloudManaged {
|
||||
layer: CloudManagedLayer,
|
||||
id: String,
|
||||
name: String,
|
||||
},
|
||||
SystemRequirementsToml {
|
||||
file: AbsolutePathBuf,
|
||||
},
|
||||
@@ -102,6 +109,9 @@ impl fmt::Display for RequirementSource {
|
||||
RequirementSource::EnterpriseManaged { id, name } => {
|
||||
write!(f, "enterprise-managed requirements {name} ({id})")
|
||||
}
|
||||
RequirementSource::CloudManaged { layer, id, name } => {
|
||||
write!(f, "cloud-managed {layer} requirements {name} ({id})")
|
||||
}
|
||||
RequirementSource::SystemRequirementsToml { file } => {
|
||||
write!(f, "{}", file.as_path().display())
|
||||
}
|
||||
|
||||
@@ -256,6 +256,7 @@ fn config_path_for_layer(layer: &ConfigLayerEntry, config_toml_file: &str) -> Op
|
||||
ConfigLayerSource::LegacyManagedConfigTomlFromFile { file } => Some(file.to_path_buf()),
|
||||
ConfigLayerSource::Mdm { .. }
|
||||
| ConfigLayerSource::EnterpriseManaged { .. }
|
||||
| ConfigLayerSource::CloudManaged { .. }
|
||||
| ConfigLayerSource::SessionFlags
|
||||
| ConfigLayerSource::LegacyManagedConfigTomlFromMdm => None,
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ pub use cloud_config_layers::cloud_config_layers_from_fragments;
|
||||
pub use codex_protocol::config_types::ProfileV2Name;
|
||||
pub use codex_protocol::config_types::ProfileV2NameParseError;
|
||||
pub use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
pub use config_layer_source::CloudManagedLayer;
|
||||
pub use config_layer_source::ConfigLayer;
|
||||
pub use config_layer_source::ConfigLayerMetadata;
|
||||
pub use config_layer_source::ConfigLayerSource;
|
||||
|
||||
@@ -209,6 +209,7 @@ impl ConfigLayerEntry {
|
||||
ConfigLayerSource::Mdm { .. } => None,
|
||||
ConfigLayerSource::System { file } => file.parent(),
|
||||
ConfigLayerSource::EnterpriseManaged { .. } => None,
|
||||
ConfigLayerSource::CloudManaged { .. } => None,
|
||||
ConfigLayerSource::User { file, .. } => file.parent(),
|
||||
ConfigLayerSource::Project { dot_codex_folder } => Some(dot_codex_folder.clone()),
|
||||
ConfigLayerSource::SessionFlags => None,
|
||||
|
||||
Reference in New Issue
Block a user