async fn process_request(&self, req: Request<Body>) -> crate::Result<Response<Body>> {
        let escaped_cert_str = req
            .headers()
            .get("x-ssl-client-escaped-cert")
            .ok_or(CustomError::MissingHeader)?
            .to_str()?;

        let cert_str = urlencoding::decode(escaped_cert_str)?;

        let cert_pem = Pem::iter_from_buffer(&cert_str.as_bytes())
            .next()
            .ok_or(CustomError::NoCertificate)??;

        let cert = cert_pem.parse_x509()?;

        let email = self
            .certificate_parser
            .get_email_from_san(&cert)
            .transpose()
            .or_else(|| self.certificate_parser.get_email_from_dn(&cert).transpose())
            .ok_or(CustomError::NoEmail)??;

        let name = cert
            .subject()
            .iter_common_name()
            .next()
            .map(|x| Ok::<_, CustomError>(x.as_str()?))
            .transpose()?
            .ok_or(CustomError::NoCommonName)?;

        let uid = self.certificate_parser.get_uid(&cert)?.unwrap_or(name);

        let users = self.snipe_it_client.get_users().await?;
        if !self.snipe_it_client.contains_username(uid, &users) {
            let password: String = rand::thread_rng()
                .sample_iter(&Alphanumeric)
                .take(64)
                .map(char::from)
                .collect();

            let user = User {
                username: uid.to_string(),
                first_name: name.split(" ").take(1).collect(),
                last_name: name.split(" ").skip(1).collect(),
                email: email.to_string(),
                activated: true,
                password: password.clone(),
                password_confirmation: password,
            };

            let _response = self.snipe_it_client.post_users(&user).await?;
        }

        Ok(Response::builder()
            .status(StatusCode::OK)
            .body(Body::from("success"))?)
    }
/// Retrieves the username and other relevant values from the client certificate
/// and checks whether a matching user exists in the Snipe-IT database.
///
/// If such a user does not yet exist, it creates a new user via the Snipe-IT REST API.
Retrieves the username and other relevant values from the client certificate
and checks whether a matching user exists in the Snipe-IT database.

If such a user does not yet exist, it creates a new user via the Snipe-IT REST API.
Retrieves the username and other relevant values from the client certificate and checks whether a matching user exists in the Snipe - IT database . If such a user does not yet exist it creates a new user via the Snipe - IT REST API .
async fn process_request(&self, req: Request<Body>) -> crate::Result<Response<Body>> {
        let escaped_cert_str = req
            .headers()
            .get("x-ssl-client-escaped-cert")
            .ok_or(CustomError::MissingHeader)?
            .to_str()?;
        let cert_str = urlencoding::decode(escaped_cert_str)?;
        let cert_pem = Pem::iter_from_buffer(&cert_str.as_bytes())
            .next()
            .ok_or(CustomError::NoCertificate)??;
        let cert = cert_pem.parse_x509()?;
        let email = self
            .certificate_parser
            .get_email_from_san(&cert)
            .transpose()
            .or_else(|| self.certificate_parser.get_email_from_dn(&cert).transpose())
            .ok_or(CustomError::NoEmail)??;
        let name = cert
            .subject()
            .iter_common_name()
            .next()
            .map(|x| Ok::<_, CustomError>(x.as_str()?))
            .transpose()?
            .ok_or(CustomError::NoCommonName)?;
        let uid = self.certificate_parser.get_uid(&cert)?.unwrap_or(name);
        let users = self.snipe_it_client.get_users().await?;
        if !self.snipe_it_client.contains_username(uid, &users) {
            let password: String = rand::thread_rng()
                .sample_iter(&Alphanumeric)
                .take(64)
                .map(char::from)
                .collect();
            let user = User {
                username: uid.to_string(),
                first_name: name.split(" ").take(1).collect(),
                last_name: name.split(" ").skip(1).collect(),
                email: email.to_string(),
                activated: true,
                password: password.clone(),
                password_confirmation: password,
            };
            let _response = self.snipe_it_client.post_users(&user).await?;
        }
        Ok(Response::builder()
            .status(StatusCode::OK)
            .body(Body::from("success"))?)
    }
async fn process_request ( & self , req : Request < Body > ) -> crate :: Result < Response < Body > > { let escaped_cert_str = req . headers ( ) . get ( " " ) . ok_or ( CustomError :: MissingHeader ) ? . to_str ( ) ? ; let cert_str = urlencoding :: decode ( escaped_cert_str ) ? ; let cert_pem = Pem :: iter_from_buffer ( & cert_str . as_bytes ( ) ) . next ( ) . ok_or ( CustomError :: NoCertificate ) ? ? ; let cert = cert_pem . parse_x509 ( ) ? ; let email = self . certificate_parser . get_email_from_san ( & cert ) . transpose ( ) . or_else ( | | self . certificate_parser . get_email_from_dn ( & cert ) . transpose ( ) ) . ok_or ( CustomError :: NoEmail ) ? ? ; let name = cert . subject ( ) . iter_common_name ( ) . next ( ) . map ( | x | Ok :: < _ , CustomError > ( x . as_str ( ) ? ) ) . transpose ( ) ? . ok_or ( CustomError :: NoCommonName ) ? ; let uid = self . certificate_parser . get_uid ( & cert ) ? . unwrap_or ( name ) ; let users = self . snipe_it_client . get_users ( ) . await ? ; if ! self . snipe_it_client . contains_username ( uid , & users ) { let password : String = rand :: thread_rng ( ) . sample_iter ( & Alphanumeric ) . take ( 64 ) . map ( char :: from ) . collect ( ) ; let user = User { username : uid . to_string ( ) , first_name : name . split ( " " ) . take ( 1 ) . collect ( ) , last_name : name . split ( " " ) . skip ( 1 ) . collect ( ) , email : email . to_string ( ) , activated : true , password : password . clone ( ) , password_confirmation : password , } ; let _response = self . snipe_it_client . post_users ( & user ) . await ? ; } Ok ( Response :: builder ( ) . status ( StatusCode :: OK ) . body ( Body :: from ( " " ) ) ? ) }
Retrieves the username and other relevant values from the client certificate
and checks whether a matching user exists in the Snipe-IT database.
Retrieves the username and other relevant values from the client certificate and checks whether a matching user exists in the Snipe - IT database .
&self
req
Request<Body>