| 1341 | } |
| 1342 | |
| 1343 | async fn create_pilot_things_integration( |
| 1344 | &self, |
| 1345 | request: Request<api::CreatePilotThingsIntegrationRequest>, |
| 1346 | ) -> Result<Response<()>, Status> { |
| 1347 | let req_int = match &request.get_ref().integration { |
| 1348 | Some(v) => v, |
| 1349 | None => { |
| 1350 | return Err(Status::invalid_argument("integration is missing")); |
| 1351 | } |
| 1352 | }; |
| 1353 | let app_id = Uuid::from_str(&req_int.application_id).map_err(|e| e.status())?; |
| 1354 | |
| 1355 | self.validator |
| 1356 | .validate( |
| 1357 | request.extensions(), |
| 1358 | validator::ValidateApplicationAccess::new(validator::Flag::Update, app_id), |
| 1359 | ) |
| 1360 | .await?; |
| 1361 | |
| 1362 | let _ = application::create_integration(application::Integration { |
| 1363 | application_id: app_id.into(), |
| 1364 | kind: application::IntegrationKind::PilotThings, |
| 1365 | configuration: application::IntegrationConfiguration::PilotThings( |
| 1366 | application::PilotThingsConfiguration { |
| 1367 | server: req_int.server.clone(), |
| 1368 | token: req_int.token.clone(), |
| 1369 | }, |
| 1370 | ), |
| 1371 | ..Default::default() |
| 1372 | }) |
| 1373 | .await |
| 1374 | .map_err(|e| e.status())?; |
| 1375 | |
| 1376 | let mut resp = Response::new(()); |
| 1377 | resp.metadata_mut().insert( |
| 1378 | "x-log-application_id", |
| 1379 | req_int.application_id.parse().unwrap(), |
| 1380 | ); |
| 1381 | |
| 1382 | Ok(resp) |
| 1383 | } |
| 1384 | |
| 1385 | async fn get_pilot_things_integration( |
| 1386 | &self, |