Skip to content

Commit

Permalink
use the oxide CLI's --resolve argument
Browse files Browse the repository at this point in the history
  • Loading branch information
iliana committed Dec 6, 2023
1 parent e090c27 commit b0c57dd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
18 changes: 10 additions & 8 deletions end-to-end-tests/src/bin/cli_wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{Context, Result};
use end_to_end_tests::helpers::ctx::ClientParams;
use end_to_end_tests::helpers::ctx::{ClientParams, E2E_TLS_CERT_ENV};
use std::os::unix::process::CommandExt;
use std::process::Command;

Expand All @@ -10,12 +10,14 @@ async fn main() -> Result<Unreachable> {
let mut args = std::env::args_os();
let cli_path =
args.next().context("usage: cli_wrapper OXIDE_CLI ARGS...")?;

let client_params = ClientParams::new()?;
Err(Command::new(cli_path)
.args(args)
.env("OXIDE_HOST", client_params.base_url())
.env("OXIDE_TOKEN", client_params.get_session_token().await?)
.exec()
.into())
let mut cmd = Command::new(cli_path);
cmd.env("OXIDE_HOST", client_params.base_url());
cmd.env("OXIDE_TOKEN", client_params.get_session_token().await?);
cmd.arg("--resolve").arg(client_params.cli_resolve_arg().await?);
if let Some(cert_path) = std::env::var_os(E2E_TLS_CERT_ENV) {
cmd.arg("--cacert").arg(cert_path);
}
cmd.args(args);
Err(cmd.exec().into())
}
19 changes: 18 additions & 1 deletion end-to-end-tests/src/helpers/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use omicron_test_utils::dev::poll::{wait_for_condition, CondCheckError};
use oxide_client::types::{Name, ProjectCreate};
use oxide_client::CustomDnsResolver;
use oxide_client::{Client, ClientImagesExt, ClientProjectsExt, ClientVpcsExt};
use reqwest::dns::Resolve;
use reqwest::header::{HeaderMap, HeaderValue};
use reqwest::Url;
use std::net::IpAddr;
Expand All @@ -21,7 +22,7 @@ const RSS_CONFIG_STR: &str = include_str!(concat!(
));

// Environment variable containing the path to a cert that we should trust.
const E2E_TLS_CERT_ENV: &str = "E2E_TLS_CERT";
pub const E2E_TLS_CERT_ENV: &str = "E2E_TLS_CERT";

#[derive(Clone)]
pub struct Context {
Expand Down Expand Up @@ -184,6 +185,22 @@ impl ClientParams {
format!("{}://{}", self.proto, self.nexus_dns_name)
}

pub async fn cli_resolve_arg(&self) -> Result<String> {
let address = self
.resolver
.resolve(self.nexus_dns_name.parse()?)
.await
.map_err(anyhow::Error::msg)?
.next()
.context("name did not resolve to any address")?;
let port = match self.proto {
"http" => "80",
"https" => "443",
_ => unreachable!(),
};
Ok(format!("{}:{}:{}", self.nexus_dns_name, port, address))
}

pub fn reqwest_builder(&self) -> reqwest::ClientBuilder {
let mut builder =
reqwest::ClientBuilder::new().dns_resolver(self.resolver.clone());
Expand Down

0 comments on commit b0c57dd

Please sign in to comment.