MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / from_files

Method from_files

crates/openshell-supervisor-network/src/opa.rs:141–157  ·  view source on GitHub ↗

Load policy from a `.rego` rules file and data from a YAML file. Preprocesses the YAML data to expand access presets and validate L7 config.

(policy_path: &Path, data_path: &Path)

Source from the content-addressed store, hash-verified

139 ///
140 /// Preprocesses the YAML data to expand access presets and validate L7 config.
141 pub fn from_files(policy_path: &Path, data_path: &Path) -> Result<Self> {
142 let yaml_str = std::fs::read_to_string(data_path).map_err(|e| {
143 miette::miette!("failed to read YAML data from {}: {e}", data_path.display())
144 })?;
145 let mut engine = regorus::Engine::new();
146 engine
147 .add_policy_from_file(policy_path)
148 .map_err(|e| miette::miette!("{e}"))?;
149 let data_json = preprocess_yaml_data(&yaml_str)?;
150 engine
151 .add_data_json(&data_json)
152 .map_err(|e| miette::miette!("{e}"))?;
153 Ok(Self {
154 engine: Mutex::new(engine),
155 generation: Arc::new(AtomicU64::new(0)),
156 })
157 }
158
159 /// Load policy rules and data from strings (data is YAML).
160 ///

Callers

nothing calls this directly

Calls 1

preprocess_yaml_dataFunction · 0.85

Tested by

no test coverage detected