ValidatorContainer

Struct ValidatorContainer 

Source
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

Source

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 container
  • docker - Docker operations implementation (use BollardDocker for production)
Source

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.

Source

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.

Source

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.

Source

pub fn id(&self) -> &str

Get the container ID

Source

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.

Source

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.

Source

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.

Source

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” format
  • mount - 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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IntoResult<T> for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more