codex_config/
config_layer_source.rs1use codex_utils_absolute_path::AbsolutePathBuf;
2use serde_json::Value as JsonValue;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum ConfigLayerSource {
7 Mdm { domain: String, key: String },
9 System { file: AbsolutePathBuf },
11 EnterpriseManaged { id: String, name: String },
13 User {
15 file: AbsolutePathBuf,
16 profile: Option<String>,
17 },
18 Project { dot_codex_folder: AbsolutePathBuf },
20 SessionFlags,
22 LegacyManagedConfigTomlFromFile { file: AbsolutePathBuf },
24 LegacyManagedConfigTomlFromMdm,
26}
27
28impl ConfigLayerSource {
29 pub fn precedence(&self) -> i16 {
32 match self {
33 ConfigLayerSource::Mdm { .. } => 0,
34 ConfigLayerSource::System { .. } => 10,
35 ConfigLayerSource::EnterpriseManaged { .. } => 15,
36 ConfigLayerSource::User { profile, .. } => {
37 if profile.is_some() {
38 21
39 } else {
40 20
41 }
42 }
43 ConfigLayerSource::Project { .. } => 25,
44 ConfigLayerSource::SessionFlags => 30,
45 ConfigLayerSource::LegacyManagedConfigTomlFromFile { .. } => 40,
46 ConfigLayerSource::LegacyManagedConfigTomlFromMdm => 50,
47 }
48 }
49}
50
51impl PartialOrd for ConfigLayerSource {
54 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
55 Some(self.precedence().cmp(&other.precedence()))
56 }
57}
58
59#[derive(Debug, Clone, PartialEq)]
61pub struct ConfigLayerMetadata {
62 pub name: ConfigLayerSource,
63 pub version: String,
64}
65
66#[derive(Debug, Clone, PartialEq)]
68pub struct ConfigLayer {
69 pub name: ConfigLayerSource,
70 pub version: String,
71 pub config: JsonValue,
72 pub disabled_reason: Option<String>,
73}
74
75pub fn format_config_layer_source(source: &ConfigLayerSource, config_toml_file: &str) -> String {
76 match source {
77 ConfigLayerSource::Mdm { domain, key } => {
78 format!("MDM ({domain}:{key})")
79 }
80 ConfigLayerSource::System { file } => {
81 format!("system ({})", file.as_path().display())
82 }
83 ConfigLayerSource::EnterpriseManaged { id, name } => {
84 format!("enterprise-managed ({name}, {id})")
85 }
86 ConfigLayerSource::User { file, .. } => {
87 format!("user ({})", file.as_path().display())
88 }
89 ConfigLayerSource::Project { dot_codex_folder } => {
90 format!(
91 "project ({}/{config_toml_file})",
92 dot_codex_folder.as_path().display()
93 )
94 }
95 ConfigLayerSource::SessionFlags => "session-flags".to_string(),
96 ConfigLayerSource::LegacyManagedConfigTomlFromFile { file } => {
97 format!("legacy managed_config.toml ({})", file.as_path().display())
98 }
99 ConfigLayerSource::LegacyManagedConfigTomlFromMdm => {
100 "legacy managed_config.toml (MDM)".to_string()
101 }
102 }
103}