| 1487 | } |
| 1488 | |
| 1489 | async fn create_ifttt_integration( |
| 1490 | &self, |
| 1491 | request: Request<api::CreateIftttIntegrationRequest>, |
| 1492 | ) -> Result<Response<()>, Status> { |
| 1493 | let req_int = match &request.get_ref().integration { |
| 1494 | Some(v) => v, |
| 1495 | None => { |
| 1496 | return Err(Status::invalid_argument("integration is missing")); |
| 1497 | } |
| 1498 | }; |
| 1499 | let app_id = Uuid::from_str(&req_int.application_id).map_err(|e| e.status())?; |
| 1500 | |
| 1501 | self.validator |
| 1502 | .validate( |
| 1503 | request.extensions(), |
| 1504 | validator::ValidateApplicationAccess::new(validator::Flag::Update, app_id), |
| 1505 | ) |
| 1506 | .await?; |
| 1507 | |
| 1508 | if !req_int.event_prefix.is_empty() |
| 1509 | && !regex::Regex::new(r"^[a-zA-Z0-9]+$") |
| 1510 | .unwrap() |
| 1511 | .is_match(&req_int.event_prefix) |
| 1512 | { |
| 1513 | return Err(Status::invalid_argument( |
| 1514 | "event_prefix may only contain A-Z, a-z and 0-9 characters", |
| 1515 | )); |
| 1516 | } |
| 1517 | |
| 1518 | let _ = application::create_integration(application::Integration { |
| 1519 | application_id: app_id.into(), |
| 1520 | kind: application::IntegrationKind::Ifttt, |
| 1521 | configuration: application::IntegrationConfiguration::Ifttt( |
| 1522 | application::IftttConfiguration { |
| 1523 | key: req_int.key.clone(), |
| 1524 | uplink_values: [ |
| 1525 | req_int.uplink_values.first().cloned().unwrap_or_default(), |
| 1526 | req_int.uplink_values.get(1).cloned().unwrap_or_default(), |
| 1527 | ], |
| 1528 | arbitrary_json: req_int.arbitrary_json, |
| 1529 | event_prefix: req_int.event_prefix.clone(), |
| 1530 | }, |
| 1531 | ), |
| 1532 | ..Default::default() |
| 1533 | }) |
| 1534 | .await |
| 1535 | .map_err(|e| e.status())?; |
| 1536 | |
| 1537 | let mut resp = Response::new(()); |
| 1538 | resp.metadata_mut().insert( |
| 1539 | "x-log-application_id", |
| 1540 | req_int.application_id.parse().unwrap(), |
| 1541 | ); |
| 1542 | |
| 1543 | Ok(resp) |
| 1544 | } |
| 1545 | |
| 1546 | async fn get_ifttt_integration( |