debian-mirror-gitlab/app/graphql/mutations/clusters/agent_tokens/create.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
1.7 KiB
Ruby
Raw Normal View History

2021-11-18 22:05:49 +05:30
# frozen_string_literal: true
module Mutations
module Clusters
module AgentTokens
class Create < BaseMutation
graphql_name 'ClusterAgentTokenCreate'
authorize :create_cluster
ClusterAgentID = ::Types::GlobalIDType[::Clusters::Agent]
argument :cluster_agent_id,
ClusterAgentID,
required: true,
description: 'Global ID of the cluster agent that will be associated with the new token.'
argument :description,
GraphQL::Types::String,
required: false,
description: 'Description of the token.'
argument :name,
GraphQL::Types::String,
required: true,
description: 'Name of the token.'
field :secret,
GraphQL::Types::String,
null: true,
description: "Token secret value. Make sure you save it - you won't be able to access it again."
field :token,
Types::Clusters::AgentTokenType,
null: true,
description: 'Token created after mutation.'
def resolve(args)
cluster_agent = authorized_find!(id: args[:cluster_agent_id])
result = ::Clusters::AgentTokens::CreateService
.new(
2023-05-27 22:25:52 +05:30
agent: cluster_agent,
2021-11-18 22:05:49 +05:30
current_user: current_user,
2023-05-27 22:25:52 +05:30
params: args
2021-11-18 22:05:49 +05:30
)
.execute
payload = result.payload
{
2023-03-04 22:38:38 +05:30
secret: payload[:secret],
token: payload[:token],
errors: Array.wrap(result.message)
2021-11-18 22:05:49 +05:30
}
end
private
def find_object(id:)
GitlabSchema.find_by_gid(id)
end
end
end
end
end