| 63 | } |
| 64 | |
| 65 | async fn get( |
| 66 | &self, |
| 67 | request: Request<api::GetApplicationRequest>, |
| 68 | ) -> Result<Response<api::GetApplicationResponse>, Status> { |
| 69 | let req = request.get_ref(); |
| 70 | let app_id = Uuid::from_str(&req.id).map_err(|e| e.status())?; |
| 71 | |
| 72 | self.validator |
| 73 | .validate( |
| 74 | request.extensions(), |
| 75 | validator::ValidateApplicationAccess::new(validator::Flag::Read, app_id), |
| 76 | ) |
| 77 | .await?; |
| 78 | |
| 79 | let a = application::get(&app_id).await.map_err(|e| e.status())?; |
| 80 | let measurement_keys = application::get_measurement_keys(&app_id) |
| 81 | .await |
| 82 | .map_err(|e| e.status())?; |
| 83 | |
| 84 | let mut resp = Response::new(api::GetApplicationResponse { |
| 85 | application: Some(api::Application { |
| 86 | id: a.id.to_string(), |
| 87 | tenant_id: a.tenant_id.to_string(), |
| 88 | name: a.name, |
| 89 | description: a.description, |
| 90 | tags: a.tags.into_hashmap(), |
| 91 | }), |
| 92 | created_at: Some(helpers::datetime_to_prost_timestamp(&a.created_at)), |
| 93 | updated_at: Some(helpers::datetime_to_prost_timestamp(&a.updated_at)), |
| 94 | measurement_keys, |
| 95 | }); |
| 96 | resp.metadata_mut() |
| 97 | .insert("x-log-application_id", req.id.parse().unwrap()); |
| 98 | |
| 99 | Ok(resp) |
| 100 | } |
| 101 | |
| 102 | async fn update( |
| 103 | &self, |