LCOV - code coverage report
Current view: top level - storage_controller/client/src - control_api.rs (source / functions) Coverage Total Hit
Test: 6df3fc19ec669bcfbbf9aba41d1338898d24eaa0.info Lines: 0.0 % 40 0
Test Date: 2025-03-12 18:28:53 Functions: 0.0 % 35 0

            Line data    Source code
       1              : use pageserver_client::mgmt_api::{self, ResponseErrorMessageExt};
       2              : use reqwest::{Method, Url};
       3              : use serde::Serialize;
       4              : use serde::de::DeserializeOwned;
       5              : 
       6              : pub struct Client {
       7              :     base_url: Url,
       8              :     jwt_token: Option<String>,
       9              :     client: reqwest::Client,
      10              : }
      11              : 
      12              : impl Client {
      13            0 :     pub fn new(base_url: Url, jwt_token: Option<String>) -> Self {
      14            0 :         Self {
      15            0 :             base_url,
      16            0 :             jwt_token,
      17            0 :             client: reqwest::ClientBuilder::new()
      18            0 :                 .build()
      19            0 :                 .expect("Failed to construct http client"),
      20            0 :         }
      21            0 :     }
      22              : 
      23              :     /// Simple HTTP request wrapper for calling into storage controller
      24            0 :     pub async fn dispatch<RQ, RS>(
      25            0 :         &self,
      26            0 :         method: Method,
      27            0 :         path: String,
      28            0 :         body: Option<RQ>,
      29            0 :     ) -> mgmt_api::Result<RS>
      30            0 :     where
      31            0 :         RQ: Serialize + Sized,
      32            0 :         RS: DeserializeOwned + Sized,
      33            0 :     {
      34            0 :         let request_path = self
      35            0 :             .base_url
      36            0 :             .join(&path)
      37            0 :             .expect("Failed to build request path");
      38            0 :         let mut builder = self.client.request(method, request_path);
      39            0 :         if let Some(body) = body {
      40            0 :             builder = builder.json(&body)
      41            0 :         }
      42            0 :         if let Some(jwt_token) = &self.jwt_token {
      43            0 :             builder = builder.header(
      44            0 :                 reqwest::header::AUTHORIZATION,
      45            0 :                 format!("Bearer {jwt_token}"),
      46            0 :             );
      47            0 :         }
      48              : 
      49            0 :         let response = builder.send().await.map_err(mgmt_api::Error::ReceiveBody)?;
      50            0 :         let response = response.error_from_body().await?;
      51              : 
      52            0 :         response
      53            0 :             .json()
      54            0 :             .await
      55            0 :             .map_err(pageserver_client::mgmt_api::Error::ReceiveBody)
      56            0 :     }
      57              : }
        

Generated by: LCOV version 2.1-beta