diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-01-24 17:52:50 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-01-24 17:52:50 +0100 |
commit | 3cd17c9430c7575b0c1f1041947f3cd0d991f00c (patch) | |
tree | 12638383d600ae6d5c8cbf6c27da7bdb2199f5e7 /app/controllers/projects/environments_controller.rb | |
parent | 8faabdf7d33b575de11b043cfe6698021d33a973 (diff) | |
parent | 8c0e358a972ca9cb2176ff9289a5a89b0c909a93 (diff) | |
download | gitlab-ce-3cd17c9430c7575b0c1f1041947f3cd0d991f00c.tar.gz |
Merge remote-tracking branch 'origin/master' into 24147-delete-env-button
Diffstat (limited to 'app/controllers/projects/environments_controller.rb')
-rw-r--r-- | app/controllers/projects/environments_controller.rb | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index bc66823dfc4..a203efc62b8 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -4,17 +4,22 @@ class Projects::EnvironmentsController < Projects::ApplicationController before_action :authorize_create_environment!, only: [:new, :create] before_action :authorize_create_deployment!, only: [:stop] before_action :authorize_update_environment!, only: [:edit, :update] - before_action :environment, only: [:show, :edit, :update, :stop] + before_action :authorize_admin_environment!, only: [:terminal, :terminal_websocket_authorize] + before_action :environment, only: [:show, :edit, :update, :stop, :terminal, :terminal_websocket_authorize] + before_action :verify_api_request!, only: :terminal_websocket_authorize def index @scope = params[:scope] - @all_environments = project.environments - @environments = - if @scope == 'stopped' - @all_environments.stopped - else - @all_environments.available + @environments = project.environments + + respond_to do |format| + format.html + format.json do + render json: EnvironmentSerializer + .new(project: @project, user: current_user) + .represent(@environments) end + end end def show @@ -57,8 +62,33 @@ class Projects::EnvironmentsController < Projects::ApplicationController end end + def terminal + # Currently, this acts as a hint to load the terminal details into the cache + # if they aren't there already. In the future, users will need these details + # to choose between terminals to connect to. + @terminals = environment.terminals + end + + # GET .../terminal.ws : implemented in gitlab-workhorse + def terminal_websocket_authorize + # Just return the first terminal for now. If the list is in the process of + # being looked up, this may result in a 404 response, so the frontend + # should retry those errors + terminal = environment.terminals.try(:first) + if terminal + set_workhorse_internal_api_content_type + render json: Gitlab::Workhorse.terminal_websocket(terminal) + else + render text: 'Not found', status: 404 + end + end + private + def verify_api_request! + Gitlab::Workhorse.verify_api_request!(request.headers) + end + def environment_params params.require(:environment).permit(:name, :external_url) end |