Ugh
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use super::{MetaPlugin, MetaPluginType, process_metadata_outputs, BaseMetaPlugin};
|
||||
use super::{BaseMetaPlugin, MetaPlugin, MetaPluginType, process_metadata_outputs};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
/// Meta plugin that extracts environment variables prefixed with KEEP_META_ as metadata.
|
||||
@@ -28,29 +28,29 @@ impl EnvMetaPlugin {
|
||||
// Collect environment variables starting with KEEP_META_
|
||||
let mut env_vars = Vec::new();
|
||||
let mut outputs_map = std::collections::HashMap::new();
|
||||
|
||||
|
||||
for (key, value) in std::env::vars() {
|
||||
if let Some(stripped_key) = key.strip_prefix("KEEP_META_") {
|
||||
// Add to env_vars to process later
|
||||
env_vars.push((stripped_key.to_string(), value));
|
||||
// Add to outputs with default mapping to the stripped name
|
||||
outputs_map.insert(
|
||||
stripped_key.to_string(),
|
||||
serde_yaml::Value::String(stripped_key.to_string())
|
||||
stripped_key.to_string(),
|
||||
serde_yaml::Value::String(stripped_key.to_string()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Override with provided outputs
|
||||
if let Some(provided_outputs) = outputs {
|
||||
for (key, value) in provided_outputs {
|
||||
outputs_map.insert(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let mut base = BaseMetaPlugin::new();
|
||||
base.outputs = outputs_map;
|
||||
|
||||
|
||||
EnvMetaPlugin {
|
||||
is_finalized: false,
|
||||
base,
|
||||
@@ -68,7 +68,7 @@ impl MetaPlugin for EnvMetaPlugin {
|
||||
fn meta_type(&self) -> MetaPluginType {
|
||||
MetaPluginType::Env
|
||||
}
|
||||
|
||||
|
||||
/// Checks if the plugin has been finalized.
|
||||
///
|
||||
/// # Returns
|
||||
@@ -77,7 +77,7 @@ impl MetaPlugin for EnvMetaPlugin {
|
||||
fn is_finalized(&self) -> bool {
|
||||
self.is_finalized
|
||||
}
|
||||
|
||||
|
||||
/// Sets the finalized state of the plugin.
|
||||
///
|
||||
/// # Arguments
|
||||
@@ -86,7 +86,7 @@ impl MetaPlugin for EnvMetaPlugin {
|
||||
fn set_finalized(&mut self, finalized: bool) {
|
||||
self.is_finalized = finalized;
|
||||
}
|
||||
|
||||
|
||||
/// Initializes the plugin, processing environment variables.
|
||||
///
|
||||
/// Processes all KEEP_META_* variables and generates metadata using output mappings.
|
||||
@@ -102,28 +102,28 @@ impl MetaPlugin for EnvMetaPlugin {
|
||||
is_finalized: true,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Process all collected environment variables
|
||||
let mut metadata = Vec::new();
|
||||
for (name, value) in &self.env_vars {
|
||||
if let Some(meta_data) = process_metadata_outputs(
|
||||
name,
|
||||
serde_yaml::Value::String(value.clone()),
|
||||
self.base.outputs()
|
||||
self.base.outputs(),
|
||||
) {
|
||||
metadata.push(meta_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Mark as finalized since this plugin only needs to run once
|
||||
self.is_finalized = true;
|
||||
|
||||
|
||||
crate::meta_plugin::MetaPluginResponse {
|
||||
metadata,
|
||||
is_finalized: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Updates the plugin with new data (unused in this implementation).
|
||||
///
|
||||
/// This plugin does not process streaming data; returns empty response.
|
||||
@@ -143,7 +143,7 @@ impl MetaPlugin for EnvMetaPlugin {
|
||||
is_finalized: true,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
crate::meta_plugin::MetaPluginResponse {
|
||||
metadata: Vec::new(),
|
||||
is_finalized: false,
|
||||
@@ -162,13 +162,13 @@ impl MetaPlugin for EnvMetaPlugin {
|
||||
if !self.is_finalized {
|
||||
return self.initialize();
|
||||
}
|
||||
|
||||
|
||||
crate::meta_plugin::MetaPluginResponse {
|
||||
metadata: Vec::new(),
|
||||
is_finalized: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Returns a reference to the outputs mapping.
|
||||
///
|
||||
/// # Returns
|
||||
@@ -177,7 +177,7 @@ impl MetaPlugin for EnvMetaPlugin {
|
||||
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
self.base.outputs()
|
||||
}
|
||||
|
||||
|
||||
/// Returns a mutable reference to the outputs mapping.
|
||||
///
|
||||
/// # Returns
|
||||
@@ -186,18 +186,16 @@ impl MetaPlugin for EnvMetaPlugin {
|
||||
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
|
||||
self.base.outputs_mut()
|
||||
}
|
||||
|
||||
|
||||
/// Returns the default output names based on collected env vars.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// A vector of environment variable names (stripped of KEEP_META_ prefix).
|
||||
fn default_outputs(&self) -> Vec<String> {
|
||||
self.env_vars.iter()
|
||||
.map(|(name, _)| name.clone())
|
||||
.collect()
|
||||
self.env_vars.iter().map(|(name, _)| name.clone()).collect()
|
||||
}
|
||||
|
||||
|
||||
/// Returns a reference to the options mapping (empty for this plugin).
|
||||
///
|
||||
/// This plugin has no configurable options.
|
||||
@@ -208,7 +206,7 @@ impl MetaPlugin for EnvMetaPlugin {
|
||||
fn options(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
self.base.options()
|
||||
}
|
||||
|
||||
|
||||
/// Returns a mutable reference to the options mapping.
|
||||
///
|
||||
/// # Panics
|
||||
|
||||
Reference in New Issue
Block a user