Class: Mutations::Clusters::AgentTokens::Create

Inherits:
BaseMutation
  • Object
show all
Defined in:
app/graphql/mutations/clusters/agent_tokens/create.rb

Constant Summary collapse

ClusterAgentID =
::Types::GlobalIDType[::Clusters::Agent]

Constants inherited from BaseMutation

BaseMutation::ERROR_MESSAGE

Constants included from Gitlab::Graphql::Authorize::AuthorizeResource

Gitlab::Graphql::Authorize::AuthorizeResource::ConfigurationError, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR

Instance Method Summary collapse

Methods inherited from BaseMutation

#api_user?, authorization, authorized?, authorizes_object?, #current_user, #errors_on_object, #load_application_object, #ready?, #unauthorized_object

Methods included from Gitlab::Graphql::Authorize::AuthorizeResource

#authorize!, #authorized_find!, #authorized_resource?, #raise_resource_not_available_error!

Instance Method Details

#resolve(args) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/graphql/mutations/clusters/agent_tokens/create.rb', line 38

def resolve(args)
  cluster_agent = authorized_find!(id: args[:cluster_agent_id])

  result = ::Clusters::AgentTokens::CreateService
    .new(
      container: cluster_agent.project,
      current_user: current_user,
      params: args.merge(agent_id: cluster_agent.id)
    )
    .execute

  payload = result.payload

  {
   secret: payload[:secret],
   token: payload[:token],
   errors: Array.wrap(result.message)
  }
end