Skip to main content

isothrum_client/proto/
target.rs

1//! Which run a command acts on, and the runner's options it is run with, on the wire.
2
3use std::collections::BTreeMap;
4use std::fmt;
5use std::path::PathBuf;
6
7use isothrum_runner::{Format, Provider, RunName};
8use serde::{Deserialize, Serialize};
9
10/// Which run: its project's folder, absolute (the service doesn't share the client's working
11/// folder), the name to run it under (default: the folder's), and its format when the folder
12/// holds several (default: the one the runner recognizes there).
13#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
14pub struct Target {
15    /// The project's folder (a file in it means the folder).
16    pub path: PathBuf,
17    /// The run's name.
18    #[serde(default, skip_serializing_if = "Option::is_none")]
19    pub name: Option<RunName>,
20    /// The project's format, for a folder that holds several.
21    #[serde(default, skip_serializing_if = "Option::is_none")]
22    pub format: Option<Format>,
23}
24
25impl Target {
26    /// The project at `path`, under `name`, its format recognized.
27    #[must_use]
28    pub fn new(path: impl Into<PathBuf>, name: Option<RunName>) -> Target {
29        Target {
30            path: path.into(),
31            name,
32            format: None,
33        }
34    }
35
36    /// The same, as a project of `format`.
37    #[must_use]
38    pub fn with_format(mut self, format: Format) -> Target {
39        self.format = Some(format);
40        self
41    }
42}
43
44/// The runner's options of an operation, on the wire. Secret values travel only over the owner-only endpoint and are
45/// never stored or logged.
46#[derive(Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
47pub struct OpOptions {
48    /// The Vagrant provider, for a Vagrant project (a run keeps the one it started with).
49    #[serde(default, skip_serializing_if = "Option::is_none")]
50    pub provider: Option<Provider>,
51    /// Values every tool of the operation gets, by name, as its format reads them.
52    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
53    pub env: BTreeMap<String, String>,
54    /// Sensitive values, by name: as `env`, but masked in every event and never stored.
55    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
56    pub secrets: BTreeMap<String, String>,
57    /// What to call the place the run is on.
58    #[serde(default, skip_serializing_if = "Option::is_none")]
59    pub host_label: Option<String>,
60    /// The Docker context the run's `docker` calls go to: given at `up`, recorded with the run,
61    /// used by every later operation that gives none.
62    #[serde(default, skip_serializing_if = "Option::is_none")]
63    pub docker_context: Option<String>,
64    /// A status read only: each sensitive output's own value instead of `***`. The service gives
65    /// it only over its owner-only endpoint; it is never in an event, never stored. Off by default.
66    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
67    pub reveal: bool,
68}
69
70impl OpOptions {
71    /// Whether it gives nothing.
72    #[must_use]
73    pub fn is_empty(&self) -> bool {
74        *self == OpOptions::default()
75    }
76}
77
78impl fmt::Debug for OpOptions {
79    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
80        f.debug_struct("OpOptions")
81            .field("provider", &self.provider)
82            .field("env", &self.env)
83            .field("secrets", &self.secrets.keys().collect::<Vec<_>>())
84            .field("host_label", &self.host_label)
85            .field("docker_context", &self.docker_context)
86            .field("reveal", &self.reveal)
87            .finish()
88    }
89}