2018-08-03 03:15:25 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-05 09:55:10 -04:00
|
|
|
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-03-28 09:17:42 -04:00
|
|
|
class BuildRunnerSession < ApplicationRecord
|
2018-07-05 09:55:10 -04:00
|
|
|
extend Gitlab::Ci::Model
|
|
|
|
|
2019-08-31 15:57:00 -04:00
|
|
|
TERMINAL_SUBPROTOCOL = 'terminal.gitlab.com'
|
2019-04-04 14:32:02 -04:00
|
|
|
|
2018-07-05 09:55:10 -04:00
|
|
|
self.table_name = 'ci_builds_runner_session'
|
|
|
|
|
|
|
|
belongs_to :build, class_name: 'Ci::Build', inverse_of: :runner_session
|
|
|
|
|
|
|
|
validates :build, presence: true
|
2019-04-11 02:29:07 -04:00
|
|
|
validates :url, addressable_url: { schemes: %w(https) }
|
2018-07-05 09:55:10 -04:00
|
|
|
|
|
|
|
def terminal_specification
|
2019-04-04 14:32:02 -04:00
|
|
|
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-07-05 09:55:10 -04:00
|
|
|
|
|
|
|
{
|
2019-04-04 14:32:02 -04:00
|
|
|
subprotocols: Array(subprotocol),
|
|
|
|
url: url,
|
2018-07-24 08:05:48 -04:00
|
|
|
headers: { Authorization: [authorization.presence] }.compact,
|
2018-07-05 09:55:10 -04:00
|
|
|
ca_pem: certificate.presence
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Ci::BuildRunnerSession.prepend_if_ee('EE::Ci::BuildRunnerSession')
|