1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
/* Copyright (c) Fortanix, Inc.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types, unused_qualifications)]

extern crate base64;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;

#[cfg(any(feature = "client"))]
#[macro_use]
extern crate hyper;
#[cfg(any(feature = "client"))]
#[macro_use]
extern crate url;


extern crate mime;
extern crate serde;
extern crate serde_json;

extern crate futures;
extern crate chrono;
extern crate uuid;

use futures::Stream;
use std::error;
use std::fmt;
use std::io::Error;

#[allow(unused_imports)]
use std::collections::HashMap;

#[cfg(feature = "client")]
mod mimetypes;

#[deprecated(note = "Import futures directly")]
pub use futures::Future;

pub const BASE_PATH: &'static str = "/v1";
pub const API_VERSION: &'static str = "1.0.0";

// Need to restore enum generation for multi-response request types

pub trait Api {
    type Error;


    /// Get result of the certificate issuance
    fn get_issue_certificate_response(&self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error>;

    /// Submit request for certificate issuance
    fn issue_certificate(&self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error>;



    /// Get Fortanix attestation for the application
    fn get_fortanix_attestation(&self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error>;

    /// Get Target Info for node provisioning enclave
    fn get_target_info(&self) -> Result<models::TargetInfo, Self::Error>;



    /// Get Agent Version
    fn get_agent_version(&self) -> Result<models::VersionResponse, Self::Error>;


}

pub trait ApiMut {
    type Error;


    /// Get result of the certificate issuance
    fn get_issue_certificate_response(&mut self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error>;

    /// Submit request for certificate issuance
    fn issue_certificate(&mut self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error>;



    /// Get Fortanix attestation for the application
    fn get_fortanix_attestation(&mut self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error>;

    /// Get Target Info for node provisioning enclave
    fn get_target_info(&mut self) -> Result<models::TargetInfo, Self::Error>;



    /// Get Agent Version
    fn get_agent_version(&mut self) -> Result<models::VersionResponse, Self::Error>;


}

impl<T, E> Api for T
where
T: CertificateApi<Error = E> + EnclaveApi<Error = E> + SystemApi<Error = E> + 
{
type Error = E;
    
        fn get_issue_certificate_response(&self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error> {
        self.get_issue_certificate_response(task_id, )
        }
    
        fn issue_certificate(&self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error> {
        self.issue_certificate(body, )
        }
    

    
        fn get_fortanix_attestation(&self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error> {
        self.get_fortanix_attestation(body, )
        }
    
        fn get_target_info(&self) -> Result<models::TargetInfo, Self::Error> {
        self.get_target_info()
        }
    

    
        fn get_agent_version(&self) -> Result<models::VersionResponse, Self::Error> {
        self.get_agent_version()
        }
    

}

impl<T, E> ApiMut for T
where
    T: CertificateApiMut<Error = E> + EnclaveApiMut<Error = E> + SystemApiMut<Error = E> + 
{
    type Error = E;




    fn get_issue_certificate_response(&mut self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error> {
        self.get_issue_certificate_response(task_id, )
    }

    fn issue_certificate(&mut self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error> {
        self.issue_certificate(body, )
    }



    fn get_fortanix_attestation(&mut self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error> {
        self.get_fortanix_attestation(body, )
    }

    fn get_target_info(&mut self) -> Result<models::TargetInfo, Self::Error> {
        self.get_target_info()
    }



    fn get_agent_version(&mut self) -> Result<models::VersionResponse, Self::Error> {
        self.get_agent_version()
    }


}

impl<T, E> Api for std::cell::RefCell<T>
where
    T: ApiMut<Error = E>,
{
    type Error = E;



    fn get_issue_certificate_response(&self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error> {
        self.borrow_mut().get_issue_certificate_response(task_id, )
    }

    fn issue_certificate(&self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error> {
        self.borrow_mut().issue_certificate(body, )
    }



    fn get_fortanix_attestation(&self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error> {
        self.borrow_mut().get_fortanix_attestation(body, )
    }

    fn get_target_info(&self) -> Result<models::TargetInfo, Self::Error> {
        self.borrow_mut().get_target_info()
    }



    fn get_agent_version(&self) -> Result<models::VersionResponse, Self::Error> {
        self.borrow_mut().get_agent_version()
    }


}

pub trait CertificateApi {
    type Error;


    /// Get result of the certificate issuance
    fn get_issue_certificate_response(&self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error>;

    /// Submit request for certificate issuance
    fn issue_certificate(&self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error>;

}

pub trait CertificateApiMut {
    type Error;


    /// Get result of the certificate issuance
    fn get_issue_certificate_response(&mut self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error>;

    /// Submit request for certificate issuance
    fn issue_certificate(&mut self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error>;

}

impl<T, E> CertificateApiMut for T
where
    T: CertificateApi<Error = E>,
{
    type Error = E;

    fn get_issue_certificate_response(&mut self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error> {
        <T as CertificateApi>::get_issue_certificate_response(self, task_id, )
    }

    fn issue_certificate(&mut self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error> {
        <T as CertificateApi>::issue_certificate(self, body, )
    }

}


pub trait EnclaveApi {
    type Error;


    /// Get Fortanix attestation for the application
    fn get_fortanix_attestation(&self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error>;

    /// Get Target Info for node provisioning enclave
    fn get_target_info(&self) -> Result<models::TargetInfo, Self::Error>;

}

pub trait EnclaveApiMut {
    type Error;


    /// Get Fortanix attestation for the application
    fn get_fortanix_attestation(&mut self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error>;

    /// Get Target Info for node provisioning enclave
    fn get_target_info(&mut self) -> Result<models::TargetInfo, Self::Error>;

}

impl<T, E> EnclaveApiMut for T
where
    T: EnclaveApi<Error = E>,
{
    type Error = E;

    fn get_fortanix_attestation(&mut self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error> {
        <T as EnclaveApi>::get_fortanix_attestation(self, body, )
    }

    fn get_target_info(&mut self) -> Result<models::TargetInfo, Self::Error> {
        <T as EnclaveApi>::get_target_info(self, )
    }

}


pub trait SystemApi {
    type Error;


    /// Get Agent Version
    fn get_agent_version(&self) -> Result<models::VersionResponse, Self::Error>;

}

pub trait SystemApiMut {
    type Error;


    /// Get Agent Version
    fn get_agent_version(&mut self) -> Result<models::VersionResponse, Self::Error>;

}

impl<T, E> SystemApiMut for T
where
    T: SystemApi<Error = E>,
{
    type Error = E;

    fn get_agent_version(&mut self) -> Result<models::VersionResponse, Self::Error> {
        <T as SystemApi>::get_agent_version(self, )
    }

}



#[cfg(feature = "client")]
pub mod client;

// Re-export Client as a top-level name
#[cfg(feature = "client")]
pub use self::client::Client;

pub mod models;

pub mod base64_format {
    // This module from swagger-rs

    use base64::{decode, encode};
    use serde::de::{Deserialize, Deserializer, Error};
    use serde::ser::{Serialize, Serializer};
    use std::ops::{Deref, DerefMut};

    #[derive(Debug, Clone, PartialEq, PartialOrd)]
    /// Base64-encoded byte array
    pub struct ByteArray(pub Vec<u8>);

    impl Serialize for ByteArray {
        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
        where
            S: Serializer,
        {
            serializer.serialize_str(&encode(&self.0))
        }
    }

    impl<'de> Deserialize<'de> for ByteArray {
        fn deserialize<D>(deserializer: D) -> Result<ByteArray, D::Error>
        where
            D: Deserializer<'de>,
        {
            let s = String::deserialize(deserializer)?;
            match decode(&s) {
                Ok(bin) => Ok(ByteArray(bin)),
                _ => Err(D::Error::custom("invalid base64")),
            }
        }
    }

    impl Deref for ByteArray {
        type Target = Vec<u8>;
        fn deref(&self) -> &Vec<u8> {
            &self.0
        }
    }

    impl DerefMut for ByteArray {
        fn deref_mut(&mut self) -> &mut Vec<u8> {
            &mut self.0
        }
    }

    impl AsRef<[u8]> for ByteArray {
        fn as_ref(&self) -> &[u8] {
            &self.0
        }
    }
}
pub use base64_format::ByteArray;


/// Very simple error type - just holds a description of the error. This is useful for human
/// diagnosis and troubleshooting, but not for applications to parse. The justification for this
/// is to deny applications visibility into the communication layer, forcing the application code
/// to act solely on the logical responses that the API provides, promoting abstraction in the
/// application code.
#[derive(Clone, Debug)]
pub struct ApiError(pub String);

impl fmt::Display for ApiError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let debug: &dyn fmt::Debug = self;
        debug.fmt(f)
    }
}

impl error::Error for ApiError {
    fn description(&self) -> &str {
        "Failed to produce a valid response."
    }
}

impl<'a> From<&'a str> for ApiError {
    fn from(e: &str) -> Self {
        ApiError(e.to_string())
    }
}

impl From<String> for ApiError {
    fn from(e: String) -> Self {
        ApiError(e)
    }
}

impl From<serde_json::Error> for ApiError {
    fn from(e: serde_json::Error) -> Self {
        ApiError(format!("Response body did not match the schema: {}", e))
    }
}