Class: ResourceAccessTokens::RevokeService

Inherits:
BaseService
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/resource_access_tokens/revoke_service.rb

Constant Summary collapse

RevokeAccessTokenError =
Class.new(RuntimeError)

Instance Attribute Summary

Attributes inherited from BaseService

#params, #project

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(current_user, resource, access_token) ⇒ RevokeService

Returns a new instance of RevokeService.


9
10
11
12
13
14
# File 'app/services/resource_access_tokens/revoke_service.rb', line 9

def initialize(current_user, resource, access_token)
  @current_user = current_user
  @access_token = access_token
  @bot_user = access_token.user
  @resource = resource
end

Instance Method Details

#executeObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/resource_access_tokens/revoke_service.rb', line 16

def execute
  return error("#{current_user.name} cannot delete #{bot_user.name}") unless can_destroy_token?
  return error("Failed to find bot user") unless find_member

  access_token.revoke!

  destroy_bot_user

  log_event

  success("Access token #{access_token.name} has been revoked and the bot user has been scheduled for deletion.")
rescue StandardError => error
  log_error("Failed to revoke access token for #{bot_user.name}: #{error.message}")
  error(error.message)
end