Skip to content
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

[WIP][RHCLOUD-37288] add option to list both principal types in one query to the /principals/ endpoint #1512

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

petracihalova
Copy link
Contributor

@petracihalova petracihalova commented Feb 14, 2025

Link(s) to Jira

Description of Intent of Change(s)

the /principals/ endpoint allow to list the user based principals with type=user query param (default option)
you can list service account based principals with type=service-account query param
this PR adds third option type=all to list both principal types in one query:

  • first we list service accounts if present
  • then we list user based principals
  • the filtering with usernames query param is working too (you can combine usernames of both principal types)
  • the access token is needed for the query (same as for type=service-account)

example of the response:

{
    "meta": {
        "count": 86,
        "limit": 2,
        "offset": 2
    },
    "links": {
        "first": "/api/rbac/v1/principals/?limit=2&offset=0",
        "next": "/api/rbac/v1/principals/?limit=2&offset=4",
        "previous": "/api/rbac/v1/principals/?limit=2&offset=0",
        "last": "/api/rbac/v1/principals/?limit=2&offset=84"
    },
    "data": {
        "serviceAccounts": [
            {
                "type": "service-account",
                "username": "service-account-de4c127a-f818-4ead-b5b9-1fef9b597513"
                ...
            }
        ],
        "users": [
            {
                "username": "my_user_principal",
                ...
            }
        ]
    }
}

Local Testing

use tenant with few user based principals and service accounts and test queries with(out) the type query param

GET /api/rbac/v1/principals/
GET /api/rbac/v1/principals/?type=user
GET /api/rbac/v1/principals/?type=service-account
GET /api/rbac/v1/principals/?type=all

for example if GET /api/rbac/v1/principals/ returns 10 user based principals and GET /api/rbac/v1/principals/?type=service-account returns 3 service accounts, then GET /api/rbac/v1/principals/?type=all should return 13 principals (both types)

try combinations of limit and offset to check that pagination is working as expected

for example if your tenant contains 3 SA (service accounts) and 4 U (user based principals) then with limit=2 and offset=0 you get this pagination:

page 1 -> 2 SA
page 2 -> 1 SA + 1 U
page 3 -> 2 U
page 4 -> 1 U

Checklist

  • open api spec updated
  • unit tests
  • added the ACs in the ticket

@petracihalova petracihalova changed the title [WIP][RHCLOUD-37288] add option to list both principal types in one query to the /principals/ endpoint [RHCLOUD-37288] add option to list both principal types in one query to the /principals/ endpoint Feb 17, 2025
@petracihalova petracihalova changed the title [RHCLOUD-37288] add option to list both principal types in one query to the /principals/ endpoint [WIP][RHCLOUD-37288] add option to list both principal types in one query to the /principals/ endpoint Feb 19, 2025
@petracihalova petracihalova added the enhancement New feature or request label Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant