(
&self,
path: &str,
payload: &S,
)
| 72 | } |
| 73 | |
| 74 | async fn send_rpc_request<S: Serialize, D: DeserializeOwned>( |
| 75 | &self, |
| 76 | path: &str, |
| 77 | payload: &S, |
| 78 | ) -> anyhow::Result<D> { |
| 79 | match &self.client { |
| 80 | TappdClientKind::Http => { |
| 81 | let client = Client::new(); |
| 82 | let url = format!( |
| 83 | "{}/{}", |
| 84 | self.base_url.trim_end_matches('/'), |
| 85 | path.trim_start_matches('/') |
| 86 | ); |
| 87 | let res = client |
| 88 | .post(&url) |
| 89 | .json(payload) |
| 90 | .header("Content-Type", "application/json") |
| 91 | .send() |
| 92 | .await? |
| 93 | .error_for_status()?; |
| 94 | Ok(res.json().await?) |
| 95 | } |
| 96 | TappdClientKind::Unix => { |
| 97 | let mut unix_client = ClientUnix::try_new(&self.endpoint).await?; |
| 98 | let res = unix_client |
| 99 | .send_request_json::<_, _, Value>( |
| 100 | path, |
| 101 | Method::POST, |
| 102 | &[("Content-Type", "application/json")], |
| 103 | Some(&payload), |
| 104 | ) |
| 105 | .await?; |
| 106 | Ok(res.1) |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /// Derives a key from the Tappd service using the path as both path and subject |
| 112 | pub async fn derive_key(&self, path: &str) -> Result<DeriveKeyResponse> { |
no test coverage detected