ic_query/cloud_engine/model.rs
1//! Module: cloud_engine::model
2//!
3//! Responsibility: define stable CloudEngine report and source-data models.
4//! Does not own: live transport, source validation, CLI parsing, or text rendering.
5//! Boundary: preserves raw control-plane identities, prices, timestamps, and authority limits.
6
7use serde::{Deserialize, Serialize};
8use std::fmt;
9
10#[cfg(feature = "cloud-engine-host")]
11use super::CloudEngineSourceRequest;
12
13///
14/// CloudEngineReportContext
15///
16/// Provenance shared by direct CloudEngine control-plane reports.
17///
18
19#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
20pub struct CloudEngineReportContext {
21 /// Report schema version.
22 pub schema_version: u32,
23 /// Queried network identity.
24 pub network: String,
25 /// Authority represented by the report.
26 pub authority: String,
27 /// CloudEngine control-plane registry canister principal.
28 pub engine_canister_id: String,
29 /// UTC collection timestamp.
30 pub fetched_at: String,
31 /// Replica endpoint used for the queries.
32 pub source_endpoint: String,
33 /// Collector identity.
34 pub fetched_by: String,
35 /// Whether the application data was cryptographically certified.
36 pub certified: bool,
37 /// Whether sequential calls form one point-in-time view.
38 pub point_in_time_guaranteed: bool,
39 /// Number of native canister query calls represented by the report.
40 pub query_call_count: usize,
41}
42
43///
44/// CloudEngineOperatorReport
45///
46/// Public operator binding and settings for one CloudEngine Subnet.
47///
48
49#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
50pub struct CloudEngineOperatorReport {
51 /// Query and authority provenance.
52 #[serde(flatten)]
53 pub context: CloudEngineReportContext,
54 /// Canonical requested Subnet principal.
55 pub subnet_id: String,
56 /// Whether the control-plane registry returned an operator binding.
57 pub operator_binding_present: bool,
58 /// Per-engine operator canister principal when registered.
59 pub operator_canister_id: Option<String>,
60 /// Public engine-owner principal returned by the operator.
61 pub engine_owner: Option<String>,
62 /// Public platform-administrator principal returned by the operator.
63 pub platform_admin: Option<String>,
64 /// Public Caffeine integration setting; `None` means the setting is absent.
65 pub caffeine_enabled: Option<bool>,
66 /// Number of claimed domains, or `None` when the operator returned no domain field.
67 pub claimed_domain_count: Option<usize>,
68 /// Canonically ordered claimed custom-domain names.
69 pub claimed_domains: Option<Vec<String>>,
70}
71
72///
73/// CloudEngineNodeType
74///
75/// CloudEngine marketplace node class.
76///
77
78#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
79pub enum CloudEngineNodeType {
80 /// Type 4.1 node class.
81 #[serde(rename = "type4.1")]
82 Type4_1,
83 /// Type 4.2 node class.
84 #[serde(rename = "type4.2")]
85 Type4_2,
86 /// Type 4.3 node class.
87 #[serde(rename = "type4.3")]
88 Type4_3,
89 /// Type 4.4 node class.
90 #[serde(rename = "type4.4")]
91 Type4_4,
92 /// Type 4.5 node class.
93 #[serde(rename = "type4.5")]
94 Type4_5,
95}
96
97impl CloudEngineNodeType {
98 /// Stable CloudEngine marketplace label.
99 #[must_use]
100 pub const fn as_str(self) -> &'static str {
101 match self {
102 Self::Type4_1 => "type4.1",
103 Self::Type4_2 => "type4.2",
104 Self::Type4_3 => "type4.3",
105 Self::Type4_4 => "type4.4",
106 Self::Type4_5 => "type4.5",
107 }
108 }
109}
110
111impl fmt::Display for CloudEngineNodeType {
112 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
113 formatter.write_str(self.as_str())
114 }
115}
116
117///
118/// CloudEnginePriceRow
119///
120/// One public CloudEngine marketplace price override.
121///
122
123#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
124pub struct CloudEnginePriceRow {
125 /// Canonical flattened marketplace key.
126 pub key: String,
127 /// Node class priced by this row.
128 pub node_type: CloudEngineNodeType,
129 /// Optional Registry data-center identifier for a location-specific override.
130 pub data_center_id: Option<String>,
131 /// Optional provider principal for a provider-specific override.
132 pub provider_id: Option<String>,
133 /// Provider share in raw cycles per month.
134 pub net_cycles_per_month: String,
135 /// Customer charge in raw cycles per month, including the network fee.
136 pub gross_cycles_per_month: String,
137 /// Raw control-plane update timestamp in Unix nanoseconds.
138 pub updated_at_unix_nanos: i64,
139}
140
141///
142/// CloudEnginePricesReport
143///
144/// Bounded public CloudEngine marketplace fee and price report.
145///
146
147#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
148pub struct CloudEnginePricesReport {
149 /// Query and authority provenance.
150 #[serde(flatten)]
151 pub context: CloudEngineReportContext,
152 /// Network-fee fraction added to provider net prices.
153 pub network_fee: f64,
154 /// Number of returned marketplace rows.
155 pub price_count: usize,
156 /// Canonically ordered marketplace prices.
157 pub prices: Vec<CloudEnginePriceRow>,
158}
159
160///
161/// CloudEngineOperatorSourceData
162///
163/// Untrusted source result for one Subnet-to-operator lookup and public detail follow-up.
164///
165
166#[cfg(feature = "cloud-engine-host")]
167#[derive(Clone, Debug, Eq, PartialEq)]
168pub struct CloudEngineOperatorSourceData {
169 /// Source provenance echoed by the adapter.
170 pub source: CloudEngineSourceRequest,
171 /// Canonical Subnet principal looked up by the source.
172 pub subnet_id: String,
173 /// Per-engine operator canister principal when registered.
174 pub operator_canister_id: Option<String>,
175 /// Public engine-owner principal returned by the operator.
176 pub engine_owner: Option<String>,
177 /// Public platform-administrator principal returned by the operator.
178 pub platform_admin: Option<String>,
179 /// Public Caffeine setting returned by the operator.
180 pub caffeine_enabled: Option<bool>,
181 /// Claimed custom-domain names, or `None` when the field was absent.
182 pub claimed_domains: Option<Vec<String>>,
183 /// Exact number of native query calls made by the source.
184 pub query_call_count: usize,
185}
186
187///
188/// CloudEnginePricesSourceData
189///
190/// Untrusted source result for the public CloudEngine marketplace.
191///
192
193#[cfg(feature = "cloud-engine-host")]
194#[derive(Clone, Debug, PartialEq)]
195pub struct CloudEnginePricesSourceData {
196 /// Source provenance echoed by the adapter.
197 pub source: CloudEngineSourceRequest,
198 /// Raw network-fee fraction returned by the control-plane canister.
199 pub network_fee: f64,
200 /// Raw public marketplace rows.
201 pub prices: Vec<CloudEnginePriceRow>,
202 /// Exact number of native query calls made by the source.
203 pub query_call_count: usize,
204}