summaryrefslogtreecommitdiff
path: root/app/models/ci/build_runner_session.rb
blob: 457d7eeab6a88968092ec3b4d5806244e8ed6633 (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
# frozen_string_literal: true

module Ci
  # The purpose of this class is to store Build related runner session.
  # Data will be removed after transitioning from running to any state.
  class BuildRunnerSession < ActiveRecord::Base
    extend Gitlab::Ci::Model

    self.table_name = 'ci_builds_runner_session'

    belongs_to :build, class_name: 'Ci::Build', inverse_of: :runner_session

    validates :build, presence: true
    validates :url, url: { protocols: %w(https) }

    def terminal_specification
      return {} unless url.present?

      {
        subprotocols: ['terminal.gitlab.com'].freeze,
        url: "#{url}/exec".sub("https://", "wss://"),
        headers: { Authorization: [authorization.presence] }.compact,
        ca_pem: certificate.presence
      }
    end
  end
end