| 25 | #[tonic::async_trait] |
| 26 | impl ApplicationService for Application { |
| 27 | async fn create( |
| 28 | &self, |
| 29 | request: Request<api::CreateApplicationRequest>, |
| 30 | ) -> Result<Response<api::CreateApplicationResponse>, Status> { |
| 31 | let req_app = match &request.get_ref().application { |
| 32 | Some(v) => v, |
| 33 | None => { |
| 34 | return Err(Status::invalid_argument("application is missing")); |
| 35 | } |
| 36 | }; |
| 37 | let tenant_id = Uuid::from_str(&req_app.tenant_id).map_err(|e| e.status())?; |
| 38 | |
| 39 | self.validator |
| 40 | .validate( |
| 41 | request.extensions(), |
| 42 | validator::ValidateApplicationsAccess::new(validator::Flag::Create, tenant_id), |
| 43 | ) |
| 44 | .await?; |
| 45 | |
| 46 | let a = application::Application { |
| 47 | tenant_id: tenant_id.into(), |
| 48 | name: req_app.name.clone(), |
| 49 | description: req_app.description.clone(), |
| 50 | tags: fields::KeyValue::new(req_app.tags.clone()), |
| 51 | ..Default::default() |
| 52 | }; |
| 53 | |
| 54 | let a = application::create(a).await.map_err(|e| e.status())?; |
| 55 | |
| 56 | let mut resp = Response::new(api::CreateApplicationResponse { |
| 57 | id: a.id.to_string(), |
| 58 | }); |
| 59 | resp.metadata_mut() |
| 60 | .insert("x-log-application_id", a.id.to_string().parse().unwrap()); |
| 61 | |
| 62 | Ok(resp) |
| 63 | } |
| 64 | |
| 65 | async fn get( |
| 66 | &self, |