#![allow(dead_code)]
use std::collections::HashMap;
pub fn is_plugin_blocked_by_policy(plugin_id: &str) -> bool {
get_settings_for_source("policySettings")
.and_then(|settings| settings.enabled_plugins)
.and_then(|enabled| enabled.get(plugin_id).cloned())
== Some(false)
}
#[derive(serde::Deserialize)]
struct SettingsSource {
enabled_plugins: Option<HashMap<String, bool>>,
}
fn get_settings_for_source(source: &str) -> Option<SettingsSource> {
match source {
"policySettings" => {
if let Ok(policy_json) = std::env::var("AI_CODE_PLUGIN_POLICY") {
if let Ok(settings) = serde_json::from_str(&policy_json) {
return Some(settings);
}
}
None
}
_ => None,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_not_blocked_without_policy() {
#[allow(unused_unsafe)]
unsafe {
std::env::remove_var("AI_CODE_PLUGIN_POLICY");
}
assert!(!is_plugin_blocked_by_policy("some-plugin"));
}
}