Skip to content
Snippets Groups Projects

Use `AgentTokensFinder` to find single agent tokens

Merged Pam Artiaga requested to merge pam/agent-tokens-finder-single-record into master
All threads resolved!

What does this MR do and why?

The AgentTokensFinder was introduced in these MRs: !103170 (merged) & !104038 (merged) and used for fetching all agent tokens of an agent.

Here, the AgentTokensFinder class is used for fetching a single agent_token record in the GET /projects/:id/cluster_agents/:agent_id/tokens/:token_id endpoint. The FinderMethods module is included to support finding a single record.

Note that this follows the original behavior of returning the token regardless of status (active or revoked).

Issue: #363119 (closed)

Screenshots or screen recordings

Setup

Example project (ID=27):

test_browser_project

Project Agent -> Tokens page

test_browser_agent_tokens

Project agent and agent tokens in the database

test_psql_project_agents

test_psql_project_agent_tokens

Test

Fetching a single agent token

test_api_get-token

Fetching a single agent token that is revoked

test_api_get-token-revoked

When specified agent_id is not under the specified project

test_api_get-token-wrong-project

When specified agent does not exist

test_api_get-token-wrong-agent

How to set up and validate locally

Setup

  1. Create a project (or use an existing one)
  2. Set up an agent in that project
    • This will register an agent and create one agent token
  3. Create more agent tokens:
    1. Go to project Infrastructure -> Kubernetes clusters page
    2. Go to the agent's page
    3. Select the Access tokens tab
    4. Click the Create token button

Validate

