ai_agent/utils/plugins/
managed_plugins.rs1#![allow(dead_code)]
3
4use std::collections::{HashMap, HashSet};
5
6pub fn get_managed_plugin_names() -> Option<HashSet<String>> {
8 let enabled_plugins =
9 get_settings_for_source("policySettings").and_then(|settings| settings.enabled_plugins)?;
10
11 if enabled_plugins.is_empty() {
12 return None;
13 }
14
15 let mut names = HashSet::new();
16 for (plugin_id, value) in &enabled_plugins {
17 if !plugin_id.contains('@') {
18 continue;
19 }
20
21 if let Some(name) = plugin_id.split('@').next() {
22 if !name.is_empty() {
23 names.insert(name.to_string());
24 }
25 }
26 }
27
28 if names.is_empty() { None } else { Some(names) }
29}
30
31#[derive(serde::Deserialize)]
33struct SettingsSource {
34 enabled_plugins: Option<HashMap<String, serde_json::Value>>,
35}
36
37fn get_settings_for_source(source: &str) -> Option<SettingsSource> {
39 match source {
40 "policySettings" => {
41 if let Ok(policy_json) = std::env::var("AI_CODE_PLUGIN_POLICY") {
42 if let Ok(settings) = serde_json::from_str(&policy_json) {
43 return Some(settings);
44 }
45 }
46 None
47 }
48 _ => None,
49 }
50}
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_no_policy_returns_none() {
58 #[allow(unused_unsafe)]
59 unsafe {
60 std::env::remove_var("AI_CODE_PLUGIN_POLICY");
61 }
62 assert!(get_managed_plugin_names().is_none());
63 }
64}