2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
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.
|
2019-07-07 11:18:12 +05:30
|
|
|
class BuildRunnerSession < ApplicationRecord
|
2018-11-08 19:23:39 +05:30
|
|
|
extend Gitlab::Ci::Model
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
TERMINAL_SUBPROTOCOL = 'terminal.gitlab.com'.freeze
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
self.table_name = 'ci_builds_runner_session'
|
|
|
|
|
|
|
|
belongs_to :build, class_name: 'Ci::Build', inverse_of: :runner_session
|
|
|
|
|
|
|
|
validates :build, presence: true
|
2019-07-31 22:56:46 +05:30
|
|
|
validates :url, addressable_url: { schemes: %w(https) }
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
def terminal_specification
|
2019-07-07 11:18:12 +05:30
|
|
|
wss_url = Gitlab::UrlHelpers.as_wss(self.url)
|
|
|
|
return {} unless wss_url.present?
|
|
|
|
|
|
|
|
wss_url = "#{wss_url}/exec"
|
|
|
|
channel_specification(wss_url, TERMINAL_SUBPROTOCOL)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def channel_specification(url, subprotocol)
|
|
|
|
return {} if subprotocol.blank? || url.blank?
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
{
|
2019-07-07 11:18:12 +05:30
|
|
|
subprotocols: Array(subprotocol),
|
|
|
|
url: url,
|
2018-11-18 11:00:15 +05:30
|
|
|
headers: { Authorization: [authorization.presence] }.compact,
|
2018-11-08 19:23:39 +05:30
|
|
|
ca_pem: certificate.presence
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|