Class: Clusters::AgentTokens::RevokeService

Inherits:
Object
  • Object
show all
Defined in:
app/services/clusters/agent_tokens/revoke_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:, current_user:) ⇒ RevokeService

Returns a new instance of RevokeService.



8
9
10
11
# File 'app/services/clusters/agent_tokens/revoke_service.rb', line 8

def initialize(token:, current_user:)
  @token = token
  @current_user = current_user
end

Instance Attribute Details

#current_projectObject (readonly)

Returns the value of attribute current_project.



6
7
8
# File 'app/services/clusters/agent_tokens/revoke_service.rb', line 6

def current_project
  @current_project
end

#current_userObject (readonly)

Returns the value of attribute current_user.



6
7
8
# File 'app/services/clusters/agent_tokens/revoke_service.rb', line 6

def current_user
  @current_user
end

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'app/services/clusters/agent_tokens/revoke_service.rb', line 6

def token
  @token
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/clusters/agent_tokens/revoke_service.rb', line 13

def execute
  return error_no_permissions unless current_user.can?(:create_cluster, token.agent.project)

  if token.revoke!
    log_activity_event(token)

    ServiceResponse.success
  else
    ServiceResponse.error(message: token.errors.full_messages)
  end
end