2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Clusters::ApplicationsController < Clusters::BaseController
|
|
|
|
before_action :cluster
|
|
|
|
before_action :authorize_create_cluster!, only: [:create]
|
2019-07-07 11:18:12 +05:30
|
|
|
before_action :authorize_update_cluster!, only: [:update]
|
2019-07-31 22:56:46 +05:30
|
|
|
before_action :authorize_admin_cluster!, only: [:destroy]
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
def create
|
2019-07-07 11:18:12 +05:30
|
|
|
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
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
def destroy
|
|
|
|
request_handler do
|
|
|
|
Clusters::Applications::DestroyService
|
|
|
|
.new(@cluster, current_user, cluster_application_destroy_params)
|
|
|
|
.execute(request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def request_handler
|
|
|
|
yield
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
head :no_content
|
2019-07-07 11:18:12 +05:30
|
|
|
rescue Clusters::Applications::BaseService::InvalidApplicationError
|
2018-12-13 13:39:08 +05:30
|
|
|
render_404
|
|
|
|
rescue StandardError
|
|
|
|
head :bad_request
|
|
|
|
end
|
|
|
|
|
|
|
|
def cluster
|
|
|
|
@cluster ||= clusterable.clusters.find(params[:id]) || render_404
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
def cluster_application_params
|
2020-04-22 19:07:51 +05:30
|
|
|
params.permit(:application, :hostname, :pages_domain_id, :email, :stack, :modsecurity_enabled, :modsecurity_mode, :host, :port, :protocol)
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
def cluster_application_destroy_params
|
|
|
|
params.permit(:application)
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|