| 1653 | } |
| 1654 | |
| 1655 | async fn create_blynk_integration( |
| 1656 | &self, |
| 1657 | request: Request<api::CreateBlynkIntegrationRequest>, |
| 1658 | ) -> Result<Response<()>, Status> { |
| 1659 | let req_int = match &request.get_ref().integration { |
| 1660 | Some(v) => v, |
| 1661 | None => { |
| 1662 | return Err(Status::invalid_argument("integration is missing")); |
| 1663 | } |
| 1664 | }; |
| 1665 | let app_id = Uuid::from_str(&req_int.application_id).map_err(|e| e.status())?; |
| 1666 | |
| 1667 | self.validator |
| 1668 | .validate( |
| 1669 | request.extensions(), |
| 1670 | validator::ValidateApplicationAccess::new(validator::Flag::Update, app_id), |
| 1671 | ) |
| 1672 | .await?; |
| 1673 | |
| 1674 | let _ = application::create_integration(application::Integration { |
| 1675 | application_id: app_id.into(), |
| 1676 | kind: application::IntegrationKind::Blynk, |
| 1677 | configuration: application::IntegrationConfiguration::Blynk( |
| 1678 | application::BlynkConfiguration { |
| 1679 | token: req_int.token.clone(), |
| 1680 | }, |
| 1681 | ), |
| 1682 | ..Default::default() |
| 1683 | }) |
| 1684 | .await |
| 1685 | .map_err(|e| e.status())?; |
| 1686 | |
| 1687 | let mut resp = Response::new(()); |
| 1688 | resp.metadata_mut().insert( |
| 1689 | "x-log-application_id", |
| 1690 | req_int.application_id.parse().unwrap(), |
| 1691 | ); |
| 1692 | |
| 1693 | Ok(resp) |
| 1694 | } |
| 1695 | |
| 1696 | async fn get_blynk_integration( |
| 1697 | &self, |