gitlab-org--gitlab-foss/app/controllers/projects/clusters/applications_controller.rb

28 lines
846 B
Ruby
Raw Normal View History

2017-11-02 10:10:46 -04:00
class Projects::Clusters::ApplicationsController < Projects::ApplicationController
before_action :cluster
before_action :application_class, only: [:create]
before_action :authorize_read_cluster!
before_action :authorize_create_cluster!, only: [:create]
def create
application = @application_class.find_or_create_by!(cluster: @cluster)
application.update(hostname: params[:hostname]) if application.respond_to?(:hostname)
Clusters::Applications::ScheduleInstallationService.new(project, current_user).execute(application)
head :no_content
rescue StandardError
head :bad_request
2017-11-02 10:10:46 -04:00
end
private
def cluster
2017-11-02 10:31:25 -04:00
@cluster ||= project.clusters.find(params[:id]) || render_404
2017-11-02 10:10:46 -04:00
end
def application_class
@application_class ||= Clusters::Cluster::APPLICATIONS[params[:application]] || render_404
2017-11-02 10:10:46 -04:00
end
end