Skip to content

Commit

Permalink
Merge branch 'dev/jfullerton/rustNewVersion' of https://github.com/mi…
Browse files Browse the repository at this point in the history
…crosoft/dev-tunnels into dev/jfullerton/rustNewVersion
  • Loading branch information
jfullerton44 committed Oct 12, 2023
2 parents ab8f92b + fe00906 commit fe30bce
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions rs/src/management/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,8 @@ impl TunnelManagementClient {
url.query_pairs_mut().append_pair("global", "true");

let request = self.make_tunnel_request(Method::GET, url, options).await?;
let response: TunnelListByRegionResponse =
self.execute_json("list_all_tunnels", request).await?;
let mut tunnels = Vec::new();
for region in response.value {
tunnels.extend(region.value);
}
Ok(tunnels)
let response: TunnelListByRegionResponse = self.execute_json("list_all_tunnels", request).await?;
Ok(response.value.into_iter().flat_map(|v| v.value).collect())
}

/// Lists tunnels owned by the user in a specific cluster.
Expand Down Expand Up @@ -105,11 +100,12 @@ impl TunnelManagementClient {
mut tunnel: Tunnel,
options: &TunnelRequestOptions,
) -> HttpResult<Tunnel> {
if tunnel.tunnel_id.is_none() || tunnel.tunnel_id.as_ref().unwrap().is_empty() {
tunnel.tunnel_id = Some(TunnelManagementClient::generate_tunnel_id());
}
let mut url = self.build_uri(tunnel.cluster_id.as_deref(), TUNNELS_API_PATH);
let new_path = url.path().to_owned() + "/" + tunnel.tunnel_id.as_ref().unwrap();
let tunnel_id = match tunnel.tunnel_id.as_ref() {
None | Some("") => TunnelManagementClient::generate_tunnel_id(),
Some(tunnel_id) => tunnel_id.to_owned(),
};
let new_path = url.path().to_owned() + "/" + tunnel_id;
url.set_path(&new_path);
let mut request = self.make_tunnel_request(Method::PUT, url, options).await?;
json_body(&mut request, tunnel);
Expand Down Expand Up @@ -224,9 +220,7 @@ impl TunnelManagementClient {
) -> HttpResult<Vec<TunnelPort>> {
let url = self.build_tunnel_uri(locator, Some(PORTS_API_SUB_PATH));
let request = self.make_tunnel_request(Method::GET, url, options).await?;
let response: TunnelPortListResponse =
self.execute_json("list_tunnel_ports", request).await?;
Ok(response.value)
self.execute_json("list_tunnel_ports", request).await.map(|r| r.value)
}

/// Gets info about a specific tunnel port.
Expand Down

0 comments on commit fe30bce

Please sign in to comment.