-
Notifications
You must be signed in to change notification settings - Fork 177
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
Make identity naming more consistent + fix bugs #1140
Make identity naming more consistent + fix bugs #1140
Conversation
@@ -585,6 +577,7 @@ async fn exec_token(config: Config, args: &ArgMatches) -> Result<(), anyhow::Err | |||
async fn exec_set_name(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> { | |||
let new_name = args.get_one::<String>("name").unwrap(); | |||
let identity_or_name = args.get_one::<String>("identity").unwrap(); | |||
config.can_set_name(Some(identity_or_name.as_str()))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a regression. It essentially renders unnamed identities unusable.
$ spacetime identity new -s local --no-email | tee output
IDENTITY 631d3896d10a5fa9db73a95a5a2e20981ab71bc32cb908859e449b5eeb886e9a
NAME
EMAIL
$ cat output | grep 'IDENTITY' | awk '{print $2;}' | tee identity
631d3896d10a5fa9db73a95a5a2e20981ab71bc32cb908859e449b5eeb886e9a
$ spacetime identity set-name $(cat identity) new-identity-name
- Updated identity:
- IDENTITY 631d3896d10a5fa9db73a95a5a2e20981ab71bc32cb908859e449b5eeb886e9a
- NAME new-identity-name
+ Error: An identity name cannot be an identity.
+ [1]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for catching this Zeke that would have been a disaster 😦
|
||
if config.identity_configs().iter().any(|ic| ic.identity == identity) { | ||
return Err(anyhow::anyhow!("Identity already exists in config")); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also added a check here to prevent adding the same identity multiple times
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(factored out config.identity_exists
so it's somewhat self-describing)
crates/cli/src/util.rs
Outdated
@@ -149,6 +149,10 @@ pub async fn select_identity_config( | |||
server: Option<&str>, | |||
) -> Result<IdentityConfig, anyhow::Error> { | |||
if let Some(identity_or_name) = identity_or_name { | |||
if identity_or_name.is_empty() { | |||
return Err(anyhow::anyhow!("Identity value cannot be empty.")); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did we need this check? shouldn't get_identity_config("")
fail anyway?
crates/cli/src/config.rs
Outdated
} | ||
|
||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: how would you feel about making this like:
pub fn can_set_name(&self, new_nickname: &str) -> Result<(), anyhow::Error> {
(it seems a bit weird to call can_set_name(None)
?)
@@ -111,6 +112,8 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E | |||
let build_debug = args.get_flag("debug"); | |||
let wasm_file = args.get_one::<PathBuf>("wasm_file"); | |||
let database_host = config.get_host_url(server)?; | |||
// Validate the identity first to provide an early error message | |||
util::select_identity_config(&mut config, identity, server).await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we just move the later code to here, rather than effectively duplicating this check? like could we put this up here:
let (auth_header, identity) = get_auth_header(&mut config, anon_identity, identity, server)
.await?
.unzip();
@@ -152,7 +152,7 @@ pub async fn select_identity_config( | |||
config | |||
.get_identity_config(identity_or_name) | |||
.cloned() | |||
.ok_or_else(|| anyhow::anyhow!("No such identity credentials for identity: {}", identity_or_name)) | |||
.ok_or_else(|| anyhow::anyhow!("No identity credentials for identity \"{}\"", identity_or_name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(the extra ""
make it clearer when it's just the empty string)
// easily create a new identity with an email | ||
let (auth_header, identity) = get_auth_header(&mut config, anon_identity, identity, server) | ||
.await? | ||
.unzip(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving this earlier means that we check identity
validity before we go through a (potentially very long) build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once the base PR merges
ae62610
to
ce04e2d
Compare
Description of Changes
Please describe your change, mention any related tickets, and so on here.
spacetime identity new --name <name> --no-email
spacetime identity set-name <identity> <name>
spacetime identity import <identity> <token> --name <name>
In these places we had slightly different logic for validating that an identity name looks okay. I've made the logic in these places more consistent. This will prevent people from accidentally adding identities with the same name or with an invalid name (identity names cannot look like identities).
API and ABI breaking changes
If this is an API or ABI breaking change, please apply the
corresponding GitHub label.
Not breaking
Expected complexity level and risk
How complicated do you think these changes are? Grade on a scale from 1 to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex change.
This complexity rating applies not only to the complexity apparent in the diff,
but also to its interactions with existing and future code.
If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning ways.
0
Testing
Describe any testing you've done, and any testing you'd like your reviewers to do,
so that you're confident that all the changes work as expected!