Skip to content
Snippets Groups Projects
Commit 88189d31 authored by Sanad Liaquat's avatar Sanad Liaquat
Browse files

Add script to revoke personal access tokens

parent a2b26577
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -29,7 +29,7 @@
%span.token-never-expires-label Never
%td= token.scopes.present? ? token.scopes.join(", ") : "<no scopes selected>"
- path = impersonation ? revoke_admin_user_impersonation_token_path(token.user, token) : revoke_profile_personal_access_token_path(token)
%td= link_to "Revoke", path, method: :put, class: "btn btn-danger float-right", data: { confirm: "Are you sure you want to revoke this #{type} Token? This action cannot be undone." }
%td= link_to "Revoke", path, method: :put, class: "btn btn-danger float-right qa-revoke-button", data: { confirm: "Are you sure you want to revoke this #{type} Token? This action cannot be undone." }
- else
.settings-message.text-center
This user has no active #{type} Tokens.
require_relative 'qa/tools/revoke_all_personal_access_tokens'
desc "Revokes all personal access tokens"
task :revoke_personal_access_tokens do
QA::Tools::RevokeAllPersonalAccessTokens.new.run
end
Loading
Loading
@@ -12,6 +12,10 @@ module QA
element :create_token_field, "text_field_tag 'created-personal-access-token'" # rubocop:disable QA/ElementWithPattern
end
 
view 'app/views/shared/_personal_access_tokens_table.html.haml' do
element :revoke_button
end
def fill_token_name(name)
fill_in 'personal_access_token_name', with: name
end
Loading
Loading
@@ -27,6 +31,22 @@ module QA
def created_access_token
page.find('#created-personal-access-token').value
end
def has_token_row_for_name?(token_name)
page.has_css?('tr', text: token_name, wait: 1.0)
end
def first_token_row_for_name(token_name)
page.find('tr', text: token_name, match: :first, wait: 1.0)
end
def revoke_first_token_with_name(token_name)
within first_token_row_for_name(token_name) do
accept_confirm do
click_element(:revoke_button)
end
end
end
end
end
end
Loading
Loading
# frozen_string_literal: true
require_relative '../../qa'
require 'net/protocol.rb'
# This script revokes all personal access tokens with the name of 'api-test-token' on the host specified by GITLAB_ADDRESS
# Required environment variables: GITLAB_USERNAME, GITLAB_PASSWORD and GITLAB_ADDRESS
# Run `rake revoke_personal_access_tokens`
module QA
module Tools
class RevokeAllPersonalAccessTokens
def run
do_run
rescue Net::ReadTimeout
STDOUT.puts 'Net::ReadTimeout during run. Trying again'
run
end
private
def do_run
raise ArgumentError, "Please provide GITLAB_USERNAME" unless ENV['GITLAB_USERNAME']
raise ArgumentError, "Please provide GITLAB_PASSWORD" unless ENV['GITLAB_PASSWORD']
raise ArgumentError, "Please provide GITLAB_ADDRESS" unless ENV['GITLAB_ADDRESS']
STDOUT.puts 'Running...'
Runtime::Browser.visit(ENV['GITLAB_ADDRESS'], Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
Page::Main::Menu.perform(&:go_to_profile_settings)
Page::Profile::Menu.perform(&:click_access_tokens)
token_name = 'api-test-token'
Page::Profile::PersonalAccessTokens.perform do |page|
while page.has_token_row_for_name?(token_name)
page.revoke_first_token_with_name(token_name)
print "\e[32m.\e[0m"
end
end
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment