pub mod audit;
pub mod bundle;
pub mod config;
pub mod endpoint;
pub mod error;
pub mod headers;
pub mod policy;
pub mod process;
pub mod producer;
pub use audit::ExecAuditEvent;
pub use bundle::ExecBundle;
pub use config::{ArgPolicy, EnvPolicy, ExecGlobalConfig, ExecProfile, OutputMode, Sandbox};
pub use endpoint::ExecEndpoint;
pub use error::ExecError;
pub use producer::{ExecProducer, ExecResult};
use std::sync::Arc;
use async_trait::async_trait;
use camel_component_api::{CamelError, Component, ComponentContext, Endpoint};
pub struct ExecComponent {
config: Arc<ExecGlobalConfig>,
}
impl ExecComponent {
pub fn new(config: ExecGlobalConfig) -> Self {
Self {
config: Arc::new(config),
}
}
}
#[async_trait]
impl Component for ExecComponent {
fn scheme(&self) -> &str {
"exec"
}
fn create_endpoint(
&self,
uri: &str,
_ctx: &dyn ComponentContext,
) -> Result<Box<dyn Endpoint>, CamelError> {
let profile_name = uri.strip_prefix("exec:").ok_or_else(|| {
CamelError::InvalidUri(format!("exec uri must start with 'exec:': {uri}"))
})?;
let profile_name = profile_name
.split_once('?')
.map(|(p, _)| p)
.unwrap_or(profile_name)
.to_string();
if profile_name.is_empty() {
return Err(CamelError::InvalidUri("exec: profile name required".into()));
}
if self.config.profile(&profile_name).is_none() {
return Err(CamelError::EndpointCreationFailed(format!(
"exec profile {profile_name:?} not configured"
)));
}
Ok(Box::new(ExecEndpoint::new(
uri.to_string(),
profile_name,
Arc::clone(&self.config),
)))
}
}