em_node_agent_client/
models.rs

1/* Copyright (c) Fortanix, Inc.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#![allow(unused_imports, unused_qualifications, unused_extern_crates)]
7extern crate chrono;
8
9use serde::ser::Serializer;
10
11use std::collections::HashMap;
12use models;
13use std::string::ParseError;
14use uuid;
15
16
17#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
18#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
19pub struct AgentManagerAuthRequest {
20    /// Node IP
21    #[serde(rename = "node_ip")]
22    #[serde(skip_serializing_if="Option::is_none")]
23    pub node_ip: Option<String>,
24
25    /// Node Name
26    #[serde(rename = "node_name")]
27    #[serde(skip_serializing_if="Option::is_none")]
28    pub node_name: Option<String>,
29
30}
31
32impl AgentManagerAuthRequest {
33    pub fn new() -> AgentManagerAuthRequest {
34        AgentManagerAuthRequest {
35            node_ip: None,
36            node_name: None,
37        }
38    }
39}
40
41
42#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
43#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
44pub struct AgentManagerAuthResponse {
45    /// Access token for node
46    #[serde(rename = "access_token")]
47    #[serde(skip_serializing_if="Option::is_none")]
48    pub access_token: Option<String>,
49
50}
51
52impl AgentManagerAuthResponse {
53    pub fn new() -> AgentManagerAuthResponse {
54        AgentManagerAuthResponse {
55            access_token: None,
56        }
57    }
58}
59
60
61#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
62#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
63pub struct AppHeartbeatRequest {
64    /// Application Heartbeat csr
65    #[serde(rename = "csr")]
66    #[serde(skip_serializing_if="Option::is_none")]
67    pub csr: Option<String>,
68
69    /// Node Id for app
70    #[serde(rename = "node_id")]
71    #[serde(skip_serializing_if="Option::is_none")]
72    pub node_id: Option<uuid::Uuid>,
73
74}
75
76impl AppHeartbeatRequest {
77    pub fn new() -> AppHeartbeatRequest {
78        AppHeartbeatRequest {
79            csr: None,
80            node_id: None,
81        }
82    }
83}
84
85
86/// App Heartbeat Response
87#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
88#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
89pub struct AppHeartbeatResponse {
90    #[serde(rename = "status")]
91    #[serde(skip_serializing_if="Option::is_none")]
92    pub status: Option<models::ResponseStatus>,
93
94}
95
96impl AppHeartbeatResponse {
97    pub fn new() -> AppHeartbeatResponse {
98        AppHeartbeatResponse {
99            status: None,
100        }
101    }
102}
103
104
105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
106#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
107pub struct GetFortanixAttestationRequest {
108    /// Enclave Report bytes
109    #[serde(rename = "report")]
110    #[serde(skip_serializing_if="Option::is_none")]
111    pub report: Option<String>,
112
113    /// Fortanix attestation CSR
114    #[serde(rename = "attestation_csr")]
115    #[serde(skip_serializing_if="Option::is_none")]
116    pub attestation_csr: Option<String>,
117
118}
119
120impl GetFortanixAttestationRequest {
121    pub fn new() -> GetFortanixAttestationRequest {
122        GetFortanixAttestationRequest {
123            report: None,
124            attestation_csr: None,
125        }
126    }
127}
128
129
130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
131#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
132pub struct GetFortanixAttestationResponse {
133    /// Verified attestation certificate
134    #[serde(rename = "attestation_certificate")]
135    #[serde(skip_serializing_if="Option::is_none")]
136    pub attestation_certificate: Option<String>,
137
138    /// Node Certificate
139    #[serde(rename = "node_certificate")]
140    #[serde(skip_serializing_if="Option::is_none")]
141    pub node_certificate: Option<String>,
142
143    /// FQPE Report bytes
144    #[serde(rename = "fqpe_report")]
145    #[serde(skip_serializing_if="Option::is_none")]
146    pub fqpe_report: Option<String>,
147
148}
149
150impl GetFortanixAttestationResponse {
151    pub fn new() -> GetFortanixAttestationResponse {
152        GetFortanixAttestationResponse {
153            attestation_certificate: None,
154            node_certificate: None,
155            fqpe_report: None,
156        }
157    }
158}
159
160
161#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
162#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
163pub struct IssueCertificateRequest {
164    /// Application CSR
165    #[serde(rename = "csr")]
166    #[serde(skip_serializing_if="Option::is_none")]
167    pub csr: Option<String>,
168
169}
170
171impl IssueCertificateRequest {
172    pub fn new() -> IssueCertificateRequest {
173        IssueCertificateRequest {
174            csr: None,
175        }
176    }
177}
178
179
180#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
181#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
182pub struct IssueCertificateResponse {
183    /// Task Id
184    #[serde(rename = "task_id")]
185    #[serde(skip_serializing_if="Option::is_none")]
186    pub task_id: Option<uuid::Uuid>,
187
188    #[serde(rename = "task_status")]
189    #[serde(skip_serializing_if="Option::is_none")]
190    pub task_status: Option<models::TaskStatusType>,
191
192    /// App Certificate
193    #[serde(rename = "certificate")]
194    #[serde(skip_serializing_if="Option::is_none")]
195    pub certificate: Option<String>,
196
197}
198
199impl IssueCertificateResponse {
200    pub fn new() -> IssueCertificateResponse {
201        IssueCertificateResponse {
202            task_id: None,
203            task_status: None,
204            certificate: None,
205        }
206    }
207}
208
209
210/// Node local data
211#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
212#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
213pub struct NodeLocalData {
214    /// Node id
215    #[serde(rename = "node_id")]
216    #[serde(skip_serializing_if="Option::is_none")]
217    pub node_id: Option<uuid::Uuid>,
218
219    /// node certificate
220    #[serde(rename = "certificate")]
221    #[serde(skip_serializing_if="Option::is_none")]
222    pub certificate: Option<String>,
223
224}
225
226impl NodeLocalData {
227    pub fn new() -> NodeLocalData {
228        NodeLocalData {
229            node_id: None,
230            certificate: None,
231        }
232    }
233}
234
235
236/// Status string for a response
237/// Enumeration of values.
238/// Since this enum's variants do not hold data, we can easily define them them as `#[repr(C)]`
239/// which helps with FFI.
240#[allow(non_camel_case_types)]
241#[repr(C)]
242#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
243#[cfg_attr(feature = "conversion", derive(LabelledGenericEnum))]
244pub enum ResponseStatus { 
245    #[serde(rename = "OK")]
246    OK,
247    #[serde(rename = "NOT_OK")]
248    NOT_OK,
249}
250
251impl ::std::fmt::Display for ResponseStatus {
252    fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
253        match *self { 
254            ResponseStatus::OK => write!(f, "{}", "OK"),
255            ResponseStatus::NOT_OK => write!(f, "{}", "NOT_OK"),
256        }
257    }
258}
259
260impl ::std::str::FromStr for ResponseStatus {
261    type Err = ();
262    fn from_str(s: &str) -> Result<Self, Self::Err> {
263        match s {
264            "OK" => Ok(ResponseStatus::OK),
265            "NOT_OK" => Ok(ResponseStatus::NOT_OK),
266            _ => Err(()),
267        }
268    }
269}
270
271
272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
273#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
274pub struct TargetInfo {
275    /// Enclave Target Info
276    #[serde(rename = "targetInfo")]
277    #[serde(skip_serializing_if="Option::is_none")]
278    pub target_info: Option<String>,
279
280}
281
282impl TargetInfo {
283    pub fn new() -> TargetInfo {
284        TargetInfo {
285            target_info: None,
286        }
287    }
288}
289
290
291/// Status string for a task
292/// Enumeration of values.
293/// Since this enum's variants do not hold data, we can easily define them them as `#[repr(C)]`
294/// which helps with FFI.
295#[allow(non_camel_case_types)]
296#[repr(C)]
297#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
298#[cfg_attr(feature = "conversion", derive(LabelledGenericEnum))]
299pub enum TaskStatusType { 
300    #[serde(rename = "INPROGRESS")]
301    INPROGRESS,
302    #[serde(rename = "FAILED")]
303    FAILED,
304    #[serde(rename = "SUCCESS")]
305    SUCCESS,
306    #[serde(rename = "DENIED")]
307    DENIED,
308    #[serde(rename = "PENDING_WHITELIST")]
309    PENDING_WHITELIST,
310}
311
312impl ::std::fmt::Display for TaskStatusType {
313    fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
314        match *self { 
315            TaskStatusType::INPROGRESS => write!(f, "{}", "INPROGRESS"),
316            TaskStatusType::FAILED => write!(f, "{}", "FAILED"),
317            TaskStatusType::SUCCESS => write!(f, "{}", "SUCCESS"),
318            TaskStatusType::DENIED => write!(f, "{}", "DENIED"),
319            TaskStatusType::PENDING_WHITELIST => write!(f, "{}", "PENDING_WHITELIST"),
320        }
321    }
322}
323
324impl ::std::str::FromStr for TaskStatusType {
325    type Err = ();
326    fn from_str(s: &str) -> Result<Self, Self::Err> {
327        match s {
328            "INPROGRESS" => Ok(TaskStatusType::INPROGRESS),
329            "FAILED" => Ok(TaskStatusType::FAILED),
330            "SUCCESS" => Ok(TaskStatusType::SUCCESS),
331            "DENIED" => Ok(TaskStatusType::DENIED),
332            "PENDING_WHITELIST" => Ok(TaskStatusType::PENDING_WHITELIST),
333            _ => Err(()),
334        }
335    }
336}
337
338
339/// Agent Version
340#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
341#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
342pub struct VersionResponse {
343    /// Agent Version
344    #[serde(rename = "version")]
345    #[serde(skip_serializing_if="Option::is_none")]
346    pub version: Option<String>,
347
348}
349
350impl VersionResponse {
351    pub fn new() -> VersionResponse {
352        VersionResponse {
353            version: None,
354        }
355    }
356}
357