Skip to content

Commit aa95b80

Browse files
authored
fix: client id should be optional (#324)
1 parent 9a072ce commit aa95b80

File tree

5 files changed

+9
-160
lines changed

5 files changed

+9
-160
lines changed

api/src/logic/connection_definition.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,10 @@ pub async fn get_available_connectors(
450450
"ownership.buildableId": user_event_access.ownership.id.to_string(),
451451
})
452452
.await
453-
.unwrap();
453+
.map_err(|e| {
454+
error!("Error reading from settings: {e}");
455+
e
456+
})?;
454457

455458
if let Some(settings) = settings {
456459
// Get platforms that are active and match the user's environment

api/tests/http/unified.rs

Lines changed: 0 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -369,160 +369,6 @@ async fn test_unified_api_create() {
369369
mock.assert_async().await;
370370
}
371371

372-
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
373-
async fn test_unified_metrics() {
374-
let mut server = TestServer::new(None).await;
375-
let (connection, _) = server.create_connection(Environment::Live).await;
376-
377-
let name = "Model".to_string();
378-
379-
let mock = create_connection_model_definition(
380-
&mut server,
381-
&connection,
382-
CrudMapping {
383-
action: CrudAction::Create,
384-
common_model_name: name.clone(),
385-
from_common_model: None,
386-
to_common_model: None,
387-
},
388-
)
389-
.await;
390-
391-
let payload: Value = Faker.fake();
392-
393-
let res = server
394-
.send_request_with_headers::<Value, Value>(
395-
&format!("v1/unified/{}", name.to_lowercase()),
396-
Method::POST,
397-
Some(&server.live_key),
398-
Some(&payload),
399-
Some(
400-
vec![
401-
(CONTENT_TYPE.to_string(), "application/json".to_string()),
402-
(
403-
"x-pica-connection-key".to_string(),
404-
connection.key.to_string(),
405-
),
406-
]
407-
.into_iter()
408-
.collect(),
409-
),
410-
)
411-
.await
412-
.expect("Failed to send request");
413-
414-
assert_eq!(res.code, StatusCode::OK);
415-
mock.assert_async().await;
416-
417-
tokio::time::sleep(Duration::from_millis(100)).await;
418-
419-
let res = server
420-
.send_request::<(), MetricResponse>("v1/metrics", Method::GET, Some(&server.live_key), None)
421-
.await
422-
.unwrap();
423-
424-
assert_eq!(res.data.count, 1);
425-
426-
let res = server
427-
.send_request_with_headers::<Value, Value>(
428-
&format!("v1/unified/{}", name.to_lowercase()),
429-
Method::POST,
430-
Some(&server.live_key),
431-
Some(&payload),
432-
Some(
433-
vec![
434-
(CONTENT_TYPE.to_string(), "application/json".to_string()),
435-
(
436-
"x-pica-connection-key".to_string(),
437-
connection.key.to_string(),
438-
),
439-
]
440-
.into_iter()
441-
.collect(),
442-
),
443-
)
444-
.await
445-
.unwrap();
446-
assert_eq!(res.code, StatusCode::OK);
447-
448-
tokio::time::sleep(Duration::from_millis(100)).await;
449-
450-
let res = server
451-
.send_request::<(), MetricResponse>(
452-
format!("v1/metrics/{}", connection.ownership.client_id).as_str(),
453-
Method::GET,
454-
Some(&server.live_key),
455-
None,
456-
)
457-
.await
458-
.unwrap();
459-
460-
assert_eq!(res.data.count, 2);
461-
462-
let date = Utc::now();
463-
let day = date.day();
464-
let month = date.month();
465-
let year = date.year();
466-
let daily_key = format!("{year}-{month:02}-{day:02}");
467-
let monthly_key = format!("{year}-{month:02}");
468-
469-
let res = server
470-
.send_request::<(), MetricResponse>(
471-
format!(
472-
"v1/metrics/{}?day={daily_key}",
473-
connection.ownership.client_id
474-
)
475-
.as_str(),
476-
Method::GET,
477-
Some(&server.live_key),
478-
None,
479-
)
480-
.await
481-
.unwrap();
482-
483-
assert_eq!(res.data.count, 2);
484-
485-
let res = server
486-
.send_request::<(), MetricResponse>(
487-
format!(
488-
"v1/metrics/{}?month={monthly_key}&apiType=unified",
489-
connection.ownership.client_id
490-
)
491-
.as_str(),
492-
Method::GET,
493-
Some(&server.live_key),
494-
None,
495-
)
496-
.await
497-
.unwrap();
498-
499-
assert_eq!(res.data.count, 2);
500-
501-
let res = server
502-
.send_request::<(), MetricResponse>(
503-
format!("v1/metrics?platform={}", connection.platform).as_str(),
504-
Method::GET,
505-
Some(&server.live_key),
506-
None,
507-
)
508-
.await
509-
.unwrap();
510-
511-
assert_eq!(res.data.count, 2);
512-
513-
let res = server
514-
.send_request::<(), MetricResponse>(
515-
"v1/metrics?apiType=passthrough",
516-
Method::GET,
517-
Some(&server.live_key),
518-
None,
519-
)
520-
.await
521-
.unwrap();
522-
523-
assert_eq!(res.data.count, 0);
524-
}
525-
526372
async fn create_connection_model_definition(
527373
server: &mut TestServer,
528374
connection: &SanitizedConnection,

api/tests/standard/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ fn test_json_connection() {
201201
error: None,
202202
ownership: Ownership {
203203
id: "owner-id".to_string().into(),
204-
client_id: "client-id".to_string(),
204+
client_id: Some("client-id".to_string()),
205205
organization_id: Some("organization-id".to_string()),
206206
project_id: Some("project-id".to_string()),
207207
user_id: Some("user-id".to_string()),

osentities/src/domain/event/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl Event {
115115
let buildable_id = access_key_data.id.to_owned();
116116
let ownership = Ownership {
117117
id: buildable_id.clone().into(),
118-
client_id: buildable_id.to_owned(),
118+
client_id: Some(buildable_id.to_owned()),
119119
organization_id: Some(buildable_id.to_owned()),
120120
project_id: Some(buildable_id.to_owned()),
121121
user_id: Some(buildable_id),
@@ -238,7 +238,7 @@ mod test {
238238
event.ownership,
239239
Ownership {
240240
id: ACCESS_KEY.data.id.to_owned().into(),
241-
client_id: ACCESS_KEY.data.id.to_owned(),
241+
client_id: Some(ACCESS_KEY.data.id.to_owned()),
242242
organization_id: Some(ACCESS_KEY.data.id.to_owned()),
243243
project_id: Some(ACCESS_KEY.data.id.to_owned()),
244244
user_id: Some(ACCESS_KEY.data.id.to_owned())

osentities/src/domain/shared/ownership.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub struct Ownership {
99
#[serde(rename = "buildableId")]
1010
#[cfg_attr(feature = "dummy", dummy(expr = "String::new().into()"))]
1111
pub id: Arc<str>,
12-
pub client_id: String,
12+
pub client_id: Option<String>,
1313
pub organization_id: Option<String>,
1414
pub project_id: Option<String>,
1515
pub user_id: Option<String>,
@@ -47,7 +47,7 @@ impl Ownership {
4747
pub fn new(id: String) -> Ownership {
4848
Self {
4949
id: id.clone().into(),
50-
client_id: id.clone(),
50+
client_id: Some(id.clone()),
5151
..Default::default()
5252
}
5353
}

0 commit comments

Comments
 (0)