Skip to content

Commit 40a0010

Browse files
client: resolve tenant code on connect (#3528)
1 parent 2e1ee5f commit 40a0010

1 file changed

Lines changed: 20 additions & 24 deletions

File tree

client/doublezero/src/command/connect.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -456,40 +456,36 @@ impl ProvisioningCliCommand {
456456
})?;
457457

458458
// Determine tenant: 1) from CLI argument, 2) from config file, 3) from access pass allowlist
459-
let tenant = if let Some(t) = tenant {
460-
Some(t)
459+
let tenant_with_source: Option<(String, &str)> = if let Some(t) = tenant {
460+
Some((t, "CLI argument"))
461461
} else {
462462
let cfg_tenant = doublezero_sdk::read_doublezero_config()
463463
.ok()
464464
.and_then(|(_, cfg)| cfg.tenant);
465-
if let Some(ref t) = cfg_tenant {
466-
spinner.println(format!(" Using tenant '{t}' from configuration file."));
467-
}
468-
cfg_tenant.or_else(|| {
465+
if let Some(t) = cfg_tenant {
466+
Some((t, "configuration file"))
467+
} else {
469468
accesspass
470469
.tenant_allowlist
471470
.first()
472471
.filter(|pk| **pk != Pubkey::default())
473-
.map(|pk| {
474-
let t = pk.to_string();
475-
spinner.println(format!(" Using tenant '{t}' from Access Pass."));
476-
t
477-
})
478-
})
472+
.map(|pk| (pk.to_string(), "Access Pass"))
473+
}
479474
};
480475

481-
let tenant_pk = match tenant {
482-
Some(tenant_str) => match parse_pubkey(&tenant_str) {
483-
Some(pk) => Some(pk),
484-
None => {
485-
let (pubkey, _) = client
486-
.get_tenant(GetTenantCommand {
487-
pubkey_or_code: tenant_str.clone(),
488-
})
489-
.map_err(|_| eyre::eyre!("Tenant not found"))?;
490-
Some(pubkey)
491-
}
492-
},
476+
let tenant_pk = match tenant_with_source {
477+
Some((tenant_str, source)) => {
478+
let (pubkey, tenant_account) = client
479+
.get_tenant(GetTenantCommand {
480+
pubkey_or_code: tenant_str.clone(),
481+
})
482+
.map_err(|_| eyre::eyre!("Tenant '{}' not found", tenant_str))?;
483+
spinner.println(format!(
484+
" Using tenant '{}' from {}.",
485+
tenant_account.code, source
486+
));
487+
Some(pubkey)
488+
}
493489
None => None,
494490
};
495491

0 commit comments

Comments
 (0)