| 28 | #[tonic::async_trait] |
| 29 | impl FuotaService for Fuota { |
| 30 | async fn create_deployment( |
| 31 | &self, |
| 32 | request: Request<api::CreateFuotaDeploymentRequest>, |
| 33 | ) -> Result<Response<api::CreateFuotaDeploymentResponse>, Status> { |
| 34 | let req_dp = match &request.get_ref().deployment { |
| 35 | Some(v) => v, |
| 36 | None => { |
| 37 | return Err(Status::invalid_argument("deployment is missing")); |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | let app_id = Uuid::from_str(&req_dp.application_id).map_err(|e| e.status())?; |
| 42 | let dp_id = Uuid::from_str(&req_dp.device_profile_id).map_err(|e| e.status())?; |
| 43 | |
| 44 | self.validator |
| 45 | .validate( |
| 46 | request.extensions(), |
| 47 | validator::ValidateFuotaDeploymentsAccess::new( |
| 48 | validator::Flag::Create, |
| 49 | None, |
| 50 | Some(app_id), |
| 51 | ), |
| 52 | ) |
| 53 | .await?; |
| 54 | |
| 55 | let t = tenant::get_for_application_id(app_id) |
| 56 | .await |
| 57 | .map_err(|e| e.status())?; |
| 58 | |
| 59 | let mut dp = fuota::FuotaDeployment { |
| 60 | name: req_dp.name.clone(), |
| 61 | application_id: app_id.into(), |
| 62 | device_profile_id: dp_id.into(), |
| 63 | multicast_addr: get_random_dev_addr(&t.get_dev_addr_prefixes()), |
| 64 | multicast_key: get_random_aes_key(), |
| 65 | multicast_group_type: match req_dp.multicast_group_type() { |
| 66 | api::MulticastGroupType::ClassB => "B", |
| 67 | api::MulticastGroupType::ClassC => "C", |
| 68 | } |
| 69 | .to_string(), |
| 70 | multicast_class_c_scheduling_type: req_dp |
| 71 | .multicast_class_c_scheduling_type() |
| 72 | .from_proto(), |
| 73 | multicast_dr: req_dp.multicast_dr as i16, |
| 74 | multicast_class_b_ping_slot_periodicity: req_dp.multicast_class_b_ping_slot_periodicity |
| 75 | as i16, |
| 76 | multicast_frequency: req_dp.multicast_frequency as i64, |
| 77 | multicast_timeout: req_dp.multicast_timeout as i16, |
| 78 | unicast_max_retry_count: req_dp.unicast_max_retry_count as i16, |
| 79 | fragmentation_fragment_size: req_dp.fragmentation_fragment_size as i16, |
| 80 | fragmentation_redundancy_percentage: req_dp.fragmentation_redundancy_percentage as i16, |
| 81 | fragmentation_session_index: req_dp.fragmentation_session_index as i16, |
| 82 | fragmentation_matrix: req_dp.fragmentation_matrix as i16, |
| 83 | fragmentation_block_ack_delay: req_dp.fragmentation_block_ack_delay as i16, |
| 84 | fragmentation_descriptor: req_dp.fragmentation_descriptor.clone(), |
| 85 | request_fragmentation_session_status: req_dp |
| 86 | .request_fragmentation_session_status() |
| 87 | .from_proto(), |