Skip to content

Commit 2fa9f3d

Browse files
committed
chore: fix on_error_callback
1 parent 02c179c commit 2fa9f3d

File tree

8 files changed

+54
-112
lines changed

8 files changed

+54
-112
lines changed

integrationos-api/src/logic/connection.rs

+9-48
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ async fn test_connection(
118118
.await;
119119
}
120120

121+
if let Some(delay) = connection_config.test_delay_in_millis {
122+
tokio::time::sleep(Duration::from_millis(delay)).await
123+
}
124+
121125
let res = state
122126
.extractor_caller
123127
.execute_model_definition(
@@ -138,30 +142,8 @@ async fn test_connection(
138142
}
139143

140144
impl PublicExt<Connection> for CreateConnectionPayload {
141-
fn public(input: Connection) -> Value {
142-
SanitizedConnection {
143-
id: input.id,
144-
platform_version: input.platform_version,
145-
connection_definition_id: input.connection_definition_id,
146-
r#type: input.r#type,
147-
key: input.key,
148-
group: input.group,
149-
name: input.name,
150-
environment: input.environment,
151-
platform: input.platform,
152-
secrets_service_id: input.secrets_service_id,
153-
event_access_id: input.event_access_id,
154-
identity: input.identity,
155-
identity_type: input.identity_type,
156-
settings: input.settings,
157-
throughput: input.throughput,
158-
ownership: input.ownership,
159-
error: input.error,
160-
has_error: input.has_error,
161-
oauth: input.oauth,
162-
record_metadata: input.record_metadata,
163-
}
164-
.to_value()
145+
fn public(conn: Connection) -> Value {
146+
Into::<SanitizedConnection>::into(conn).to_value()
165147
}
166148
}
167149

@@ -303,7 +285,7 @@ pub async fn create_connection(
303285
error!("Error creating secret for connection: {:?}", e);
304286
})?;
305287

306-
let connection = Connection {
288+
let conn = Connection {
307289
id: connection_id,
308290
platform_version: connection_config.clone().platform_version,
309291
connection_definition_id: payload.connection_definition_id,
@@ -333,34 +315,13 @@ pub async fn create_connection(
333315
state
334316
.app_stores
335317
.connection
336-
.create_one(&connection)
318+
.create_one(&conn)
337319
.await
338320
.inspect_err(|e| {
339321
error!("Error creating connection: {:?}", e);
340322
})?;
341323

342-
Ok(Json(SanitizedConnection {
343-
id: connection.id,
344-
platform_version: connection.platform_version,
345-
connection_definition_id: connection.connection_definition_id,
346-
r#type: connection.r#type,
347-
key: connection.key,
348-
group: connection.group,
349-
name: connection.name,
350-
environment: connection.environment,
351-
platform: connection.platform,
352-
secrets_service_id: connection.secrets_service_id,
353-
event_access_id: connection.event_access_id,
354-
identity: connection.identity,
355-
identity_type: connection.identity_type,
356-
settings: connection.settings,
357-
throughput: connection.throughput,
358-
ownership: connection.ownership,
359-
has_error: connection.has_error,
360-
error: connection.error,
361-
oauth: connection.oauth,
362-
record_metadata: connection.record_metadata,
363-
}))
324+
Ok(Json(conn.into()))
364325
}
365326

366327
async fn generate_k8s_specs_and_secret(

integrationos-api/src/logic/connection_definition.rs

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub struct CreateRequest {
6464
pub settings: Settings,
6565
pub paths: Paths,
6666
pub test_connection: Option<Id>,
67+
pub test_delay_in_millis: Option<u64>,
6768
pub active: bool,
6869
#[serde(default)]
6970
pub markdown: Option<String>,
@@ -358,6 +359,7 @@ impl RequestExt for CreateRequest {
358359
paths: self.paths.clone(),
359360
settings: self.settings.clone(),
360361
hidden: false,
362+
test_delay_in_millis: self.test_delay_in_millis,
361363
record_metadata: RecordMetadata::default(),
362364
};
363365

integrationos-api/tests/standard/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ fn test_json_connection_definition() {
276276
},
277277
hidden: true,
278278
test_connection: Some(Id::test(IdPrefix::Connection)),
279+
test_delay_in_millis: None,
279280
record_metadata: RecordMetadata::test(),
280281
};
281282

integrationos-database/src/algebra/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub async fn on_error_callback(
2424
None,
2525
))?;
2626

27-
let path = format!("{base_path}/v1/database-connection-lost/{connection_id}");
27+
let path = format!("{base_path}/v1/event-callbacks/database-connection-lost/{connection_id}");
2828

2929
let authorization = Claims::from_secret(jwt_secret.as_str())?;
3030
let payload = ConnectionLostReason {

integrationos-database/src/algebra/storage.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,16 @@ impl Storage for PostgresDatabaseConnection {
3434
}
3535

3636
async fn probe(&self) -> Result<bool, IntegrationOSError> {
37-
self.execute_raw("SELECT 1").await.map(|_| true)
37+
let result = self.execute_raw("SELECT 1").await.map(|_| true);
38+
39+
if result == Ok(true) {
40+
result
41+
} else {
42+
Err(ApplicationError::bad_request(
43+
"Failed to probe database",
44+
None,
45+
))
46+
}
3847
}
3948
}
4049

integrationos-database/tests/http/signal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async fn test_kill_signal() -> Result<Unit, IntegrationOSError> {
2020
.create_async()
2121
.await;
2222

23-
let path = format!("/v1/database-connection-lost/{connection_id}");
23+
let path = format!("/v1/event-callbacks/database-connection-lost/{connection_id}");
2424
let body = ConnectionLostReason {
2525
reason: "Deserialization error: Failed to deserialize secret: error decoding response body"
2626
.to_string(),

integrationos-domain/src/domain/connection/connection_definition.rs

+3-61
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::{api_model_config::AuthMethod, ConnectionType};
2-
use crate::id::{prefix::IdPrefix, Id};
2+
use crate::id::Id;
33
use crate::prelude::shared::{record_metadata::RecordMetadata, settings::Settings};
44
use serde::{Deserialize, Serialize};
55
use strum::{self, AsRefStr, Display};
@@ -27,6 +27,8 @@ pub struct ConnectionDefinition {
2727
pub settings: Settings,
2828
pub hidden: bool,
2929
pub test_connection: Option<Id>,
30+
#[serde(default, skip_serializing_if = "Option::is_none")]
31+
pub test_delay_in_millis: Option<u64>,
3032
#[serde(flatten, default)]
3133
pub record_metadata: RecordMetadata,
3234
}
@@ -83,66 +85,6 @@ pub struct ModelSorting {
8385
}
8486

8587
impl ConnectionDefinition {
86-
pub fn new(
87-
name: String,
88-
description: String,
89-
platform: String,
90-
platform_version: String,
91-
category: String,
92-
image: String,
93-
tags: Vec<String>,
94-
) -> Self {
95-
let key = format!("api::{}::{}", platform, platform_version);
96-
97-
Self {
98-
id: Id::now(IdPrefix::ConnectionDefinition),
99-
platform_version,
100-
platform: platform.clone(),
101-
r#type: ConnectionDefinitionType::Api,
102-
status: ConnectionStatus::Beta,
103-
name: name.clone(),
104-
key,
105-
frontend: Frontend {
106-
spec: Spec {
107-
title: name.clone(),
108-
description: description.clone(),
109-
platform,
110-
category,
111-
image,
112-
tags,
113-
helper_link: None,
114-
markdown: None,
115-
},
116-
connection_form: ConnectionForm {
117-
name,
118-
description,
119-
form_data: vec![],
120-
},
121-
},
122-
test_connection: None,
123-
auth_secrets: vec![],
124-
auth_method: None,
125-
multi_env: false,
126-
paths: Paths {
127-
id: None,
128-
event: None,
129-
payload: None,
130-
timestamp: None,
131-
secret: None,
132-
signature: None,
133-
cursor: None,
134-
},
135-
settings: Settings {
136-
parse_webhook_body: false,
137-
show_secret: false,
138-
allow_custom_events: false,
139-
oauth: false,
140-
},
141-
hidden: true,
142-
record_metadata: RecordMetadata::default(),
143-
}
144-
}
145-
14688
pub fn to_connection_type(&self) -> super::ConnectionType {
14789
match self.r#type {
14890
ConnectionDefinitionType::Api => ConnectionType::Api {},

integrationos-domain/src/domain/connection/mod.rs

+27
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,33 @@ pub struct SanitizedConnection {
112112
pub record_metadata: RecordMetadata,
113113
}
114114

115+
impl From<Connection> for SanitizedConnection {
116+
fn from(conn: Connection) -> Self {
117+
Self {
118+
id: conn.id,
119+
platform_version: conn.platform_version,
120+
connection_definition_id: conn.connection_definition_id,
121+
r#type: conn.r#type,
122+
key: conn.key,
123+
group: conn.group,
124+
name: conn.name,
125+
environment: conn.environment,
126+
platform: conn.platform,
127+
secrets_service_id: conn.secrets_service_id,
128+
event_access_id: conn.event_access_id,
129+
identity: conn.identity,
130+
identity_type: conn.identity_type,
131+
settings: conn.settings,
132+
throughput: conn.throughput,
133+
ownership: conn.ownership,
134+
oauth: conn.oauth,
135+
has_error: conn.has_error,
136+
error: conn.error,
137+
record_metadata: conn.record_metadata,
138+
}
139+
}
140+
}
141+
115142
impl SanitizedConnection {
116143
pub fn to_value(&self) -> Value {
117144
serde_json::to_value(self).unwrap_or(Value::Null)

0 commit comments

Comments
 (0)