| 90 | } |
| 91 | |
| 92 | async fn send_rpc_request<S: Serialize, D: DeserializeOwned>( |
| 93 | &self, |
| 94 | path: &str, |
| 95 | payload: &S, |
| 96 | ) -> anyhow::Result<D> { |
| 97 | match &self.client { |
| 98 | ClientKind::Http => { |
| 99 | let client = Client::new(); |
| 100 | let url = format!( |
| 101 | "{}/{}", |
| 102 | self.base_url.trim_end_matches('/'), |
| 103 | path.trim_start_matches('/') |
| 104 | ); |
| 105 | let res = client |
| 106 | .post(&url) |
| 107 | .json(payload) |
| 108 | .header("Content-Type", "application/json") |
| 109 | .send() |
| 110 | .await? |
| 111 | .error_for_status()?; |
| 112 | Ok(res.json().await?) |
| 113 | } |
| 114 | ClientKind::Unix => { |
| 115 | let mut unix_client = ClientUnix::try_new(&self.endpoint).await?; |
| 116 | let res = unix_client |
| 117 | .send_request_json::<_, _, Value>( |
| 118 | path, |
| 119 | Method::POST, |
| 120 | &[("Content-Type", "application/json"), ("Host", "dstack")], |
| 121 | Some(&payload), |
| 122 | ) |
| 123 | .await?; |
| 124 | Ok(res.1) |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | pub async fn get_key( |
| 130 | &self, |