Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: more efficient API key load #463

Merged
merged 5 commits into from
Apr 26, 2021
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
25 changes: 17 additions & 8 deletions crates/houston/src/profile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,27 @@ impl Profile {

/// Loads and deserializes configuration from the file system for a
/// specific profile.
pub fn load(name: &str, config: &Config, opts: LoadOpts) -> Result<Profile, HoustonProblem> {
let profile_count = Profile::list(&config).unwrap_or_default().len();
if Profile::dir(name, config).exists() {
pub fn load(
profile_name: &str,
config: &Config,
opts: LoadOpts,
) -> Result<Profile, HoustonProblem> {
if Profile::dir(profile_name, config).exists() {
if opts.sensitive {
let sensitive = Sensitive::load(name, config)?;
let sensitive = Sensitive::load(profile_name, config)?;
return Ok(Profile { sensitive });
}
Err(HoustonProblem::NoNonSensitiveConfigFound(name.to_string()))
} else if profile_count == 0 {
Err(HoustonProblem::NoConfigProfiles)
Err(HoustonProblem::NoNonSensitiveConfigFound(
profile_name.to_string(),
))
} else {
Err(HoustonProblem::ProfileNotFound(name.to_string()))
let profiles_base_dir = Profile::base_dir(config);
if let Ok(mut base_dir) = fs::read_dir(profiles_base_dir) {
if base_dir.next().is_none() {
return Err(HoustonProblem::NoConfigProfiles);
}
}
Err(HoustonProblem::ProfileNotFound(profile_name.to_string()))
}
}

Expand Down