1use serde::{Deserialize, Serialize};
2
3use crate::stack::ResourceState;
4
5#[derive(Debug, Clone, Default, Deserialize, Serialize)]
6pub struct ConfigValue {
7 pub value: String,
8 pub secret: bool,
9}
10
11#[derive(Debug, Clone, Deserialize, Serialize)]
12#[serde(untagged)]
13pub enum RawConfigValue {
14 Plain(serde_yaml::Value),
15 Secret { secure: String },
16}
17
18#[derive(Debug, Clone, Default, Deserialize, Serialize)]
19pub struct StackSettings {
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub secrets_provider: Option<String>,
22 #[serde(skip_serializing_if = "Option::is_none")]
23 pub encrypted_key: Option<String>,
24 #[serde(skip_serializing_if = "Option::is_none")]
25 pub encryption_salt: Option<String>,
26 #[serde(skip_serializing_if = "Option::is_none")]
27 pub config: Option<std::collections::HashMap<String, RawConfigValue>>,
28
29 #[serde(flatten)]
30 pub additional: Option<std::collections::HashMap<String, serde_yaml::Value>>,
31}
32
33#[derive(Debug, Clone, Default, Deserialize)]
34pub struct TokenInformation {
35 pub name: String,
36 pub organization: Option<String>,
37 pub team: Option<String>,
38}
39
40#[derive(Debug, Clone, Default, Deserialize)]
41pub struct Whoami {
42 pub user: String,
43 pub url: Option<String>,
44 pub organizations: Option<Vec<String>>,
45 pub token_information: Option<TokenInformation>,
46}
47
48#[derive(Debug, Clone, Default, Deserialize)]
49pub struct StackRemoveOptions {
50 pub force: Option<bool>,
51 pub preserve_config: Option<bool>,
52}
53
54#[derive(Debug, Clone, Default, Deserialize)]
55pub struct StackListOptions {
56 pub all: Option<bool>,
57}
58
59#[derive(Debug, Clone, Default, Deserialize)]
60pub struct StackSummary {
61 pub name: String,
62 pub current: bool,
63 pub last_update: Option<String>,
64 pub update_in_progress: Option<bool>,
65 pub resource_count: Option<usize>,
66 pub url: Option<String>,
67}
68
69#[derive(Debug, Clone, Default, Deserialize, Serialize)]
70pub struct Deployment {
71 pub version: usize,
72 pub deployment: DeploymentDetails,
73}
74
75#[derive(Debug, Clone, Default, Deserialize, Serialize)]
76pub struct DeploymentDetails {
77 pub resources: Vec<ResourceState>,
78 #[serde(flatten)]
79 pub additional: Option<std::collections::HashMap<String, serde_json::Value>>,
80}
81
82#[derive(Debug, Clone, Default)]
83pub struct StackCreateOptions {
84 pub secrets_provider: Option<String>,
85 pub copy_config_from: Option<String>,
86}
87
88pub type ConfigMap = std::collections::HashMap<String, ConfigValue>;
89pub type OutputMap = std::collections::HashMap<String, serde_json::Value>;
90
91pub trait Workspace {
92 type Stack: super::stack::Stack;
93
94 fn whoami(&self) -> super::Result<Whoami>;
95 fn get_stack_config(&self, stack_name: &str) -> super::Result<StackSettings>;
96 fn set_stack_config(&self, stack_name: &str, config: StackSettings) -> super::Result<()>;
97 fn get_config(&self, stack_name: &str, key: &str, path: bool) -> super::Result<ConfigValue>;
98 fn set_config(
99 &self,
100 stack_name: &str,
101 key: &str,
102 path: bool,
103 value: ConfigValue,
104 ) -> super::Result<()>;
105 fn remove_config(&self, stack_name: &str, key: &str, path: bool) -> super::Result<()>;
106 fn create_stack(&self, name: &str, options: StackCreateOptions) -> super::Result<Self::Stack>;
107 fn select_stack(&self, name: &str) -> super::Result<Self::Stack>;
108 fn select_or_create_stack(
109 &self,
110 name: &str,
111 options: Option<StackCreateOptions>,
112 ) -> super::Result<Self::Stack>;
113 fn remove_stack(
114 &self,
115 stack_name: &str,
116 options: Option<StackRemoveOptions>,
117 ) -> super::Result<()>;
118 fn list_stacks(&self, options: Option<StackListOptions>) -> super::Result<Vec<StackSummary>>;
119 fn export_stack(&self, stack_name: &str) -> super::Result<Deployment>;
120 fn import_stack(&self, stack_name: &str, deployment: Deployment) -> super::Result<()>;
121 fn stack_outputs(&self, stack_name: &str) -> super::Result<OutputMap>;
122}