Skip to main content

greentic_setup/engine/
types.rs

1//! Core types for the setup engine.
2//!
3//! Contains request/config types used across the engine.
4
5use std::collections::BTreeSet;
6use std::path::PathBuf;
7
8use serde_json::{Map as JsonMap, Value};
9
10use crate::plan::{
11    AccessChangeSelection, PackDefaultSelection, PackRemoveSelection, RemoveTarget,
12    TenantSelection, UpdateOp,
13};
14use crate::platform_setup::{PlatformSetupAnswers, StaticRoutesPolicy, TelemetryAnswers};
15
16fn default_true() -> bool {
17    true
18}
19
20/// A declarative provider entry in the answers document.
21///
22/// Each entry maps to a `provider add` + `link-bundle` mutation during
23/// post-setup auto-deploy.
24#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
25#[serde(deny_unknown_fields)]
26pub struct ProviderEntry {
27    /// Provider kind (e.g. `telegram`, `slack`, `webex`).
28    pub kind: String,
29    /// Human-readable display name for the messaging endpoint.
30    #[serde(default)]
31    pub display_name: Option<String>,
32    /// Whether to link the provider to the deployed bundle.
33    /// Defaults to `true` — matching `provider add` interactive behaviour.
34    /// Set to `false` explicitly to register without linking.
35    #[serde(default = "default_true")]
36    pub link_bundle: bool,
37    /// Provider-specific setup answers (may contain secret values).
38    #[serde(default)]
39    pub answers: JsonMap<String, Value>,
40    /// Override the default provider instance id.
41    #[serde(default)]
42    pub provider_id: Option<String>,
43}
44
45/// Loaded answers from a JSON/YAML file.
46#[derive(Clone, Debug, Default)]
47pub struct LoadedAnswers {
48    pub tenant: Option<String>,
49    pub team: Option<String>,
50    pub env: Option<String>,
51    pub platform_setup: PlatformSetupAnswers,
52    pub setup_answers: JsonMap<String, Value>,
53    /// Declarative provider wiring — processed after bundle deploy.
54    pub providers: Vec<ProviderEntry>,
55}
56
57/// The request object that drives plan building.
58#[derive(Clone, Debug, Default)]
59pub struct SetupRequest {
60    pub bundle: PathBuf,
61    pub bundle_name: Option<String>,
62    pub pack_refs: Vec<String>,
63    pub tenants: Vec<TenantSelection>,
64    pub default_assignments: Vec<PackDefaultSelection>,
65    pub providers: Vec<String>,
66    pub update_ops: BTreeSet<UpdateOp>,
67    pub remove_targets: BTreeSet<RemoveTarget>,
68    pub packs_remove: Vec<PackRemoveSelection>,
69    pub providers_remove: Vec<String>,
70    pub tenants_remove: Vec<TenantSelection>,
71    pub access_changes: Vec<AccessChangeSelection>,
72    pub static_routes: StaticRoutesPolicy,
73    pub deployment_targets: Vec<crate::deployment_targets::DeploymentTargetRecord>,
74    pub tunnel: Option<crate::platform_setup::TunnelAnswers>,
75    pub telemetry: Option<TelemetryAnswers>,
76    pub setup_answers: serde_json::Map<String, serde_json::Value>,
77    /// Filter by provider domain (messaging, events, secrets, oauth).
78    pub domain_filter: Option<String>,
79    /// Number of parallel setup operations.
80    pub parallel: usize,
81    /// Backup existing config before setup.
82    pub backup: bool,
83    /// Skip secrets initialization.
84    pub skip_secrets_init: bool,
85    /// Continue on error (best effort).
86    pub best_effort: bool,
87}
88
89/// Configuration for the setup engine.
90pub struct SetupConfig {
91    pub tenant: String,
92    pub team: Option<String>,
93    pub env: String,
94    pub offline: bool,
95    pub verbose: bool,
96}