2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Projects
|
|
|
|
module Serverless
|
|
|
|
class FunctionsController < Projects::ApplicationController
|
2022-05-07 20:08:51 +05:30
|
|
|
before_action :ensure_feature_enabled!
|
2019-02-15 15:39:39 +05:30
|
|
|
before_action :authorize_read_cluster!
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
feature_category :not_owned # rubocop:todo Gitlab/AvoidFeatureCategoryNotOwned
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
def index
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2020-03-13 15:44:24 +05:30
|
|
|
functions = finder.execute.select do |function|
|
|
|
|
can?(@current_user, :read_cluster, function.cluster)
|
|
|
|
end
|
|
|
|
|
|
|
|
serialized_functions = serialize_function(functions)
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
render json: {
|
|
|
|
knative_installed: finder.knative_installed,
|
2020-03-13 15:44:24 +05:30
|
|
|
functions: serialized_functions
|
2019-09-04 21:01:54 +05:30
|
|
|
}.to_json
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
format.html do
|
|
|
|
render
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
def show
|
2020-03-13 15:44:24 +05:30
|
|
|
function = finder.service(params[:environment_id], params[:id])
|
|
|
|
return not_found unless function && can?(@current_user, :read_cluster, function.cluster)
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
@service = serialize_function(function)
|
2019-03-02 22:35:43 +05:30
|
|
|
return not_found if @service.nil?
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
@prometheus = finder.has_prometheus?(params[:environment_id])
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: @service
|
|
|
|
end
|
|
|
|
|
|
|
|
format.html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
def metrics
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
metrics = finder.invocation_metrics(params[:environment_id], params[:id])
|
|
|
|
|
|
|
|
if metrics.nil?
|
|
|
|
head :no_content
|
|
|
|
else
|
|
|
|
render json: metrics
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def finder
|
2019-07-07 11:18:12 +05:30
|
|
|
Projects::Serverless::FunctionsFinder.new(project)
|
2019-03-02 22:35:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def serialize_function(function)
|
|
|
|
Projects::Serverless::ServiceSerializer.new(current_user: @current_user, project: project).represent(function)
|
|
|
|
end
|
2022-05-07 20:08:51 +05:30
|
|
|
|
|
|
|
def ensure_feature_enabled!
|
|
|
|
render_404 unless Feature.enabled?(:deprecated_serverless, project, default_enabled: :yaml, type: :ops)
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|