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

refactor: more idiomatic identity override #3743

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions src/dfx-core/src/identity/identity_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub struct IdentityManager {
impl IdentityManager {
pub fn new(
logger: &Logger,
identity_override: &Option<String>,
identity_override: Option<&str>,
) -> Result<Self, NewIdentityManagerError> {
let config_dfx_dir_path =
get_user_dfx_config_dir().map_err(NewIdentityManagerError::GetConfigDirectoryFailed)?;
Expand All @@ -222,8 +222,9 @@ impl IdentityManager {
};

let selected_identity = identity_override
.clone()
.unwrap_or_else(|| configuration.default.clone());
.unwrap_or(&configuration.default)
.to_string();

let file_locations = IdentityFileLocations::new(identity_root_path);

let mgr = IdentityManager {
Expand Down
8 changes: 4 additions & 4 deletions src/dfx/src/lib/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub trait Environment {

/// This is value of the name passed to dfx `--identity <name>`
/// Notably, it is _not_ the name of the default identity or selected identity
fn get_identity_override(&self) -> &Option<String>;
fn get_identity_override(&self) -> Option<&str>;

// Explicit lifetimes are actually needed for mockall to work properly.
#[allow(clippy::needless_lifetimes)]
Expand Down Expand Up @@ -196,8 +196,8 @@ impl Environment for EnvironmentImpl {
&self.version
}

fn get_identity_override(&self) -> &Option<String> {
&self.identity_override
fn get_identity_override(&self) -> Option<&str> {
self.identity_override.as_deref()
}

fn get_agent(&self) -> &Agent {
Expand Down Expand Up @@ -317,7 +317,7 @@ impl<'a> Environment for AgentEnvironment<'a> {
self.backend.get_version()
}

fn get_identity_override(&self) -> &Option<String> {
fn get_identity_override(&self) -> Option<&str> {
self.backend.get_identity_override()
}

Expand Down