diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2019-04-04 21:32:02 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-04-04 21:32:02 +0300 |
commit | 8a134f4c6505c4f8f3c89e0ae4d4ea2293765be3 (patch) | |
tree | 910dce4df7fd61af86a9f282f52fcc72ff056975 /app | |
parent | 465f82e32cd1ca7c87ca7553e350af4c52b00805 (diff) |
Renamed terminal_specification to channel_specification
We're moving from using terminology related to terminals when
we refer to Websockets connections in Workhorse.
It's more appropiate a concept like channel.
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/environments_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/projects/jobs_controller.rb | 2 | ||||
-rw-r--r-- | app/models/ci/build_runner_session.rb | 18 |
3 files changed, 17 insertions, 5 deletions
diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index 4fa6cd94ae5..301449cfa90 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -117,7 +117,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController terminal = environment.terminals.try(:first) if terminal set_workhorse_internal_api_content_type - render json: Gitlab::Workhorse.terminal_websocket(terminal) + render json: Gitlab::Workhorse.channel_websocket(terminal) else render html: 'Not found', status: :not_found end diff --git a/app/controllers/projects/jobs_controller.rb b/app/controllers/projects/jobs_controller.rb index 35cc32d3e63..2a4933e7bc2 100644 --- a/app/controllers/projects/jobs_controller.rb +++ b/app/controllers/projects/jobs_controller.rb @@ -157,7 +157,7 @@ class Projects::JobsController < Projects::ApplicationController # GET .../terminal.ws : implemented in gitlab-workhorse def terminal_websocket_authorize set_workhorse_internal_api_content_type - render json: Gitlab::Workhorse.terminal_websocket(@build.terminal_specification) + render json: Gitlab::Workhorse.channel_websocket(@build.terminal_specification) end private diff --git a/app/models/ci/build_runner_session.rb b/app/models/ci/build_runner_session.rb index 061eff090f5..80dbb150085 100644 --- a/app/models/ci/build_runner_session.rb +++ b/app/models/ci/build_runner_session.rb @@ -6,6 +6,8 @@ module Ci class BuildRunnerSession < ApplicationRecord extend Gitlab::Ci::Model + TERMINAL_SUBPROTOCOL = 'terminal.gitlab.com'.freeze + self.table_name = 'ci_builds_runner_session' belongs_to :build, class_name: 'Ci::Build', inverse_of: :runner_session @@ -14,11 +16,21 @@ module Ci validates :url, url: { protocols: %w(https) } def terminal_specification - return {} unless url.present? + 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? { - subprotocols: ['terminal.gitlab.com'].freeze, - url: "#{url}/exec".sub("https://", "wss://"), + subprotocols: Array(subprotocol), + url: url, headers: { Authorization: [authorization.presence] }.compact, ca_pem: certificate.presence } |