2018-09-26 03:45:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-15 03:37:51 +00:00
|
|
|
class Clusters::ApplicationsController < Clusters::BaseController
|
2017-11-02 14:10:46 +00:00
|
|
|
before_action :cluster
|
|
|
|
before_action :authorize_create_cluster!, only: [:create]
|
2019-02-18 17:06:51 +00:00
|
|
|
before_action :authorize_update_cluster!, only: [:update]
|
2017-11-02 14:10:46 +00:00
|
|
|
|
|
|
|
def create
|
2019-02-18 17:06:51 +00:00
|
|
|
request_handler do
|
|
|
|
Clusters::Applications::CreateService
|
|
|
|
.new(@cluster, current_user, cluster_application_params)
|
|
|
|
.execute(request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
request_handler do
|
|
|
|
Clusters::Applications::UpdateService
|
|
|
|
.new(@cluster, current_user, cluster_application_params)
|
|
|
|
.execute(request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def request_handler
|
|
|
|
yield
|
2018-05-30 09:02:45 +00:00
|
|
|
|
2017-11-06 17:21:10 +00:00
|
|
|
head :no_content
|
2019-02-18 17:06:51 +00:00
|
|
|
rescue Clusters::Applications::BaseService::InvalidApplicationError
|
2018-10-10 03:47:27 +00:00
|
|
|
render_404
|
2017-11-06 17:21:10 +00:00
|
|
|
rescue StandardError
|
|
|
|
head :bad_request
|
2017-11-02 14:10:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def cluster
|
2018-10-19 01:42:30 +00:00
|
|
|
@cluster ||= clusterable.clusters.find(params[:id]) || render_404
|
2017-11-02 14:10:46 +00:00
|
|
|
end
|
|
|
|
|
2019-02-18 17:06:51 +00:00
|
|
|
def cluster_application_params
|
2018-12-07 16:10:03 +00:00
|
|
|
params.permit(:application, :hostname, :email)
|
2018-05-24 15:11:30 +00:00
|
|
|
end
|
2017-11-02 14:10:46 +00:00
|
|
|
end
|