Skip to main content

isothrum_runner/
options.rs

1//! What the embedder passes to an operation: the values and secrets its tools get, and its choices.
2
3use std::collections::BTreeMap;
4
5use crate::project::platform::Provider;
6use crate::secrets::Secrets;
7
8/// The options of one operation.
9#[derive(Debug, Clone, Default)]
10#[non_exhaustive]
11pub struct RunOptions {
12    /// The Vagrant provider (`vagrant up --provider`), for a Vagrant project.
13    pub provider: Option<Provider>,
14    /// Sensitive values every tool of the operation gets, as its format reads them
15    /// (each by its name; Terraform also gets it as `TF_VAR_<name>`): never stored, never written to a file, masked in every event.
16    /// Pass them to every operation.
17    pub secrets: Secrets,
18    /// What the embedder calls the place the run is on (a server or account id): recorded, so a
19    /// later operation asked for elsewhere is refused (`running_elsewhere`).
20    pub host_label: Option<String>,
21    /// How long the run may live from its `up`: recorded as its expiry ([`crate::RunRecord`]'s
22    /// `expires_at`), which the reaper reads ([`crate::Runner::expired`]).
23    pub lifetime: Option<std::time::Duration>,
24    /// Values every tool of the operation gets, by name, as its format reads them
25    /// (Compose's `${NAME}`, a Vagrantfile's `ENV`, Terraform's
26    /// `TF_VAR_NAME` too). Never stored: pass them to every operation.
27    pub env: BTreeMap<String, String>,
28    /// A status read only: each sensitive output's own value instead of `***`, for its caller
29    /// to use (an admin password a project gives back). Never in an event, never stored; a service
30    /// gives it only over its owner-only endpoint. Off by default.
31    pub reveal: bool,
32    /// The Docker context the run's `docker` calls go to (`docker --context <it>`), whatever the
33    /// current one is: given at `up` (or any later operation), recorded with the run, and used by
34    /// every later operation and read that gives none. None: the current context, as `docker`
35    /// picks it.
36    pub docker_context: Option<String>,
37    /// The journaled operation this one is: a row a service queued (`Tx::queue_operation`), which
38    /// the operation begins instead of journaling a new one.
39    pub operation: Option<crate::store::OperationId>,
40}
41
42impl RunOptions {
43    /// No value, no secret, nothing recorded about the place.
44    #[must_use]
45    pub fn new() -> RunOptions {
46        RunOptions::default()
47    }
48
49    /// Sets variable `name` to `value` for every tool of the operation.
50    #[must_use]
51    pub fn with_env(mut self, name: impl Into<String>, value: impl Into<String>) -> RunOptions {
52        self.env.insert(name.into(), value.into());
53        self
54    }
55
56    /// Gives the tools the sensitive values `secrets`.
57    #[must_use]
58    pub fn with_secrets(mut self, secrets: Secrets) -> RunOptions {
59        self.secrets = secrets;
60        self
61    }
62
63    /// Runs as the queued operation `id` of the home's journal ([`crate::store::Tx::queue_operation`]).
64    #[must_use]
65    pub fn with_operation(mut self, id: crate::store::OperationId) -> RunOptions {
66        self.operation = Some(id);
67        self
68    }
69
70    /// Records the place the run is on as `label`.
71    #[must_use]
72    pub fn with_host_label(mut self, label: impl Into<String>) -> RunOptions {
73        self.host_label = Some(label.into());
74        self
75    }
76
77    /// Runs with Vagrant provider `provider`.
78    #[must_use]
79    pub fn with_provider(mut self, provider: Provider) -> RunOptions {
80        self.provider = Some(provider);
81        self
82    }
83
84    /// Sends the run's `docker` calls to Docker context `context` ([`RunOptions::docker_context`]).
85    #[must_use]
86    pub fn with_docker_context(mut self, context: impl Into<String>) -> RunOptions {
87        self.docker_context = Some(context.into());
88        self
89    }
90
91    /// Lets the run live `lifetime` from its `up`.
92    #[must_use]
93    pub fn with_lifetime(mut self, lifetime: std::time::Duration) -> RunOptions {
94        self.lifetime = Some(lifetime);
95        self
96    }
97
98    /// A status read that gives the sensitive outputs' own values ([`RunOptions::reveal`]).
99    #[must_use]
100    pub fn with_reveal(mut self) -> RunOptions {
101        self.reveal = true;
102        self
103    }
104}