pub async fn execute(self) -> Result<Device, AzureError> {
        let device_id = self.device_id.ok_or_else(|| {
            AzureError::GenericErrorWithText("Field 'device_id' is not set".to_string())
        })?;

        let status = self.status.ok_or_else(|| {
            AzureError::GenericErrorWithText("Field 'status' is not set".to_string())
        })?;

        let authentication = self.authentication.ok_or_else(|| {
            AzureError::GenericErrorWithText("Field 'authentication' is not set".to_string())
        })?;

        let uri = format!(
            "https://{}.azure-devices.net/devices/{}?api-version={}",
            self.service_client.iothub_name, device_id, API_VERSION
        );

        let https = HttpsConnector::new();
        let client = Client::builder().build::<_, hyper::Body>(https);
        let mut request_builder = Request::builder()
            .uri(uri)
            .method(Method::PUT)
            .header("Authorization", &self.service_client.sas_token)
            .header("Content-Type", "application/json");

        let mut body = serde_json::json!({
            "authentication": authentication,
            "deviceId": device_id,
            "status": status,
            "capabilities": self.capabilities
        });

        match self.operation {
            IdentityOperation::Update => {
                let etag = self.etag.ok_or_else(|| {
                    AzureError::GenericErrorWithText("etag is not set".to_string())
                })?;
                request_builder = request_builder.header("If-Match", "*");
                body["etag"] = serde_json::json!(etag);
            }
            IdentityOperation::Create => {}
        }

        let request = request_builder.body(Body::from(serde_json::to_string(&body)?))?;
        let (status_code, _, whole_body) =
            extract_status_headers_and_body(client.request(request)).await?;
        if !status_code.is_success() {
            return Err(AzureError::UnexpectedHTTPResult(UnexpectedHTTPResult::new(
                StatusCode::OK,
                status_code,
                std::str::from_utf8(&whole_body)?,
            )));
        }

        Ok(serde_json::from_slice::<Device>(&whole_body)?)
    }
/// Performs the create or update request on the device identity
Performs the create or update request on the device identity
Performs the create or update request on the device identity
pub async fn execute(self) -> Result<Device, AzureError> {
        let device_id = self.device_id.ok_or_else(|| {
            AzureError::GenericErrorWithText("Field 'device_id' is not set".to_string())
        })?;
        let status = self.status.ok_or_else(|| {
            AzureError::GenericErrorWithText("Field 'status' is not set".to_string())
        })?;
        let authentication = self.authentication.ok_or_else(|| {
            AzureError::GenericErrorWithText("Field 'authentication' is not set".to_string())
        })?;
        let uri = format!(
            "https://{}.azure-devices.net/devices/{}?api-version={}",
            self.service_client.iothub_name, device_id, API_VERSION
        );
        let https = HttpsConnector::new();
        let client = Client::builder().build::<_, hyper::Body>(https);
        let mut request_builder = Request::builder()
            .uri(uri)
            .method(Method::PUT)
            .header("Authorization", &self.service_client.sas_token)
            .header("Content-Type", "application/json");
        let mut body = serde_json::json!({
            "authentication": authentication,
            "deviceId": device_id,
            "status": status,
            "capabilities": self.capabilities
        });
        match self.operation {
            IdentityOperation::Update => {
                let etag = self.etag.ok_or_else(|| {
                    AzureError::GenericErrorWithText("etag is not set".to_string())
                })?;
                request_builder = request_builder.header("If-Match", "*");
                body["etag"] = serde_json::json!(etag);
            }
            IdentityOperation::Create => {}
        }
        let request = request_builder.body(Body::from(serde_json::to_string(&body)?))?;
        let (status_code, _, whole_body) =
            extract_status_headers_and_body(client.request(request)).await?;
        if !status_code.is_success() {
            return Err(AzureError::UnexpectedHTTPResult(UnexpectedHTTPResult::new(
                StatusCode::OK,
                status_code,
                std::str::from_utf8(&whole_body)?,
            )));
        }
        Ok(serde_json::from_slice::<Device>(&whole_body)?)
    }
pub async fn execute ( self ) -> Result < Device , AzureError > { let device_id = self . device_id . ok_or_else ( | | { AzureError :: GenericErrorWithText ( " " . to_string ( ) ) } ) ? ; let status = self . status . ok_or_else ( | | { AzureError :: GenericErrorWithText ( " " . to_string ( ) ) } ) ? ; let authentication = self . authentication . ok_or_else ( | | { AzureError :: GenericErrorWithText ( " " . to_string ( ) ) } ) ? ; let uri = format ! ( " " self service_client iothub_name device_id API_VERSION ) ; let https = HttpsConnector :: new ( ) ; let client = Client :: builder ( ) . build :: < _ , hyper :: Body > ( https ) ; let mut request_builder = Request :: builder ( ) . uri ( uri ) . method ( Method :: PUT ) . header ( " " , & self . service_client . sas_token ) . header ( " " , " " ) ; let mut body = serde_json :: json ! ( { " " authentication " " device_id " " status " " self capabilities } ) ; match self . operation { IdentityOperation :: Update => { let etag = self . etag . ok_or_else ( | | { AzureError :: GenericErrorWithText ( " " . to_string ( ) ) } ) ? ; request_builder = request_builder . header ( " " , " " ) ; body [ " " ] = serde_json :: json ! ( etag ) ; } IdentityOperation :: Create => { } } let request = request_builder . body ( Body :: from ( serde_json :: to_string ( & body ) ? ) ) ? ; let ( status_code , _ , whole_body ) = extract_status_headers_and_body ( client . request ( request ) ) . await ? ; if ! status_code . is_success ( ) { return Err ( AzureError :: UnexpectedHTTPResult ( UnexpectedHTTPResult :: new ( StatusCode :: OK , status_code , std :: str :: from_utf8 ( & whole_body ) ? , ) ) ) ; } Ok ( serde_json :: from_slice :: < Device > ( & whole_body ) ? ) }
Performs the create or update request on the device identity
Performs the create or update request on the device identity
self