integrationos_domain/domain/connection/
mod.rs1pub mod api_model_config;
2pub mod connection_definition;
3pub mod connection_model_definition;
4pub mod connection_model_schema;
5pub mod connection_oauth_definition;
6
7use super::{
8 configuration::environment::Environment,
9 shared::{ownership::Ownership, record_metadata::RecordMetadata, settings::Settings},
10};
11use crate::id::Id;
12use serde::{Deserialize, Serialize};
13use serde_json::Value;
14use std::{hash::Hash, sync::Arc};
15use strum::{AsRefStr, Display, EnumString};
16
17fn key_default() -> Arc<str> {
18 String::new().into()
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
22#[serde(rename_all = "camelCase")]
23pub struct Connection {
24 #[serde(rename = "_id")]
25 pub id: Id,
26 pub platform_version: String,
27 pub connection_definition_id: Id,
28 pub r#type: ConnectionType,
29 #[serde(default = "key_default")]
30 pub key: Arc<str>,
31 pub group: String,
32 pub name: Option<String>,
33 pub environment: Environment,
34 pub platform: Arc<str>,
35 pub secrets_service_id: String,
36 pub event_access_id: Id,
37 pub access_key: String,
38 pub identity: Option<String>,
39 pub identity_type: Option<ConnectionIdentityType>,
40 pub settings: Settings,
41 pub throughput: Throughput,
42 pub ownership: Ownership,
43 #[serde(default)]
44 pub oauth: Option<OAuth>,
45 #[serde(flatten, default)]
46 pub record_metadata: RecordMetadata,
47}
48
49#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
50#[serde(rename_all = "camelCase")]
51#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
52pub enum ConnectionIdentityType {
53 Organization,
54 User,
55 Team,
56}
57
58#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
59#[serde(rename_all = "camelCase")]
60pub struct PublicConnection {
61 #[serde(rename = "_id")]
62 pub id: Id,
63 pub platform_version: String,
64 pub r#type: ConnectionType,
65 pub key: Arc<str>,
66 pub environment: Environment,
67 pub platform: Arc<str>,
68 pub identity: Option<String>,
69 pub identity_type: Option<ConnectionIdentityType>,
70 #[serde(flatten, default)]
71 pub record_metadata: RecordMetadata,
72}
73
74#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
75#[serde(rename_all = "camelCase")]
76pub struct SanitizedConnection {
77 #[serde(rename = "_id")]
78 pub id: Id,
79 pub platform_version: String,
80 pub connection_definition_id: Id,
81 pub r#type: ConnectionType,
82 pub key: Arc<str>,
83 pub group: String,
84 pub name: Option<String>,
85 pub environment: Environment,
86 pub platform: Arc<str>,
87 pub secrets_service_id: String,
88 pub event_access_id: Id,
89 pub identity: Option<String>,
90 pub identity_type: Option<ConnectionIdentityType>,
91 pub settings: Settings,
92 pub throughput: Throughput,
93 pub ownership: Ownership,
94 #[serde(default)]
95 pub oauth: Option<OAuth>,
96 #[serde(flatten, default)]
97 pub record_metadata: RecordMetadata,
98}
99
100impl SanitizedConnection {
101 pub fn to_value(&self) -> Value {
102 serde_json::to_value(self).unwrap_or(Value::Null)
103 }
104}
105
106impl Hash for Connection {
107 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
108 self.id.hash(state);
109 }
110}
111
112impl PartialEq for Connection {
113 fn eq(&self, other: &Self) -> bool {
114 self.id == other.id
115 }
116}
117
118impl Eq for Connection {}
119
120#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, AsRefStr, Default)]
121#[serde(rename_all = "camelCase")]
122#[strum(serialize_all = "camelCase")]
123pub enum OAuth {
124 Enabled {
125 connection_oauth_definition_id: Id,
126 expires_in: Option<i32>,
127 #[serde(default)]
128 expires_at: Option<i64>,
129 },
130 #[default]
131 Disabled,
132}
133
134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Display, AsRefStr)]
135#[serde(rename_all = "lowercase")]
136#[strum(serialize_all = "lowercase")]
137pub enum ConnectionType {
138 Api {},
139 DatabaseSql {},
140 DatabaseNoSql,
141 FileSystem,
142 Stream,
143 Custom,
144}
145
146#[derive(
147 Debug, Clone, Copy, Serialize, PartialEq, Eq, Deserialize, Display, AsRefStr, EnumString,
148)]
149#[serde(rename_all = "lowercase")]
150#[strum(serialize_all = "lowercase")]
151pub enum Platform {
152 RabbitMq,
153 Xero,
154 PostgreSql,
155 MySql,
156 MariaDb,
157 MsSql,
158 Stripe,
159 Sage,
160 Shopify,
161 Snowflake,
162}
163
164#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize)]
165#[serde(rename_all = "camelCase")]
166pub struct Throughput {
167 pub key: String,
168 pub limit: u64,
169}