Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,25 @@ fn mount_parse_ovf_env(dev: String) -> Result<Environment, anyhow::Error> {
Ok(environment)
}

fn get_environment() -> Result<Environment, anyhow::Error> {
Comment thread
jeremycline marked this conversation as resolved.
let ovf_devices = media::get_mount_device()?;
let mut environment: Option<Environment> = None;

// loop until it finds a correct device.
for dev in ovf_devices {
environment = match mount_parse_ovf_env(dev) {
Ok(env) => Some(env),
Err(_) => continue,
}
}

environment
.ok_or_else(|| anyhow::anyhow!("Unable to get list of block devices"))
}

fn get_username(
instance_metadata: &InstanceMetadata,
environment: &Environment,
) -> Result<String, anyhow::Error> {
if instance_metadata
.compute
Expand All @@ -49,22 +66,8 @@ fn get_username(
} else {
// password authentication is enabled

// list of CDROM devices that is available with possible filesystems.
let ovf_devices = media::get_mount_device()?;
let mut environment: Option<Environment> = None;

// loop until it finds a correct device.
for dev in ovf_devices {
environment = match mount_parse_ovf_env(dev) {
Ok(env) => Some(env),
Err(_) => continue,
}
}

Ok(environment
.ok_or_else(|| {
anyhow::anyhow!("Unable to get list of block devices")
})?
.clone()
.provisioning_section
.linux_prov_conf_set
.username)
Expand Down Expand Up @@ -103,7 +106,7 @@ async fn provision() -> Result<(), anyhow::Error> {
.build()?;

let instance_metadata = imds::query(&client).await?;
let username = get_username(&instance_metadata)?;
let username = get_username(&instance_metadata, &get_environment()?)?;

let mut file_path = "/home/".to_string();
file_path.push_str(username.as_str());
Expand Down