use std::sync::Arc;
use crate::managed::ManagedConnector;
use crate::sink::Sink;
use crate::types::{ConnectorConfig, ConnectorError, SinkConnector};
#[derive(Debug, Clone)]
pub struct ConnectorComponentInfo {
pub connector_type: &'static str,
pub display_name: &'static str,
pub description: &'static str,
pub feature_flag: &'static str,
pub supports_source: bool,
pub supports_sink: bool,
pub supports_managed: bool,
pub config_params: &'static [ConfigParamInfo],
}
#[derive(Debug, Clone)]
pub struct ConfigParamInfo {
pub name: &'static str,
pub description: &'static str,
pub required: bool,
pub default_value: Option<&'static str>,
}
pub trait ConnectorFactory: Send + Sync {
fn info(&self) -> &ConnectorComponentInfo;
fn create_managed(
&self,
name: &str,
config: &ConnectorConfig,
) -> Result<Box<dyn ManagedConnector>, ConnectorError> {
let _ = (name, config);
Err(ConnectorError::NotAvailable(format!(
"Connector '{}' does not support managed mode",
self.info().connector_type
)))
}
fn create_sink_connector(
&self,
config: &ConnectorConfig,
) -> Result<Box<dyn SinkConnector>, ConnectorError> {
let _ = config;
Err(ConnectorError::NotAvailable(format!(
"Connector '{}' does not support sink connector mode",
self.info().connector_type
)))
}
fn create_engine_sink(
&self,
name: &str,
config: &ConnectorConfig,
topic_override: Option<&str>,
context_name: Option<&str>,
) -> Result<Arc<dyn Sink>, ConnectorError> {
let _ = (name, config, topic_override, context_name);
Err(ConnectorError::NotAvailable(format!(
"Connector '{}' does not support engine sink mode",
self.info().connector_type
)))
}
}
inventory::collect!(&'static dyn ConnectorFactory);
pub fn find_factory(connector_type: &str) -> Option<&'static dyn ConnectorFactory> {
inventory::iter::<&'static dyn ConnectorFactory>
.into_iter()
.copied()
.find(|f| f.info().connector_type == connector_type)
}
pub fn list_components() -> Vec<&'static ConnectorComponentInfo> {
inventory::iter::<&'static dyn ConnectorFactory>
.into_iter()
.map(|f| f.info())
.collect()
}