-
Notifications
You must be signed in to change notification settings - Fork 55
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 and improve users import cmd #735
Conversation
3933e6a
to
538b6bf
Compare
docs/auth0_users_import.md
Outdated
@@ -18,9 +18,15 @@ auth0 users import [flags] | |||
``` | |||
auth0 users import | |||
auth0 users import --connection "Username-Password-Authentication" | |||
auth0 users import --connection "Username-Password-Authentication" --users-body "[]" |
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 biggest change here is the exposure of the users body flag. Previously this was hidden and only used to store the contents of the file opened up through the editor. We're now allowing users to pass the body directly bypassing the template selection. This change also enables us to add automated integration tests and improves DX.
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 data should also be able to be passed by pipe, like in other similar commands.
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.
Thanks @Widcket 👍🏻 good catch. Updated in 735e93f
(#735)
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 docs should also be updated to include a piped example, like in auth0 rules create
or auth0 api
.
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.
if editorErr != nil { | ||
return fmt.Errorf("Failed to capture input from the editor: %w", editorErr) | ||
} | ||
if inputs.UsersBody == "" { |
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.
If we don't pass a body directly, then we're gonna select a template and use the editor.
} | ||
|
||
if !confirmed { | ||
return nil | ||
if canPrompt(cmd) { |
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 gets skipped if we use --no-input.
|
||
list, err := c.api.Connection.List() | ||
func (c *cli) dbConnectionPickerOptions() ([]string, error) { | ||
list, err := c.api.Connection.List(management.Parameter("strategy", management.ConnectionStrategyAuth0)) |
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.
We're improving the logic here by directly only retrieving database connections from the API instead of retrieving everything and then filtering them out.
@@ -52,25 +52,6 @@ func TestConnectionsPickerOptions(t *testing.T) { | |||
assert.ErrorContains(t, err, "There are currently no database connections.") | |||
}, | |||
}, | |||
{ | |||
name: "no database connections", |
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.
No longer needed as we retrieve only database conns directly from the API.
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #735 +/- ##
==========================================
+ Coverage 70.60% 70.82% +0.22%
==========================================
Files 87 87
Lines 11197 11210 +13
==========================================
+ Hits 7906 7940 +34
+ Misses 2778 2750 -28
- Partials 513 520 +7
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
internal/cli/users.go
Outdated
LongForm: "template-body", | ||
userImportBody = Flag{ | ||
Name: "Users Body", | ||
LongForm: "users-body", |
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.
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.
Thanks for raising this. I actually think we're lacking a bit of consistency in these areas. Would you suggest just naming this users
so it's clear what kind of content it is? Or perhaps rename the others to rules-script for example?
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 think that we should prefer shorter flag names wherever possible, for usability reasons. Also I suspect changing this pattern to "resources-property" would cause a bigger inconsistency, requiring the renaming of a lot more flags.
users
is fine for this, I think.
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.
Renamed it to users in c092246
(#735).
But I also removed the short form as it was conflicting and replacing it with anything else than u
doesn't really work so well.
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.
Consider having -u
be the short form for users
and -U
the short version for upsert
.
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.
Good point 👍🏻 de8a9a4
(#735)
For some reason I thought short forms had to always be lower case.
527cce8
to
6caee69
Compare
6caee69
to
19b6a0c
Compare
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.
Large improvement!
🔧 Changes
This PR brings various improvements to the users import command. Additional context added within code comments below.
📚 References
🔬 Testing
📝 Checklist