(
&self,
request: Request<ResourceSpecification>,
)
| 36 | #[tonic::async_trait] |
| 37 | impl BicepExtension for BicepExtensionService { |
| 38 | async fn create_or_update( |
| 39 | &self, |
| 40 | request: Request<ResourceSpecification>, |
| 41 | ) -> Result<Response<LocalExtensibilityOperationResponse>, Status> { |
| 42 | let spec = request.into_inner(); |
| 43 | let resource_type = spec.r#type; |
| 44 | let version = spec.api_version; |
| 45 | let properties = spec.properties; |
| 46 | |
| 47 | tracing::debug!( |
| 48 | "{}", |
| 49 | t!( |
| 50 | "bicep.functionCalled", |
| 51 | function = "CreateOrUpdate", |
| 52 | resourceType = resource_type, |
| 53 | version = format!("{version:?}"), |
| 54 | properties = properties |
| 55 | ) |
| 56 | ); |
| 57 | |
| 58 | let type_name = FullyQualifiedTypeName::parse(&resource_type) |
| 59 | .map_err(|e| Status::invalid_argument(e.to_string()))?; |
| 60 | let version_req = version.as_deref() |
| 61 | .map(|v| ResourceVersionReq::parse(&format!("={v}"))) |
| 62 | .transpose() |
| 63 | .map_err(|e| Status::invalid_argument(e.to_string()))?; |
| 64 | |
| 65 | let mut dsc = DscManager::new(); |
| 66 | let Some(resource) = dsc |
| 67 | .find_resource(&DiscoveryFilter::new( |
| 68 | &type_name, |
| 69 | version_req, |
| 70 | None, |
| 71 | )) |
| 72 | .unwrap_or(None) |
| 73 | else { |
| 74 | return Err(Status::not_found( |
| 75 | t!("dscerror.resourceNotFound").to_string(), |
| 76 | )); |
| 77 | }; |
| 78 | |
| 79 | let SetResult::Resource(result) = resource |
| 80 | .set(&properties, false, &ExecutionKind::Actual) |
| 81 | .map_err(|e| Status::aborted(e.to_string()))? |
| 82 | else { |
| 83 | return Err(Status::unimplemented( |
| 84 | t!("dscerror.notSupported").to_string(), |
| 85 | )); |
| 86 | }; |
| 87 | |
| 88 | Ok(Response::new(LocalExtensibilityOperationResponse { |
| 89 | resource: Some(proto::Resource { |
| 90 | r#type: resource_type, |
| 91 | api_version: version, |
| 92 | identifiers: properties, |
| 93 | properties: result.after_state.to_string(), |
| 94 | status: None, |
| 95 | }), |
nothing calls this directly
no test coverage detected