ai_agent/utils/plugins/
plugin_policy.rs1#![allow(dead_code)]
3
4use std::collections::HashMap;
5
6pub fn is_plugin_blocked_by_policy(plugin_id: &str) -> bool {
8 get_settings_for_source("policySettings")
9 .and_then(|settings| settings.enabled_plugins)
10 .and_then(|enabled| enabled.get(plugin_id).cloned())
11 == Some(false)
12}
13
14#[derive(serde::Deserialize)]
16struct SettingsSource {
17 enabled_plugins: Option<HashMap<String, bool>>,
18}
19
20fn get_settings_for_source(source: &str) -> Option<SettingsSource> {
22 match source {
23 "policySettings" => {
24 if let Ok(policy_json) = std::env::var("AI_CODE_PLUGIN_POLICY") {
25 if let Ok(settings) = serde_json::from_str(&policy_json) {
26 return Some(settings);
27 }
28 }
29 None
30 }
31 _ => None,
32 }
33}
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn test_not_blocked_without_policy() {
41 #[allow(unused_unsafe)]
42 unsafe {
43 std::env::remove_var("AI_CODE_PLUGIN_POLICY");
44 }
45 assert!(!is_plugin_blocked_by_policy("some-plugin"));
46 }
47}