interop.rs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. use serde::{Deserialize, Serialize};
  2. #[derive(Clone, Debug, Serialize, Deserialize)]
  3. pub struct KeyValuePair {
  4. pub key: String,
  5. pub value: String,
  6. }
  7. #[derive(Debug, Deserialize)]
  8. pub enum FormDataValue {
  9. Text(String),
  10. File {
  11. filename: String,
  12. data: Vec<u8>,
  13. mime: String,
  14. },
  15. }
  16. #[derive(Debug, Deserialize)]
  17. pub struct FormDataEntry {
  18. pub key: String,
  19. pub value: FormDataValue,
  20. }
  21. #[derive(Debug, Deserialize)]
  22. pub enum BodyDef {
  23. Text(String),
  24. URLEncoded(Vec<KeyValuePair>),
  25. FormData(Vec<FormDataEntry>),
  26. }
  27. #[derive(Debug, Deserialize)]
  28. pub struct RequestWithMetadata {
  29. pub req_id: usize,
  30. pub method: String,
  31. pub endpoint: String,
  32. pub headers: Vec<KeyValuePair>,
  33. pub body: Option<BodyDef>,
  34. pub validate_certs: bool,
  35. pub root_cert_bundle_files: Vec<Vec<u8>>,
  36. pub client_cert: Option<ClientCertDef>,
  37. pub proxy: Option<ProxyConfig>,
  38. }
  39. impl RequestWithMetadata {
  40. pub fn new(
  41. req_id: usize,
  42. method: String,
  43. endpoint: String,
  44. headers: Vec<KeyValuePair>,
  45. body: Option<BodyDef>,
  46. validate_certs: bool,
  47. root_cert_bundle_files: Vec<Vec<u8>>,
  48. client_cert: Option<ClientCertDef>,
  49. proxy: Option<ProxyConfig>,
  50. ) -> Self {
  51. Self {
  52. req_id,
  53. method,
  54. endpoint,
  55. headers,
  56. body,
  57. validate_certs,
  58. root_cert_bundle_files,
  59. client_cert,
  60. proxy,
  61. }
  62. }
  63. }
  64. #[derive(Debug, Deserialize)]
  65. pub struct ProxyConfig {
  66. pub url: String,
  67. }
  68. #[derive(Debug, Deserialize)]
  69. pub enum ClientCertDef {
  70. PEMCert {
  71. certificate_pem: Vec<u8>,
  72. key_pem: Vec<u8>,
  73. },
  74. PFXCert {
  75. certificate_pfx: Vec<u8>,
  76. password: String,
  77. },
  78. }
  79. #[derive(Debug, Serialize)]
  80. pub struct ResponseWithMetadata {
  81. pub status: u16,
  82. pub status_text: String,
  83. pub headers: Vec<KeyValuePair>,
  84. pub data: Vec<u8>,
  85. pub time_start_ms: u128,
  86. pub time_end_ms: u128,
  87. }