Skip to main content

spin_manifest/schema/v2/
target_env.rs

1use std::path::PathBuf;
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6/// Identifies a deployment target.
7#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
8#[serde(untagged, deny_unknown_fields)]
9pub enum TargetEnvironmentRef {
10    /// Environment definition doc reference e.g. `spin-up:3.2`, `my-host`. This is looked up
11    /// in the default environment catalogue (the `spin-environments` repo, `env` directory).
12    Catalogue(String),
13    /// An environment definition doc HTTP URL
14    Http {
15        /// The environment document URL e.g. `https://github.com/me/environments/blob/main/target-envs/spin-up.3.6.toml`.
16        url: String,
17    },
18    /// A local environment document file. This is expected to contain a serialised
19    /// EnvironmentDefinition in TOML format.
20    File {
21        /// The file path of the document.
22        path: PathBuf,
23    },
24}
25
26impl std::fmt::Display for TargetEnvironmentRef {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        match self {
29            Self::Catalogue(e) => e.fmt(f),
30            Self::Http { url } => url.fmt(f),
31            Self::File { path } => path.display().fmt(f),
32        }
33    }
34}