How-To Guides
Filter Data

How to Filter Data

Oso Cloud's list API can efficiently perform authorization checks over collections of data.

Imagine you're building a dashboard for GitCloud users. When an authenticated user accesses the page, they should see a high-level overview of the repositories they have "read" access for. A naive way to implement that would be to fetch all repositories from the database and then filter them in-memory by asking if the current user is allowed to view each repository in turn. If GitCloud has millions of repositories, that might get pretty darn slow.

Oso Cloud's list API flattens that iterative approach into a single request: "What is the set of repositories that the user is allowed to see?" The response is a list of IDs of authorized resources (repositories, in this case) that can then be loaded from the database in one fell swoop:

PythonNodeGo
def authorized_repositories(oso: Oso, current_user: User) -> List[Repository]:
    repository_ids = oso.list(current_user, "view", "Repository")
    return get_repositories_by_ids(repository_ids)

For more details, consult the API docs for the list endpoint.

Talk to an Oso Engineer

Our team is happy to help you get started with Oso Cloud. If you'd like to learn more about using Oso Cloud in your app or have any questions about this guide, schedule a 1x1 with an Oso engineer.

Get started with Oso Cloud →