Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create.rb « agent_tokens « clusters « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a99a54fa5edabb2304a924c06c550861d5f1930f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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(
              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

        private

        def find_object(id:)
          GitlabSchema.find_by_gid(id)
        end
      end
    end
  end
end