pub struct ValidatorContainer { /* private fields */ }Expand description
Manages validator container lifecycle
Starts an Alpine container with a validator script copied in, then executes the script with environment variables for validation data.
Implementations§
Source§impl ValidatorContainer
impl ValidatorContainer
Sourcepub fn with_docker(
container: ContainerAsync<GenericImage>,
docker: Arc<dyn DockerOperations>,
) -> Self
pub fn with_docker( container: ContainerAsync<GenericImage>, docker: Arc<dyn DockerOperations>, ) -> Self
Create a ValidatorContainer with a custom Docker operations implementation.
This constructor is primarily for testing error paths by injecting mock
Docker implementations. Production code should use start_with_image
or start_raw instead.
§Arguments
container- The testcontainers async containerdocker- Docker operations implementation (useBollardDockerfor production)
Sourcepub async fn start_with_image(
image: &str,
validator_script: &[u8],
) -> Result<Self>
pub async fn start_with_image( image: &str, validator_script: &[u8], ) -> Result<Self>
Start a new validator container with the given image and script.
The script is copied to /validate.sh inside the container.
Container uses sleep infinity to stay running for exec calls.
§Arguments
image- Docker image in “name:tag” format (e.g., “osquery/osquery:5.17.0-ubuntu22.04”)validator_script- Script content to copy to/validate.sh
§Errors
Returns error if Docker is not running or container fails to start.
Sourcepub async fn start(validator_script: &[u8]) -> Result<Self>
pub async fn start(validator_script: &[u8]) -> Result<Self>
Start a new validator container with the default Alpine image.
The script is copied to /validate.sh inside the container.
Container uses sleep infinity to stay running for exec calls.
§Errors
Returns error if Docker is not running or container fails to start.
Sourcepub async fn exec_with_env(
&self,
setup: Option<&str>,
content: &str,
assertions: Option<&str>,
expect: Option<&str>,
) -> Result<ValidationResult>
pub async fn exec_with_env( &self, setup: Option<&str>, content: &str, assertions: Option<&str>, expect: Option<&str>, ) -> Result<ValidationResult>
Execute validator with environment variables.
Environment variables:
VALIDATOR_CONTENT: The visible code content (always set)VALIDATOR_SETUP: Setup content (if present)VALIDATOR_ASSERTIONS: Assertion rules (if present)VALIDATOR_EXPECT: Expected output (if present)
§Errors
Returns error if exec creation or execution fails.
Sourcepub async fn exec_raw(&self, cmd: &[&str]) -> Result<ValidationResult>
pub async fn exec_raw(&self, cmd: &[&str]) -> Result<ValidationResult>
Execute a raw command in the container and return output.
This is a lower-level method than exec_with_env that runs arbitrary
commands without environment variables or script injection.
§Arguments
cmd- Command and arguments to execute (e.g.,&["sqlite3", "-json", "/tmp/db", "SELECT 1"])
§Errors
Returns error if exec creation or execution fails.
Sourcepub async fn exec_with_stdin(
&self,
cmd: &[&str],
stdin_content: &str,
) -> Result<ValidationResult>
pub async fn exec_with_stdin( &self, cmd: &[&str], stdin_content: &str, ) -> Result<ValidationResult>
Execute a command in the container with stdin content.
This passes content via stdin instead of shell interpolation, eliminating shell injection risks from special characters in the content.
§Arguments
cmd- Command and arguments to execute (e.g.,&["cat"])stdin_content- Content to pass via stdin
§Errors
Returns error if exec creation, stdin write, or execution fails.
Sourcepub async fn start_raw(image: &str) -> Result<Self>
pub async fn start_raw(image: &str) -> Result<Self>
Start a container without copying a validator script.
This is for the new architecture where validators run on the host, and containers only provide the tool (sqlite3, osquery, etc.).
§Arguments
image- Docker image in “name:tag” format
§Errors
Returns error if Docker is not running or container fails to start.
Sourcepub async fn start_raw_with_mount(
image: &str,
mount: Option<(&Path, &str)>,
) -> Result<Self>
pub async fn start_raw_with_mount( image: &str, mount: Option<(&Path, &str)>, ) -> Result<Self>
Start a container with an optional host directory mounted.
This is for the new architecture where validators run on the host, and containers only provide the tool (sqlite3, osquery, etc.).
§Arguments
image- Docker image in “name:tag” formatmount- Optional (host_path,container_path) tuple for bind mount
§Errors
Returns error if Docker is not running or container fails to start.
Auto Trait Implementations§
impl Freeze for ValidatorContainer
impl !RefUnwindSafe for ValidatorContainer
impl Send for ValidatorContainer
impl Sync for ValidatorContainer
impl Unpin for ValidatorContainer
impl !UnwindSafe for ValidatorContainer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more