Skip to main content

Client

Struct Client 

Source
pub struct Client<D = Docker> { /* private fields */ }
Expand description

The main entry point for interacting with local Atlas deployments.

Client provides a high-level interface for managing MongoDB Atlas local deployments through Docker. It serves as the primary abstraction layer between your application and the underlying Docker containers running Atlas services.

§Examples

See the module-level documentation for a complete example of creating a new client instance.

Implementations§

Source§

impl<D: DockerPullImage + DockerCreateContainer + DockerStartContainer + DockerInspectContainer + Send + Sync + 'static> Client<D>

Source

pub fn create_deployment( &self, deployment_options: CreateDeploymentOptions, ) -> CreateDeploymentProgress

Creates a local Atlas deployment.

Source§

impl<D: DockerStopContainer + DockerRemoveContainer + DockerInspectContainer> Client<D>

Source

pub async fn delete_deployment( &self, name: &str, ) -> Result<(), DeleteDeploymentError>

Deletes a local Atlas deployment.

Source§

impl<D: DockerInspectContainer + RunCommandInContainer> Client<D>

Source

pub async fn get_connection_string( &self, container_id_or_name: String, ) -> Result<String, GetConnectionStringError>

Source§

impl<D: DockerInspectContainer> Client<D>

Source

pub async fn get_deployment( &self, container_id_or_name: &str, ) -> Result<Deployment, GetDeploymentError>

Inspects a container.

§Arguments
  • container_id_or_name - The ID or name of the container to inspect.
Source§

impl<D: DockerInspectContainer + RunCommandInContainer> Client<D>

Source

pub async fn get_deployment_id( &self, cluster_id_or_name: &str, ) -> Result<String, GetDeploymentIdError>

Gets the Atlas deployment ID for a local Atlas deployment.

Source§

impl<D: DockerLogContainer> Client<D>

Source

pub async fn get_logs( &self, container_id_or_name: &str, options: Option<LogsOptions>, ) -> Result<Vec<LogOutput>, GetLogsError>

Gets the logs from a container.

§Arguments
  • container_id_or_name - The ID or name of the container to get logs from.
  • options - Optional logging options (e.g., tail, timestamps, etc.)
§Returns

A Result containing a vector of log entries from the container, or an error if the logs could not be retrieved.

§Examples

See the complete working example:

cargo run --example get_logs

Example code:

use anyhow::{Context, Result};
use atlas_local::{
    Client,
    models::{CreateDeploymentOptions, LogsOptions, Tail},
};
use bollard::Docker;

#[tokio::main]
async fn main() -> Result<()> {
    let docker = Docker::connect_with_defaults().context("connecting to docker")?;
    let client = Client::new(docker.clone());

    let deployment_options = CreateDeploymentOptions::default();
    let deployment = client
        .create_deployment(deployment_options)
        .await
        .context("creating deployment")?;

    // Configure log options
    let log_options = LogsOptions::builder()
        .stdout(true) // Include stdout
        .stderr(true) // Include stderr
        .tail(Tail::Number(100)) // Get last 100 lines
        .timestamps(true) // Include timestamps
        .build();

    // Get logs from the deployment
    let logs = client
        .get_logs(&deployment.container_id, Some(log_options))
        .await
        .context("getting logs")?;

    println!("Container logs:");
    for log in logs {
        // Use print! instead of println! because logs contain new line characters
        print!("{}", log);
    }

    Ok(())
}
Source§

impl<D: DockerListContainers + DockerInspectContainer> Client<D>

Source

pub async fn list_deployments( &self, ) -> Result<Vec<Deployment>, GetDeploymentError>

Lists all local Atlas deployments.

Source§

impl<D: DockerPauseContainer + DockerInspectContainer> Client<D>

Source

pub async fn pause_deployment( &self, name: &str, ) -> Result<(), PauseDeploymentError>

Pauses a local Atlas deployment.

Source§

impl<D: DockerPullImage> Client<D>

Source

pub async fn pull_image( &self, image: &str, tag: &str, ) -> Result<(), PullImageError>

Pulls the Atlas Local image.

§Arguments
  • image - The image to pull.
  • tag - The tag to pull.
Source§

impl<D: DockerStartContainer + DockerInspectContainer> Client<D>

Source

pub async fn start_deployment( &self, name: &str, ) -> Result<(), StartDeploymentError>

Starts a local Atlas deployment.

Source§

impl<D: DockerStopContainer + DockerInspectContainer> Client<D>

Source

pub async fn stop_deployment( &self, name: &str, ) -> Result<(), StopDeploymentError>

Stops a local Atlas deployment.

Source§

impl<D: DockerUnpauseContainer + DockerInspectContainer> Client<D>

Source

pub async fn unpause_deployment( &self, name: &str, ) -> Result<(), UnpauseDeploymentError>

Unpauses a local Atlas deployment.

Source§

impl<D: DockerInspectContainer> Client<D>

Source

pub async fn wait_for_healthy_deployment( &self, deployment_name: &str, options: WatchOptions, ) -> Result<(), WatchDeploymentError>

Waits for a deployment to become healthy.

This method polls the container’s health status until it becomes healthy, or until the timeout specified in the options is reached.

§Arguments
  • cluster_name - The name or ID of the container to watch
  • options - Configuration options including timeout duration
§Returns

Returns Ok(()) when the container becomes healthy, or an error if:

  • The container inspection fails
  • The container becomes unhealthy
  • The timeout is reached
§Examples
use atlas_local::models::WatchOptions;
use std::time::Duration;

let options = WatchOptions::builder()
    .timeout_duration(Duration::from_secs(300))
    .build();

client.wait_for_healthy_deployment("my-deployment", options).await?;
Source§

impl<D> Client<D>

Source

pub fn new(docker: D) -> Client<D>

Creates a new Atlas Local client with the default MongoDB adapter.

§Arguments
  • docker - A connected Docker client instance from the bollard crate
§Returns

A new Client instance ready to manage Atlas Local deployments.

§Examples

See the module-level documentation for usage examples.

Trait Implementations§

Source§

impl<D> Clone for Client<D>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<D> Freeze for Client<D>

§

impl<D> RefUnwindSafe for Client<D>
where D: RefUnwindSafe,

§

impl<D> Send for Client<D>
where D: Sync + Send,

§

impl<D> Sync for Client<D>
where D: Sync + Send,

§

impl<D> Unpin for Client<D>

§

impl<D> UnsafeUnpin for Client<D>

§

impl<D> UnwindSafe for Client<D>
where D: RefUnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,