gitlab-org--gitlab-foss/app/controllers/projects/serverless/functions_controller.rb
James Edwards-Jones bedb9a3e6d Avoid passing not_found_or_authorized_proc around
Since this needs to be called on every find_routable!(Project, ...
we can instead move it to a RoutableActions check.
2019-05-15 17:36:50 +07:00

67 lines
1.5 KiB
Ruby

# frozen_string_literal: true
module Projects
module Serverless
class FunctionsController < Projects::ApplicationController
before_action :authorize_read_cluster!
def index
respond_to do |format|
format.json do
functions = finder.execute
if functions.any?
render json: serialize_function(functions)
else
head :no_content
end
end
format.html do
@installed = finder.installed?
render
end
end
end
def show
@service = serialize_function(finder.service(params[:environment_id], params[:id]))
@prometheus = finder.has_prometheus?(params[:environment_id])
return not_found if @service.nil?
respond_to do |format|
format.json do
render json: @service
end
format.html
end
end
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
private
def finder
Projects::Serverless::FunctionsFinder.new(project)
end
def serialize_function(function)
Projects::Serverless::ServiceSerializer.new(current_user: @current_user, project: project).represent(function)
end
end
end
end