2018-10-14 23:37:51 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Clusters::BaseController < ApplicationController
|
|
|
|
include RoutableActions
|
|
|
|
|
|
|
|
skip_before_action :authenticate_user!
|
2022-01-27 19:14:06 -05:00
|
|
|
before_action :authorize_admin_cluster!, except: [:show, :index, :new, :authorize_aws_role, :update]
|
2018-10-14 23:37:51 -04:00
|
|
|
|
2018-10-30 06:33:43 -04:00
|
|
|
helper_method :clusterable
|
2018-10-18 21:42:30 -04:00
|
|
|
|
2020-10-05 17:08:47 -04:00
|
|
|
feature_category :kubernetes_management
|
2022-04-28 14:10:01 -04:00
|
|
|
urgency :low, [
|
|
|
|
:index, :show, :environments, :cluster_status, :prometheus_proxy,
|
|
|
|
:destroy, :new_cluster_docs, :connect, :new, :create_user
|
|
|
|
]
|
2020-10-05 17:08:47 -04:00
|
|
|
|
2018-10-14 23:37:51 -04:00
|
|
|
private
|
|
|
|
|
2018-10-31 20:39:01 -04:00
|
|
|
def cluster
|
|
|
|
@cluster ||= clusterable.clusters.find(params[:id])
|
|
|
|
.present(current_user: current_user)
|
2018-10-14 23:37:51 -04:00
|
|
|
end
|
|
|
|
|
2018-10-31 20:39:01 -04:00
|
|
|
def authorize_update_cluster!
|
2022-01-27 19:14:06 -05:00
|
|
|
access_denied! unless can?(current_user, :update_cluster, clusterable)
|
2018-10-14 23:37:51 -04:00
|
|
|
end
|
|
|
|
|
2018-10-31 20:39:01 -04:00
|
|
|
def authorize_admin_cluster!
|
2022-01-27 19:14:06 -05:00
|
|
|
access_denied! unless can?(current_user, :admin_cluster, clusterable)
|
2018-10-14 23:37:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_read_cluster!
|
|
|
|
access_denied! unless can?(current_user, :read_cluster, clusterable)
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_create_cluster!
|
|
|
|
access_denied! unless can?(current_user, :create_cluster, clusterable)
|
|
|
|
end
|
|
|
|
|
2019-09-07 04:24:33 -04:00
|
|
|
def authorize_read_prometheus!
|
|
|
|
access_denied! unless can?(current_user, :read_prometheus, clusterable)
|
|
|
|
end
|
|
|
|
|
2018-10-14 23:37:51 -04:00
|
|
|
def clusterable
|
2018-10-31 20:39:01 -04:00
|
|
|
raise NotImplementedError
|
2018-10-14 23:37:51 -04:00
|
|
|
end
|
|
|
|
end
|