summaryrefslogtreecommitdiff
path: root/qa/qa/resource/clusters/agent_token.rb
blob: 6d803b9456488e49612fb88d77f5e9551856817a (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
# frozen_string_literal: true

module QA
  module Resource
    module Clusters
      class AgentToken < QA::Resource::Base
        attribute :id
        attribute :secret
        attribute :agent do
          QA::Resource::Clusters::Agent.fabricate_via_api!
        end

        def fabricate!
          puts 'TODO: FABRICATE VIA UI'
        end

        def resource_web_url(resource)
          super
        rescue ResourceURLMissingError
          # this particular resource does not expose a web_url property
        end

        def api_get_path
          "gid://gitlab/Clusters::AgentToken/#{id}"
        end

        def api_post_path
          "/graphql"
        end

        def api_post_body
          <<~GQL
          mutation createToken {
            clusterAgentTokenCreate(input: { clusterAgentId: "gid://gitlab/Clusters::Agent/#{agent.id}" name: "token-#{agent.id}" }) {
              secret # This is the value you need to use on the next step
              token {
                createdAt
                id
              }
              errors
            }
          }
          GQL
        end
      end
    end
  end
end