Use curl to test the API endpoint

  1. Set up a project or personal access token to make sure your curl request is authorized

  2. 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/<token_id>"

    Example:

    curl -ki -X GET \
    --header "Authorization: Bearer <token>" \
    "https://gdk.test:3443/api/v4/projects/27/cluster_agents/7/tokens/6"

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Pam Artiaga

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Pam Artiaga mentioned in merge request !103170 (merged)

    mentioned in merge request !103170 (merged)

  • Pam Artiaga added 4 commits

    added 4 commits

    • f6261f2f...2cec222d - 2 commits from branch pam/agent-tokens-finder
    • 3794f664 - Use AgentTokensFinder in API endpoint for fetching a single token
    • bc9aa460 - Add test for revoked agent_token

    Compare with previous version

  • Pam Artiaga changed the description

    changed the description

  • Pam Artiaga resolved all threads

    resolved all threads

  • Pam Artiaga marked this merge request as ready

    marked this merge request as ready

  • Author Maintainer

    Hi @Alexand @timofurrer could you also give this a :eyes: please.

  • Pam Artiaga requested review from @Alexand and @timofurrer

    requested review from @Alexand and @timofurrer

  • Timo Furrer
  • @partiaga I really appreciate the great MR descriptions in all of the MRs in this series. Thank you! :handshake:

  • Timo Furrer approved this merge request

    approved this merge request

  • :wave: @timofurrer, thanks for approving this merge request.

    This is the first time the merge request is approved. To ensure full test coverage, a new pipeline will be started shortly.

    For more info, please refer to the following links:

  • 🤖 GitLab Bot 🤖 added 1 deleted label

    added 1 deleted label

  • Timo Furrer removed review request for @timofurrer

    removed review request for @timofurrer

  • Pam Artiaga resolved all threads

    resolved all threads

  • Pam Artiaga added 1 commit

    added 1 commit

    • 03476a44 - Test status of the agent token

    Compare with previous version

  • Pam Artiaga deleted the pam/agent-tokens-finder branch. This merge request now targets the master branch

    deleted the pam/agent-tokens-finder branch. This merge request now targets the master branch

  • Pam Artiaga added 1113 commits

    added 1113 commits

    • 03476a44...6892a52f - 1110 commits from branch master
    • 1013234c - Use AgentTokensFinder in API endpoint for fetching a single token
    • adb81e1f - Add test for revoked agent_token
    • b2ec84a9 - Test status of the agent token

    Compare with previous version

  • Author Maintainer

    Hi @Alexand did you have any comments about this MR? Will assign to the maintainer if not :slight_smile:

    Btw, the review-app deploy step is running into timeouts and currently being investigated, thus the failed pipeline. The MR code still be ok to review :slight_smile:

  • Pam Artiaga mentioned in merge request !103897 (merged)

    mentioned in merge request !103897 (merged)

  • João Alexandre Cunha
  • João Alexandre Cunha
  • Thanks, @partiaga. :bow_tone1:

    I've only had 2 very minor suggestions. Since those are really trivial to fix, I'll approve this so you don't have to wait for another review cycle from me. So feel free to pass forward to the database and backend maintainers after you address those 2 threads. But also feel free to send it back to me if you'd like.

    Edited by João Alexandre Cunha
  • João Alexandre Cunha approved this merge request

    approved this merge request

  • João Alexandre Cunha removed review request for @Alexand

    removed review request for @Alexand

  • Pam Artiaga added 1 commit

    added 1 commit

    Compare with previous version

  • Pam Artiaga resolved all threads

    resolved all threads

  • Pam Artiaga marked this merge request as draft

    marked this merge request as draft

  • Pam Artiaga mentioned in merge request !104038 (merged)

    mentioned in merge request !104038 (merged)

  • Pam Artiaga added 396 commits

    added 396 commits

    • 4ea0da28...8fdbfce3 - 390 commits from branch master
    • fb99ead1 - Update AgentTokensFinder to expect agent argument
    • 6e2f447e - Use AgentTokensFinder in API endpoint for fetching a single token
    • 06462eda - Add test for revoked agent_token
    • 7d67b994 - Test status of the agent token
    • 2df9f0e9 - Follow testing guidelines
    • 81594b1c - Pass the agent as argument to AgentTokensFinder

    Compare with previous version

  • Pam Artiaga changed the description

    changed the description

  • Pam Artiaga changed target branch from master to pam/agent-tokens-finder-agent-arg

    changed target branch from master to pam/agent-tokens-finder-agent-arg

  • Pam Artiaga added 7 commits

    added 7 commits

    • cd9d5f72 - 1 commit from branch pam/agent-tokens-finder-agent-arg
    • 3be71988 - Use AgentTokensFinder in API endpoint for fetching a single token
    • 52caa594 - Add test for revoked agent_token
    • fd6202cc - Test status of the agent token
    • dac47858 - Follow testing guidelines
    • e29f3551 - Pass the agent as argument to AgentTokensFinder
    • 00c3e7e3 - Update arguments passed to AgentTokensFinder

    Compare with previous version

  • Pam Artiaga added 7 commits

    added 7 commits

    • 6017ef6b - 1 commit from branch pam/agent-tokens-finder-agent-arg
    • 2fecb209 - Use AgentTokensFinder in API endpoint for fetching a single token
    • 6acd2596 - Add test for revoked agent_token
    • 3c6853fd - Test status of the agent token
    • d6802ed5 - Follow testing guidelines
    • 7ff3b932 - Pass the agent as argument to AgentTokensFinder
    • 55e2ad74 - Update arguments passed to AgentTokensFinder

    Compare with previous version

  • Pam Artiaga deleted the pam/agent-tokens-finder-agent-arg branch. This merge request now targets the master branch

    deleted the pam/agent-tokens-finder-agent-arg branch. This merge request now targets the master branch

  • Pam Artiaga added 1031 commits

    added 1031 commits

    • 55e2ad74...e51f4c53 - 1025 commits from branch master
    • 7a11edce - Use AgentTokensFinder in API endpoint for fetching a single token
    • efa13a2f - Add test for revoked agent_token
    • c97f6644 - Test status of the agent token
    • a9523cf8 - Follow testing guidelines
    • 2e1833f1 - Pass the agent as argument to AgentTokensFinder
    • b1b594da - Update arguments passed to AgentTokensFinder

    Compare with previous version

  • Pam Artiaga added 2 commits

    added 2 commits

    Compare with previous version

  • Pam Artiaga marked this merge request as ready

    marked this merge request as ready

  • Pam Artiaga requested review from @Alexand

    requested review from @Alexand

  • João Alexandre Cunha
  • João Alexandre Cunha approved this merge request

    approved this merge request

  • João Alexandre Cunha removed review request for @Alexand

    removed review request for @Alexand

  • Pam Artiaga added 1 commit

    added 1 commit

    • e212a783 - Separate setup from actual test

    Compare with previous version

  • Pam Artiaga resolved all threads

    resolved all threads

  • Pam Artiaga requested review from @ck3g and @ahegyi

    requested review from @ck3g and @ahegyi

  • added databaseapproved label and removed databasereviewed label

  • Adam Hegyi approved this merge request

    approved this merge request

  • Adam Hegyi removed review request for @ahegyi

    removed review request for @ahegyi

  • Vitali Tatarintev approved this merge request

    approved this merge request

  • Vitali Tatarintev resolved all threads

    resolved all threads

  • mentioned in commit a65a5c92

  • added workflowstaging label and removed workflowcanary label

  • Pam Artiaga changed milestone to %15.7

    changed milestone to %15.7

  • Please register or sign in to reply
    Loading