Welcome to mirror list, hosted at ThFree Co, Russian Federation.

applications_controller.rb « clusters « projects « controllers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 629e3d40c34c179be93fa861f9e248c111b85fd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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_initialize_by(cluster: @cluster)

    if application.has_attribute?(:hostname)
      application.hostname = params[:hostname]
    end

    if application.respond_to?(:oauth_application)
      application.oauth_application = create_oauth_application(application)
    end

    application.save!

    Clusters::Applications::ScheduleInstallationService.new(project, current_user).execute(application)

    head :no_content
  rescue StandardError => e
    Rails.logger.error("Request to install a cluster application failed: #{e.message}")
    head :bad_request
  end

  private

  def cluster
    @cluster ||= project.clusters.find(params[:id]) || render_404
  end

  def application_class
    @application_class ||= Clusters::Cluster::APPLICATIONS[params[:application]] || render_404
  end

  def create_oauth_application(application)
    oauth_application_params = {
      name: params[:application],
      redirect_uri: application.callback_url,
      scopes: 'api read_user openid',
      owner: current_user
    }

    Applications::CreateService.new(current_user, oauth_application_params).execute
  end
end