Implement `AgentTokensFinder` and use in agent_tokens api
What does this MR do and why?
This implements a Clusters::AgentTokensFinder
class, similar to the Clusters::AgentsFinder class.
This is the first of a set of changes to use the AgentTokensFinder
in the Cluster Agent Tokens API. In this MR, the AgentTokensFinder
class is used for fetching the agent_token records in the GET /projects/:id/cluster_agents/:agent_id/tokens
endpoint. There is no need yet to have anything in the finder class beyond a straightforward execute
method.
Changes to the AgentTokensFinder
(e.g.: including FinderMethods
module or having a params
argument) will be added as needed by the endpoints using it.
Note that this follows the original behavior of returning all tokens of an agent regardless of status (active or revoked).
Issue: #363119 (closed)
Other MRs for the issue: !103292 (merged) !103300 (merged)
Screenshots or screen recordings
Setup
Example project (ID=27):
Project Agent -> Tokens page
Project agent and agent tokens in the database
Test
Fetching agent tokens
When specified agent_id is not under the specified project
When specified agent does not exist
How to set up and validate locally
Setup
- Create a project (or use an existing one)
-
Set up an agent in that project
- This will register an agent and create one agent token
- Create more agent tokens:
- Go to project Infrastructure -> Kubernetes clusters page
- Go to the agent's page
- Select the Access tokens tab
- Click the Create token button
Validate
Use curl
to test the API endpoint
-
Set up a project or personal access token to make sure your curl request is authorized
-
Run the following
curl
request:curl -ki -X GET \ --header "Authorization: Bearer <your project or personal access token>" \ "https://<local gitlab url>/api/v4/projects/<project_id>/cluster_agents/<agent_id>/tokens"
Example:
curl -ki -X GET \ --header "Authorization: Bearer <token>" \ "https://gdk.test:3443/api/v4/projects/28/cluster_agents/7/tokens"
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.