Skip to content

Conversation

@tvdaptible
Copy link
Contributor

@tvdaptible tvdaptible commented Dec 19, 2025

% bundle exec bin/aptible help organizations
Usage:
  aptible organizations

List all organizations

% bundle exec bin/aptible organizations
Id: 5ca1ab1e-0000-0000-0000-000000000000
Name: Acme Prod
Roles:
  Id: 5afe5afe-0000-0000-0000-000000000000
  Name: Deploy Owners

  Id: acce5500-0000-0000-0000-000000000000
  Name: Read Only

Id: cafecafe-cafe-cafe-cafe-cafecafecafe
Name: Acme Test
Roles:
  Id: c0ffee50-0000-0000-0000-000000000000
  Name: Account Owners

% APTIBLE_OUTPUT_FORMAT=json bundle exec bin/aptible organizations
[
  {
    "id": "5ca1ab1e-0000-0000-0000-000000000000",
    "name": "Acme Prod",
    "roles": [
      {
        "id": "5afe5afe-0000-0000-0000-000000000000",
        "name": "Deploy Owners"
      },
      {
        "id": "acce5500-0000-0000-0000-000000000000",
        "name": "Read Only"
      }
    ]
  },
  {
    "id": "cafecafe-cafe-cafe-cafe-cafecafecafe",
    "name": "Acme Test",
    "roles": [
      {
        "id": "c0ffee50-0000-0000-0000-000000000000",
        "name": "Account Owners"
      }
    ]
  }
]

Requires:

Copy link
Member

@madhuravius madhuravius left a 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

tvdaptible added a commit to aptible/aptible-auth-ruby that referenced this pull request Dec 22, 2025
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
@tvdaptible tvdaptible marked this pull request as draft December 23, 2025 00:04
tvdaptible added a commit to aptible/aptible-auth-ruby that referenced this pull request Dec 24, 2025
* 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
@tvdaptible tvdaptible marked this pull request as ready for review December 29, 2025 22:05
@tvdaptible tvdaptible merged commit a4a7bfe into aptible:master Dec 29, 2025
7 checks passed
@tvdaptible tvdaptible deleted the list-orgs branch December 29, 2025 22:26
@promptless
Copy link

promptless bot commented Jan 2, 2026

📝 Documentation updates detected!

Updated existing suggestion: Add documentation for missing CLI commands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants