-
Notifications
You must be signed in to change notification settings - Fork 37
feat: aptible organizations subcommand [SC-35706] #403
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
Conversation
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 this is a potentially great feature for us to have
i think i spotted:
- one bug to revisit (first user)
- extra API calls that probably don't need to fire (you have organization in hand already)
- nits/a few stylistic preferences - feel free to disregard
edit - if top two bullets addressed, i think this is fine.
i'm looking through our slack/history to see if you'll run into any other issues with this
This makes it simple to get the current user from the current token: ```ruby whoami = Aptible::Auth::Token.current_token.user ``` This will help with: aptible/aptible-cli#403
* feat: new Token.current_token class method [SC-35706] This makes it simple to get the current user from the current token: ```ruby whoami = Aptible::Auth::Token.current_token.user ``` This will help with: aptible/aptible-cli#403 * feat: efficient roles & orgs lookup for a user [SC-35706] We want to display the organizations a user has access to in the cli, along with their roles for each org. This is roughly the structure of what we have without this change: ```ruby user = Aptible::Auth::Token.current_token(token: token).user user.roles.each do |role| # http request to list all roles for the user org = role.organization # http request for this organization puts "#{org.name}: #{role.name} (#{role.id})" end ``` Note that this is an N+1 operation, because each `role.organization` call in the loop does another http call to retrieve the organization. That happens even if the same organization has already been seen. We add `user.roles_with_organizations`, which enables the same looping operations and only make 2 http requests. First it gets all the organizations and keeps them in a map, then it does the call to roles and preloads each role with the organization from the preloaded map. The above code can be converted to: ```ruby user = Aptible::Auth::Token.current_token(token: token).user user.roles_with_organizations.each do |role| # 2 http requests org = role.organization # does _not_ make an http request 🎉 puts "#{org.name}: #{role.name} (#{role.id})" end ``` * bump version 1.4.0 -> 1.5.0 * build pls
|
📝 Documentation updates detected! Updated existing suggestion: Add documentation for missing CLI commands |
Requires: