refactor: update meta plugin to use output mappings
Co-authored-by: aider (openai/andrew/openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
@@ -41,12 +41,33 @@ pub enum MetaPluginType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Central function to handle metadata output with name mapping
|
/// Central function to handle metadata output with name mapping
|
||||||
pub fn output_metadata(conn: &Connection, item_id: i64, name: &str, value: String, output_names: &std::collections::HashMap<String, String>) -> Result<()> {
|
/// outputs: HashMap where key is internal name, value is either custom name or "false" to disable
|
||||||
let output_name = output_names.get(name).cloned().unwrap_or_else(|| name.to_string());
|
pub fn output_metadata(conn: &Connection, item_id: i64, internal_name: &str, value: String, outputs: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||||
debug!("META: Saving metadata: item_id={}, name={}, value={}", item_id, output_name, value);
|
// Check if this output is disabled
|
||||||
|
if let Some(mapping) = outputs.get(internal_name) {
|
||||||
|
if let Some(false_val) = mapping.as_bool() {
|
||||||
|
if !false_val {
|
||||||
|
debug!("META: Skipping disabled output: {}", internal_name);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(custom_name) = mapping.as_str() {
|
||||||
|
debug!("META: Saving metadata: item_id={}, internal_name={}, custom_name={}, value={}", item_id, internal_name, custom_name, value);
|
||||||
let meta = crate::db::Meta {
|
let meta = crate::db::Meta {
|
||||||
id: item_id,
|
id: item_id,
|
||||||
name: output_name,
|
name: custom_name.to_string(),
|
||||||
|
value,
|
||||||
|
};
|
||||||
|
crate::db::store_meta(conn, meta)?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default: use internal name as output name
|
||||||
|
debug!("META: Saving metadata: item_id={}, name={}, value={}", item_id, internal_name, value);
|
||||||
|
let meta = crate::db::Meta {
|
||||||
|
id: item_id,
|
||||||
|
name: internal_name.to_string(),
|
||||||
value,
|
value,
|
||||||
};
|
};
|
||||||
crate::db::store_meta(conn, meta)?;
|
crate::db::store_meta(conn, meta)?;
|
||||||
@@ -80,21 +101,20 @@ pub trait MetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save metadata to database using central output handler
|
// Save metadata to database using central output handler
|
||||||
fn save_meta(&mut self, conn: &Connection, item_id: i64, value: String) -> Result<()> {
|
fn save_meta(&mut self, conn: &Connection, item_id: i64, internal_name: &str, value: String) -> Result<()> {
|
||||||
let meta_name = self.meta_name();
|
output_metadata(conn, item_id, internal_name, value, self.get_outputs())
|
||||||
// Default implementation: no output name mapping
|
|
||||||
output_metadata(conn, item_id, &meta_name, value, &std::collections::HashMap::new())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure plugin with options
|
// Configure plugin with options and outputs
|
||||||
fn configure(&mut self, _options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
fn configure(&mut self, _options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get output name mapping
|
// Get outputs mapping
|
||||||
fn get_output_name(&self, default_name: &str) -> String {
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value>;
|
||||||
default_name.to_string()
|
|
||||||
}
|
// Set outputs mapping
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box<dyn MetaPlugin> {
|
pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box<dyn MetaPlugin> {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ pub struct BinaryMetaPlugin {
|
|||||||
max_buffer_size: usize,
|
max_buffer_size: usize,
|
||||||
is_saved: bool,
|
is_saved: bool,
|
||||||
item_id: Option<i64>,
|
item_id: Option<i64>,
|
||||||
output_names: std::collections::HashMap<String, String>,
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BinaryMetaPlugin {
|
impl BinaryMetaPlugin {
|
||||||
@@ -22,7 +22,7 @@ impl BinaryMetaPlugin {
|
|||||||
max_buffer_size: 4096, // 4KB
|
max_buffer_size: 4096, // 4KB
|
||||||
is_saved: false,
|
is_saved: false,
|
||||||
item_id: None,
|
item_id: None,
|
||||||
output_names: std::collections::HashMap::new(),
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ impl BinaryMetaPlugin {
|
|||||||
let value = if is_binary_result { "true".to_string() } else { "false".to_string() };
|
let value = if is_binary_result { "true".to_string() } else { "false".to_string() };
|
||||||
|
|
||||||
// Save to database immediately using central output handler
|
// Save to database immediately using central output handler
|
||||||
let _ = output_metadata(conn, item_id, &self.meta_name, value, &self.output_names);
|
let _ = self.save_meta(conn, item_id, "binary", value);
|
||||||
|
|
||||||
self.is_saved = true;
|
self.is_saved = true;
|
||||||
}
|
}
|
||||||
@@ -93,8 +93,8 @@ impl MetaPlugin for BinaryMetaPlugin {
|
|||||||
if let Some(outputs) = options.get("outputs") {
|
if let Some(outputs) = options.get("outputs") {
|
||||||
if let Some(outputs_map) = outputs.as_mapping() {
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
for (key, value) in outputs_map {
|
for (key, value) in outputs_map {
|
||||||
if let (Some(key_str), Some(value_str)) = (key.as_str(), value.as_str()) {
|
if let Some(key_str) = key.as_str() {
|
||||||
self.output_names.insert(key_str.to_string(), value_str.to_string());
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,11 @@ impl MetaPlugin for BinaryMetaPlugin {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_output_name(&self, default_name: &str) -> String {
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
self.output_names.get(default_name).cloned().unwrap_or_else(|| default_name.to_string())
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ pub struct DigestSha256MetaPlugin {
|
|||||||
hasher: Sha256,
|
hasher: Sha256,
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
item_id: Option<i64>,
|
item_id: Option<i64>,
|
||||||
output_names: std::collections::HashMap<String, String>,
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DigestSha256MetaPlugin {
|
impl DigestSha256MetaPlugin {
|
||||||
@@ -19,7 +19,7 @@ impl DigestSha256MetaPlugin {
|
|||||||
hasher: Sha256::new(),
|
hasher: Sha256::new(),
|
||||||
meta_name: "digest_sha256".to_string(),
|
meta_name: "digest_sha256".to_string(),
|
||||||
item_id: None,
|
item_id: None,
|
||||||
output_names: std::collections::HashMap::new(),
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ impl MetaPlugin for DigestSha256MetaPlugin {
|
|||||||
let hex_string = format!("{:x}", hash_result);
|
let hex_string = format!("{:x}", hash_result);
|
||||||
|
|
||||||
// Save the hash as metadata using central output handler
|
// Save the hash as metadata using central output handler
|
||||||
let _ = output_metadata(conn, item_id, &self.meta_name, hex_string, &self.output_names);
|
let _ = self.save_meta(conn, item_id, "digest_sha256", hex_string);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -58,8 +58,8 @@ impl MetaPlugin for DigestSha256MetaPlugin {
|
|||||||
if let Some(outputs) = options.get("outputs") {
|
if let Some(outputs) = options.get("outputs") {
|
||||||
if let Some(outputs_map) = outputs.as_mapping() {
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
for (key, value) in outputs_map {
|
for (key, value) in outputs_map {
|
||||||
if let (Some(key_str), Some(value_str)) = (key.as_str(), value.as_str()) {
|
if let Some(key_str) = key.as_str() {
|
||||||
self.output_names.insert(key_str.to_string(), value_str.to_string());
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,8 +67,12 @@ impl MetaPlugin for DigestSha256MetaPlugin {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_output_name(&self, default_name: &str) -> String {
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
self.output_names.get(default_name).cloned().unwrap_or_else(|| default_name.to_string())
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +81,7 @@ impl MetaPlugin for DigestSha256MetaPlugin {
|
|||||||
pub struct ReadTimeMetaPlugin {
|
pub struct ReadTimeMetaPlugin {
|
||||||
start_time: Option<Instant>,
|
start_time: Option<Instant>,
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReadTimeMetaPlugin {
|
impl ReadTimeMetaPlugin {
|
||||||
@@ -84,6 +89,7 @@ impl ReadTimeMetaPlugin {
|
|||||||
ReadTimeMetaPlugin {
|
ReadTimeMetaPlugin {
|
||||||
start_time: None,
|
start_time: None,
|
||||||
meta_name: "read_time".to_string(),
|
meta_name: "read_time".to_string(),
|
||||||
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,6 +112,27 @@ impl MetaPlugin for ReadTimeMetaPlugin {
|
|||||||
fn meta_name(&mut self) -> String {
|
fn meta_name(&mut self) -> String {
|
||||||
self.meta_name.clone()
|
self.meta_name.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||||
|
if let Some(outputs) = options.get("outputs") {
|
||||||
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
|
for (key, value) in outputs_map {
|
||||||
|
if let Some(key_str) = key.as_str() {
|
||||||
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
@@ -113,6 +140,7 @@ pub struct ReadRateMetaPlugin {
|
|||||||
start_time: Option<Instant>,
|
start_time: Option<Instant>,
|
||||||
bytes_read: u64,
|
bytes_read: u64,
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReadRateMetaPlugin {
|
impl ReadRateMetaPlugin {
|
||||||
@@ -121,6 +149,7 @@ impl ReadRateMetaPlugin {
|
|||||||
start_time: None,
|
start_time: None,
|
||||||
bytes_read: 0,
|
bytes_read: 0,
|
||||||
meta_name: "read_rate".to_string(),
|
meta_name: "read_rate".to_string(),
|
||||||
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,4 +173,25 @@ impl MetaPlugin for ReadRateMetaPlugin {
|
|||||||
fn meta_name(&mut self) -> String {
|
fn meta_name(&mut self) -> String {
|
||||||
self.meta_name.clone()
|
self.meta_name.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||||
|
if let Some(outputs) = options.get("outputs") {
|
||||||
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
|
for (key, value) in outputs_map {
|
||||||
|
if let Some(key_str) = key.as_str() {
|
||||||
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ pub struct MagicFileMetaPlugin {
|
|||||||
is_saved: bool,
|
is_saved: bool,
|
||||||
item_id: Option<i64>,
|
item_id: Option<i64>,
|
||||||
cookie: Option<Cookie>,
|
cookie: Option<Cookie>,
|
||||||
output_names: std::collections::HashMap<String, String>,
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MagicFileMetaPlugin {
|
impl MagicFileMetaPlugin {
|
||||||
@@ -23,7 +23,7 @@ impl MagicFileMetaPlugin {
|
|||||||
is_saved: false,
|
is_saved: false,
|
||||||
item_id: None,
|
item_id: None,
|
||||||
cookie: None,
|
cookie: None,
|
||||||
output_names: std::collections::HashMap::new(),
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,10 +56,22 @@ impl MagicFileMetaPlugin {
|
|||||||
|
|
||||||
fn save_all_magic_metadata(&mut self, conn: &Connection) -> Result<()> {
|
fn save_all_magic_metadata(&mut self, conn: &Connection) -> Result<()> {
|
||||||
if let Some(item_id) = self.item_id {
|
if let Some(item_id) = self.item_id {
|
||||||
// Only save MIME type since that's what's mapped in the config
|
// Save all three magic outputs: mime_type, mime_encoding, and file_type
|
||||||
if let Ok(mime_type) = self.get_magic_result(CookieFlags::MIME_TYPE) {
|
if let Ok(mime_type) = self.get_magic_result(CookieFlags::MIME_TYPE) {
|
||||||
if !mime_type.is_empty() {
|
if !mime_type.is_empty() {
|
||||||
let _ = output_metadata(conn, item_id, "mime_type", mime_type, &self.output_names);
|
let _ = self.save_meta(conn, item_id, "mime_type", mime_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(mime_encoding) = self.get_magic_result(CookieFlags::MIME_ENCODING) {
|
||||||
|
if !mime_encoding.is_empty() {
|
||||||
|
let _ = self.save_meta(conn, item_id, "mime_encoding", mime_encoding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(file_type) = self.get_magic_result(CookieFlags::default()) {
|
||||||
|
if !file_type.is_empty() {
|
||||||
|
let _ = self.save_meta(conn, item_id, "file_type", file_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,8 +133,8 @@ impl MetaPlugin for MagicFileMetaPlugin {
|
|||||||
if let Some(outputs) = options.get("outputs") {
|
if let Some(outputs) = options.get("outputs") {
|
||||||
if let Some(outputs_map) = outputs.as_mapping() {
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
for (key, value) in outputs_map {
|
for (key, value) in outputs_map {
|
||||||
if let (Some(key_str), Some(value_str)) = (key.as_str(), value.as_str()) {
|
if let Some(key_str) = key.as_str() {
|
||||||
self.output_names.insert(key_str.to_string(), value_str.to_string());
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,8 +149,12 @@ impl MetaPlugin for MagicFileMetaPlugin {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_output_name(&self, default_name: &str) -> String {
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
self.output_names.get(default_name).cloned().unwrap_or_else(|| default_name.to_string())
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ pub struct MetaPluginProgram {
|
|||||||
writer: Option<Box<dyn Write>>,
|
writer: Option<Box<dyn Write>>,
|
||||||
item_id: Option<i64>,
|
item_id: Option<i64>,
|
||||||
result: Option<String>,
|
result: Option<String>,
|
||||||
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for MetaPluginProgram {
|
impl std::fmt::Debug for MetaPluginProgram {
|
||||||
@@ -29,6 +30,7 @@ impl std::fmt::Debug for MetaPluginProgram {
|
|||||||
.field("split_whitespace", &self.split_whitespace)
|
.field("split_whitespace", &self.split_whitespace)
|
||||||
.field("process", &self.process)
|
.field("process", &self.process)
|
||||||
.field("writer", &"Box<dyn Write>")
|
.field("writer", &"Box<dyn Write>")
|
||||||
|
.field("outputs", &self.outputs)
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,6 +50,7 @@ impl MetaPluginProgram {
|
|||||||
writer: None,
|
writer: None,
|
||||||
item_id: None,
|
item_id: None,
|
||||||
result: None,
|
result: None,
|
||||||
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,12 +118,7 @@ impl MetaPlugin for MetaPluginProgram {
|
|||||||
|
|
||||||
// Save the result to database if we have item_id
|
// Save the result to database if we have item_id
|
||||||
if let Some(item_id) = self.item_id {
|
if let Some(item_id) = self.item_id {
|
||||||
let meta = crate::db::Meta {
|
let _ = self.save_meta(conn, item_id, &self.meta_name.clone(), self.result.clone().unwrap());
|
||||||
id: item_id,
|
|
||||||
name: self.meta_name.clone(),
|
|
||||||
value: self.result.clone().unwrap(),
|
|
||||||
};
|
|
||||||
let _ = crate::db::store_meta(conn, meta);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -153,4 +151,25 @@ impl MetaPlugin for MetaPluginProgram {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||||
|
if let Some(outputs) = options.get("outputs") {
|
||||||
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
|
for (key, value) in outputs_map {
|
||||||
|
if let Some(key_str) = key.as_str() {
|
||||||
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use crate::meta_plugin::{MetaPlugin, output_metadata};
|
|||||||
pub struct CwdMetaPlugin {
|
pub struct CwdMetaPlugin {
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
is_saved: bool,
|
is_saved: bool,
|
||||||
output_names: std::collections::HashMap<String, String>,
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CwdMetaPlugin {
|
impl CwdMetaPlugin {
|
||||||
@@ -21,7 +21,7 @@ impl CwdMetaPlugin {
|
|||||||
CwdMetaPlugin {
|
CwdMetaPlugin {
|
||||||
meta_name: "cwd".to_string(),
|
meta_name: "cwd".to_string(),
|
||||||
is_saved: false,
|
is_saved: false,
|
||||||
output_names: std::collections::HashMap::new(),
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ impl MetaPlugin for CwdMetaPlugin {
|
|||||||
Err(_) => "unknown".to_string(),
|
Err(_) => "unknown".to_string(),
|
||||||
};
|
};
|
||||||
// Use central output handler
|
// Use central output handler
|
||||||
output_metadata(conn, item_id, &self.meta_name, cwd, &self.output_names)?;
|
self.save_meta(conn, item_id, "cwd", cwd)?;
|
||||||
self.is_saved = true;
|
self.is_saved = true;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -59,8 +59,8 @@ impl MetaPlugin for CwdMetaPlugin {
|
|||||||
if let Some(outputs) = options.get("outputs") {
|
if let Some(outputs) = options.get("outputs") {
|
||||||
if let Some(outputs_map) = outputs.as_mapping() {
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
for (key, value) in outputs_map {
|
for (key, value) in outputs_map {
|
||||||
if let (Some(key_str), Some(value_str)) = (key.as_str(), value.as_str()) {
|
if let Some(key_str) = key.as_str() {
|
||||||
self.output_names.insert(key_str.to_string(), value_str.to_string());
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,8 +68,12 @@ impl MetaPlugin for CwdMetaPlugin {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_output_name(&self, default_name: &str) -> String {
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
self.output_names.get(default_name).cloned().unwrap_or_else(|| default_name.to_string())
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +81,7 @@ impl MetaPlugin for CwdMetaPlugin {
|
|||||||
pub struct UidMetaPlugin {
|
pub struct UidMetaPlugin {
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
is_saved: bool,
|
is_saved: bool,
|
||||||
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UidMetaPlugin {
|
impl UidMetaPlugin {
|
||||||
@@ -84,6 +89,7 @@ impl UidMetaPlugin {
|
|||||||
UidMetaPlugin {
|
UidMetaPlugin {
|
||||||
meta_name: "uid".to_string(),
|
meta_name: "uid".to_string(),
|
||||||
is_saved: false,
|
is_saved: false,
|
||||||
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,16 +114,38 @@ impl MetaPlugin for UidMetaPlugin {
|
|||||||
|
|
||||||
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
||||||
let uid = get_current_uid().to_string();
|
let uid = get_current_uid().to_string();
|
||||||
self.save_meta(conn, item_id, uid)?;
|
self.save_meta(conn, item_id, "uid", uid)?;
|
||||||
self.is_saved = true;
|
self.is_saved = true;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||||
|
if let Some(outputs) = options.get("outputs") {
|
||||||
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
|
for (key, value) in outputs_map {
|
||||||
|
if let Some(key_str) = key.as_str() {
|
||||||
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct UserMetaPlugin {
|
pub struct UserMetaPlugin {
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
is_saved: bool,
|
is_saved: bool,
|
||||||
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserMetaPlugin {
|
impl UserMetaPlugin {
|
||||||
@@ -125,6 +153,7 @@ impl UserMetaPlugin {
|
|||||||
UserMetaPlugin {
|
UserMetaPlugin {
|
||||||
meta_name: "user".to_string(),
|
meta_name: "user".to_string(),
|
||||||
is_saved: false,
|
is_saved: false,
|
||||||
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,16 +181,38 @@ impl MetaPlugin for UserMetaPlugin {
|
|||||||
Some(username) => username.to_string_lossy().to_string(),
|
Some(username) => username.to_string_lossy().to_string(),
|
||||||
None => "unknown".to_string(),
|
None => "unknown".to_string(),
|
||||||
};
|
};
|
||||||
self.save_meta(conn, item_id, user)?;
|
self.save_meta(conn, item_id, "user", user)?;
|
||||||
self.is_saved = true;
|
self.is_saved = true;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||||
|
if let Some(outputs) = options.get("outputs") {
|
||||||
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
|
for (key, value) in outputs_map {
|
||||||
|
if let Some(key_str) = key.as_str() {
|
||||||
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct GidMetaPlugin {
|
pub struct GidMetaPlugin {
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
is_saved: bool,
|
is_saved: bool,
|
||||||
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GidMetaPlugin {
|
impl GidMetaPlugin {
|
||||||
@@ -169,6 +220,7 @@ impl GidMetaPlugin {
|
|||||||
GidMetaPlugin {
|
GidMetaPlugin {
|
||||||
meta_name: "gid".to_string(),
|
meta_name: "gid".to_string(),
|
||||||
is_saved: false,
|
is_saved: false,
|
||||||
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,16 +245,38 @@ impl MetaPlugin for GidMetaPlugin {
|
|||||||
|
|
||||||
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
||||||
let gid = get_current_gid().to_string();
|
let gid = get_current_gid().to_string();
|
||||||
self.save_meta(conn, item_id, gid)?;
|
self.save_meta(conn, item_id, "gid", gid)?;
|
||||||
self.is_saved = true;
|
self.is_saved = true;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||||
|
if let Some(outputs) = options.get("outputs") {
|
||||||
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
|
for (key, value) in outputs_map {
|
||||||
|
if let Some(key_str) = key.as_str() {
|
||||||
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct GroupMetaPlugin {
|
pub struct GroupMetaPlugin {
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
is_saved: bool,
|
is_saved: bool,
|
||||||
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GroupMetaPlugin {
|
impl GroupMetaPlugin {
|
||||||
@@ -210,6 +284,7 @@ impl GroupMetaPlugin {
|
|||||||
GroupMetaPlugin {
|
GroupMetaPlugin {
|
||||||
meta_name: "group".to_string(),
|
meta_name: "group".to_string(),
|
||||||
is_saved: false,
|
is_saved: false,
|
||||||
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,16 +312,38 @@ impl MetaPlugin for GroupMetaPlugin {
|
|||||||
Some(groupname) => groupname.to_string_lossy().to_string(),
|
Some(groupname) => groupname.to_string_lossy().to_string(),
|
||||||
None => "unknown".to_string(),
|
None => "unknown".to_string(),
|
||||||
};
|
};
|
||||||
self.save_meta(conn, item_id, group)?;
|
self.save_meta(conn, item_id, "group", group)?;
|
||||||
self.is_saved = true;
|
self.is_saved = true;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||||
|
if let Some(outputs) = options.get("outputs") {
|
||||||
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
|
for (key, value) in outputs_map {
|
||||||
|
if let Some(key_str) = key.as_str() {
|
||||||
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct ShellMetaPlugin {
|
pub struct ShellMetaPlugin {
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
is_saved: bool,
|
is_saved: bool,
|
||||||
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShellMetaPlugin {
|
impl ShellMetaPlugin {
|
||||||
@@ -254,6 +351,7 @@ impl ShellMetaPlugin {
|
|||||||
ShellMetaPlugin {
|
ShellMetaPlugin {
|
||||||
meta_name: "shell".to_string(),
|
meta_name: "shell".to_string(),
|
||||||
is_saved: false,
|
is_saved: false,
|
||||||
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,16 +379,38 @@ impl MetaPlugin for ShellMetaPlugin {
|
|||||||
Ok(shell) => shell,
|
Ok(shell) => shell,
|
||||||
Err(_) => "unknown".to_string(),
|
Err(_) => "unknown".to_string(),
|
||||||
};
|
};
|
||||||
self.save_meta(conn, item_id, shell)?;
|
self.save_meta(conn, item_id, "shell", shell)?;
|
||||||
self.is_saved = true;
|
self.is_saved = true;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||||
|
if let Some(outputs) = options.get("outputs") {
|
||||||
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
|
for (key, value) in outputs_map {
|
||||||
|
if let Some(key_str) = key.as_str() {
|
||||||
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct ShellPidMetaPlugin {
|
pub struct ShellPidMetaPlugin {
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
is_saved: bool,
|
is_saved: bool,
|
||||||
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShellPidMetaPlugin {
|
impl ShellPidMetaPlugin {
|
||||||
@@ -298,6 +418,7 @@ impl ShellPidMetaPlugin {
|
|||||||
ShellPidMetaPlugin {
|
ShellPidMetaPlugin {
|
||||||
meta_name: "shell_pid".to_string(),
|
meta_name: "shell_pid".to_string(),
|
||||||
is_saved: false,
|
is_saved: false,
|
||||||
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -325,16 +446,38 @@ impl MetaPlugin for ShellPidMetaPlugin {
|
|||||||
Ok(ppid) => ppid,
|
Ok(ppid) => ppid,
|
||||||
Err(_) => process::id().to_string(),
|
Err(_) => process::id().to_string(),
|
||||||
};
|
};
|
||||||
self.save_meta(conn, item_id, pid)?;
|
self.save_meta(conn, item_id, "shell_pid", pid)?;
|
||||||
self.is_saved = true;
|
self.is_saved = true;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||||
|
if let Some(outputs) = options.get("outputs") {
|
||||||
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
|
for (key, value) in outputs_map {
|
||||||
|
if let Some(key_str) = key.as_str() {
|
||||||
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct KeepPidMetaPlugin {
|
pub struct KeepPidMetaPlugin {
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
is_saved: bool,
|
is_saved: bool,
|
||||||
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeepPidMetaPlugin {
|
impl KeepPidMetaPlugin {
|
||||||
@@ -342,6 +485,7 @@ impl KeepPidMetaPlugin {
|
|||||||
KeepPidMetaPlugin {
|
KeepPidMetaPlugin {
|
||||||
meta_name: "keep_pid".to_string(),
|
meta_name: "keep_pid".to_string(),
|
||||||
is_saved: false,
|
is_saved: false,
|
||||||
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -366,16 +510,38 @@ impl MetaPlugin for KeepPidMetaPlugin {
|
|||||||
|
|
||||||
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
fn initialize(&mut self, conn: &Connection, item_id: i64) -> Result<()> {
|
||||||
let pid = process::id().to_string();
|
let pid = process::id().to_string();
|
||||||
self.save_meta(conn, item_id, pid)?;
|
self.save_meta(conn, item_id, "keep_pid", pid)?;
|
||||||
self.is_saved = true;
|
self.is_saved = true;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||||
|
if let Some(outputs) = options.get("outputs") {
|
||||||
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
|
for (key, value) in outputs_map {
|
||||||
|
if let Some(key_str) = key.as_str() {
|
||||||
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct HostnameMetaPlugin {
|
pub struct HostnameMetaPlugin {
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
is_saved: bool,
|
is_saved: bool,
|
||||||
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HostnameMetaPlugin {
|
impl HostnameMetaPlugin {
|
||||||
@@ -383,6 +549,7 @@ impl HostnameMetaPlugin {
|
|||||||
HostnameMetaPlugin {
|
HostnameMetaPlugin {
|
||||||
meta_name: "hostname".to_string(),
|
meta_name: "hostname".to_string(),
|
||||||
is_saved: false,
|
is_saved: false,
|
||||||
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -410,16 +577,38 @@ impl MetaPlugin for HostnameMetaPlugin {
|
|||||||
Ok(hostname) => hostname,
|
Ok(hostname) => hostname,
|
||||||
Err(_) => "unknown".to_string(),
|
Err(_) => "unknown".to_string(),
|
||||||
};
|
};
|
||||||
self.save_meta(conn, item_id, hostname)?;
|
self.save_meta(conn, item_id, "hostname", hostname)?;
|
||||||
self.is_saved = true;
|
self.is_saved = true;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||||
|
if let Some(outputs) = options.get("outputs") {
|
||||||
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
|
for (key, value) in outputs_map {
|
||||||
|
if let Some(key_str) = key.as_str() {
|
||||||
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct FullHostnameMetaPlugin {
|
pub struct FullHostnameMetaPlugin {
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
is_saved: bool,
|
is_saved: bool,
|
||||||
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FullHostnameMetaPlugin {
|
impl FullHostnameMetaPlugin {
|
||||||
@@ -427,6 +616,7 @@ impl FullHostnameMetaPlugin {
|
|||||||
FullHostnameMetaPlugin {
|
FullHostnameMetaPlugin {
|
||||||
meta_name: "full_hostname".to_string(),
|
meta_name: "full_hostname".to_string(),
|
||||||
is_saved: false,
|
is_saved: false,
|
||||||
|
outputs: std::collections::HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -472,8 +662,29 @@ impl MetaPlugin for FullHostnameMetaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
self.save_meta(conn, item_id, hostname)?;
|
self.save_meta(conn, item_id, "full_hostname", hostname)?;
|
||||||
self.is_saved = true;
|
self.is_saved = true;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||||
|
if let Some(outputs) = options.get("outputs") {
|
||||||
|
if let Some(outputs_map) = outputs.as_mapping() {
|
||||||
|
for (key, value) in outputs_map {
|
||||||
|
if let Some(key_str) = key.as_str() {
|
||||||
|
self.outputs.insert(key_str.to_string(), value.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||||
|
&self.outputs
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
|
||||||
|
self.outputs = outputs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,11 +42,19 @@ fn setup_compression_and_plugins(
|
|||||||
.map(|meta_plugin_type| crate::meta_plugin::get_meta_plugin(meta_plugin_type.clone()))
|
.map(|meta_plugin_type| crate::meta_plugin::get_meta_plugin(meta_plugin_type.clone()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Configure meta plugins with their options from settings
|
// Configure meta plugins with their options and outputs from settings
|
||||||
if let Some(meta_plugin_configs) = &settings.meta_plugins {
|
if let Some(meta_plugin_configs) = &settings.meta_plugins {
|
||||||
for meta_plugin in meta_plugins.iter_mut() {
|
for meta_plugin in meta_plugins.iter_mut() {
|
||||||
let plugin_name = meta_plugin.meta_name();
|
let plugin_name = meta_plugin.meta_name();
|
||||||
if let Some(config) = meta_plugin_configs.iter().find(|c| c.name == plugin_name) {
|
if let Some(config) = meta_plugin_configs.iter().find(|c| c.name == plugin_name) {
|
||||||
|
// Set outputs first
|
||||||
|
let mut outputs = std::collections::HashMap::new();
|
||||||
|
for (key, value) in &config.outputs {
|
||||||
|
outputs.insert(key.clone(), serde_yaml::Value::String(value.clone()));
|
||||||
|
}
|
||||||
|
meta_plugin.set_outputs(outputs);
|
||||||
|
|
||||||
|
// Then configure with options
|
||||||
if let Err(e) = meta_plugin.configure(&config.options) {
|
if let Err(e) = meta_plugin.configure(&config.options) {
|
||||||
eprintln!("Warning: Failed to configure meta plugin '{}': {}", plugin_name, e);
|
eprintln!("Warning: Failed to configure meta plugin '{}': {}", plugin_name, e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user