2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-14 23:37:51 -04:00
|
|
|
class Clusters::ApplicationsController < Clusters::BaseController
|
2017-11-02 10:10:46 -04:00
|
|
|
before_action :cluster
|
|
|
|
before_action :authorize_create_cluster!, only: [:create]
|
2019-02-18 12:06:51 -05:00
|
|
|
before_action :authorize_update_cluster!, only: [:update]
|
2017-11-02 10:10:46 -04:00
|
|
|
|
|
|
|
def create
|
2019-02-18 12:06:51 -05: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 05:02:45 -04:00
|
|
|
|
2017-11-06 12:21:10 -05:00
|
|
|
head :no_content
|
2019-02-18 12:06:51 -05:00
|
|
|
rescue Clusters::Applications::BaseService::InvalidApplicationError
|
2018-10-09 23:47:27 -04:00
|
|
|
render_404
|
2017-11-06 12:21:10 -05:00
|
|
|
rescue StandardError
|
|
|
|
head :bad_request
|
2017-11-02 10:10:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def cluster
|
2018-10-18 21:42:30 -04:00
|
|
|
@cluster ||= clusterable.clusters.find(params[:id]) || render_404
|
2017-11-02 10:10:46 -04:00
|
|
|
end
|
|
|
|
|
2019-02-18 12:06:51 -05:00
|
|
|
def cluster_application_params
|
2018-12-07 11:10:03 -05:00
|
|
|
params.permit(:application, :hostname, :email)
|
2018-05-24 11:11:30 -04:00
|
|
|
end
|
2017-11-02 10:10:46 -04:00
|
|
|
end
|