docker-client-async 0.1.0

A modern async/await Docker client written in Rust.
Documentation
/*
 * Copyright 2020 Damian Peckett <damian@pecke.tt>.
 * Copyright 2013-2018 Docker, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

use derive_builder::Builder;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// MountPoint is the intersection point between a volume and a container. It
/// specifies which volume is to be used and where inside a container it should
/// be mounted.
///
/// Note that this type is embedded in `container.Container` object and persisted to disk.
/// Changes to this struct need to by synced with on disk state.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
#[builder(default, setter(into))]
pub struct MountPoint {
    /// Source is the source path of the mount.
    /// E.g. `mount --bind /foo /bar`, `/foo` is the `Source`.
    #[serde(rename = "Source")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source: Option<String>,
    /// Destination is the path relative to the container root (`/`) to the mount point
    /// It is where the `Source` is mounted to.
    #[serde(rename = "Destination")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub destination: Option<String>,
    /// RW is set to true when the mountpoint should be mounted as read-write.
    #[serde(rename = "RW")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rw: Option<bool>,
    /// Name is the name reference to the underlying data defined by `Source`
    /// e.g., the volume name.
    #[serde(rename = "Name")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Driver is the volume driver used to create the volume (if it is a volume).
    #[serde(rename = "Driver")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub driver: Option<String>,
    // Type of mount to use, see `Type<foo>` definitions in github.com/docker/docker/api/types/mount.
    #[serde(rename = "Type")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mount_type: Option<MountType>,
    /// mode is the comma separated list of options supplied by the user when creating
    /// the bind/volume mount.
    /// Note mode is not used on Windows
    #[serde(rename = "Mode", alias = "Relabel")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mode: Option<String>,
    /// Propagation describes how the mounts are propagated from the host into the
    /// mount point, and vice-versa.
    /// See https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt
    /// Note Propagation is not used on Windows
    #[serde(rename = "Propagation")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub propagation: Option<MountPropagation>,
    /// ID is the opaque ID used to pass to the volume driver.
    /// This should be set by calls to `Mount` and unset by calls to `Unmount`
    #[serde(rename = "ID")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<String>,
    /// Spec is a copy of the API request that created this mount.
    #[serde(rename = "Spec")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub spec: Option<Mount>,
    /// Some bind mounts should not be automatically created.
    /// (Some are auto-created for backwards-compatibility)
    /// This is checked on the API but setting this here prevents race conditions.
    /// where a bind dir existed during validation was removed before reaching the setup code.
    #[serde(rename = "SkipMountpointCreation")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub skip_mountpoint_creation: Option<bool>,
    /// Track usage of this mountpoint
    /// Specifically needed for containers which are running and calls to `docker cp`
    /// because both these actions require mounting the volumes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub active: Option<i32>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum MountType {
    /// TypeBind is the type for mounting host dir.
    #[serde(rename = "bind")]
    TypeBind,
    /// TypeVolume is the type for remote storage volumes.
    #[serde(rename = "volume")]
    TypeVolume,
    /// TypeTmpfs is the type for mounting tmpfs.
    #[serde(rename = "tmpfs")]
    TypeTmpfs,
    /// TypeNamedPipe is the type for mounting Windows named pipes.
    #[serde(rename = "npipe")]
    TypeNamedPipe,
}

/// Propagation represents the propagation of a mount.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum MountPropagation {
    /// PropagationRPrivate RPRIVATE.
    #[serde(rename = "rprivate")]
    PropagationRPrivate,
    /// PropagationPrivate PRIVATE.
    #[serde(rename = "private")]
    PropagationPrivate,
    /// PropagationRShared RSHARED.
    #[serde(rename = "rshared")]
    PropagationRShared,
    /// PropagationShared SHARED.
    #[serde(rename = "shared")]
    PropagationShared,
    /// PropagationRSlave RSLAVE.
    #[serde(rename = "rslave")]
    PropagationRSlave,
    /// PropagationSlave SLAVE.
    #[serde(rename = "slave")]
    PropagationSlave,
}

/// Mount represents a mount (volume).
#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
#[builder(default, setter(into))]
pub struct Mount {
    #[serde(rename = "Type")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mount_type: Option<MountType>,
    /// source specifies the name of the mount. Depending on mount type, this
    /// may be a volume name or a host path, or even ignored.
    /// Source is not supported for tmpfs (must be an empty value).
    #[serde(rename = "Source")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source: Option<String>,
    #[serde(rename = "Target")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub target: Option<String>,
    #[serde(rename = "ReadOnly")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub read_only: Option<bool>,
    #[serde(rename = "Consistency")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub consistency: Option<MountConsistency>,
    #[serde(rename = "BindOptions")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bind_options: Option<MountBindOptions>,
    #[serde(rename = "VolumeOptions")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub volume_options: Option<MountVolumeOptions>,
    #[serde(rename = "TmpfsOptions")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tmpfs_options: Option<MountTmpfsOptions>,
}

/// MountConsistency represents the consistency requirements of a mount.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum MountConsistency {
    /// ConsistencyFull guarantees bind mount-like consistency.
    #[serde(rename = "consistent")]
    ConsistencyFull,
    /// ConsistencyCached mounts can cache read data and FS structure.
    #[serde(rename = "cached")]
    ConsistencyCached,
    /// ConsistencyDelegated mounts can cache read and written data and structure.
    #[serde(rename = "delegated")]
    ConsistencyDelegated,
    /// ConsistencyDefault provides "consistent" behavior unless overridden.
    #[serde(rename = "default")]
    ConsistencyDefault,
}

/// MountBindOptions defines options specific to mounts of type "bind".
#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
#[builder(default, setter(into))]
pub struct MountBindOptions {
    #[serde(rename = "Propagation")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub propagation: Option<MountPropagation>,
    #[serde(rename = "NonRecursive")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub non_recursive: Option<bool>,
}

/// MountVolumeOptions represents the options for a mount of type volume.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
#[builder(default, setter(into))]
pub struct MountVolumeOptions {
    #[serde(rename = "NoCopy")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub no_copy: Option<bool>,
    #[serde(rename = "Labels")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub labels: Option<HashMap<String, String>>,
    #[serde(rename = "DriverConfig")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub driver_config: Option<MountDriver>,
}

/// MountDriver represents a volume driver.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
#[builder(default, setter(into))]
pub struct MountDriver {
    #[serde(rename = "Name")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    #[serde(rename = "Options")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub options: Option<HashMap<String, String>>,
}

/// MountTmpfsOptions defines options specific to mounts of type "tmpfs".
#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
#[builder(default, setter(into))]
pub struct MountTmpfsOptions {
    /// Size sets the size of the tmpfs, in bytes.
    ///
    /// This will be converted to an operating system specific value
    /// depending on the host. For example, on linux, it will be converted to
    /// use a 'k', 'm' or 'g' syntax. BSD, though not widely supported with
    /// docker, uses a straight byte value.
    ///
    /// Percentages are not supported.
    #[serde(rename = "SizeBytes")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub size_bytes: Option<i64>,
    /// Mode of the tmpfs upon creation.
    #[serde(rename = "Mode")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mode: Option<u32>,
}