Add statistics to the token management for service accounts UI

What does this MR do and why?

This Mr adds stats cards to the service accounts

These stats are:-

  • Active Tokens
  • Tokens expiring in 2 weeks
  • Revoked Tokens
  • Expired Tokens

Screenshots or screen recordings

Before After
CleanShot 2025-03-18 at 12.56.18@2x.png CleanShot 2025-03-18 at 13.02.20@2x.png

Screen_Recording_2025-03-14_at_5.39.06_PM

How to set up and validate locally

  1. Enable the following feature flag: service_accounts_crud. Tip: use http://127.0.0.1:3000/rails/features/ for a UI to do that.
  2. Enable Ultimate license to group Flightjs
  3. Create a service account and several tokens in the gdk rails console:
group = Group.find_by(name: 'Flightjs')
response = Namespaces::ServiceAccounts::CreateService.new(User.first, name: 'My service account', organization_id: group.organization_id, namespace_id: group.id).execute
service_account = response.payload[:user]

(1..5).each do |n|
  service_account.personal_access_tokens.create!(name: "Active token #{n}", expires_at: 30.days.since, scopes: ['read_api', 'read_user'])

  service_account.personal_access_tokens.create!(name: "Expiring token #{n}", expires_at: 5.days.since, scopes: ['read_api', 'read_user'])

  service_account.personal_access_tokens.create!(name: "Expired token #{n}", expires_at: 30.days.ago, scopes: ['read_api', 'read_user'])

  service_account.personal_access_tokens.create!(name: "Revoked token #{n}", revoked: true, expires_at: 30.days.since, scopes: ['read_api', 'read_user'])
end

service_account.id

Take note

Write down the id number that comes out of the rails console

  1. Use your address bar to access the specific page
  • In SaaS emulation, go to https://gdk.test:3443/groups/my_service_account/-/settings/service_accounts/[id (last line from console)]/access_tokens
  • Without SaaS emulation, go to https://gdk.test:3443/admin/application_settings/service_accounts/[id (last line from console)]/access_tokens
Edited by Austin Regnery

Merge request reports

Loading