gitlab-org--gitlab-foss/app/controllers/projects/serverless/functions_controller.rb

68 lines
1.5 KiB
Ruby
Raw Normal View History

2018-12-06 13:08:49 -05:00
# 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)
2018-12-06 13:08:49 -05:00
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]))
2019-04-05 22:02:39 -04:00
@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
2019-04-05 22:02:39 -04:00
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
2019-04-05 22:02:39 -04:00
Projects::Serverless::FunctionsFinder.new(project)
end
def serialize_function(function)
Projects::Serverless::ServiceSerializer.new(current_user: @current_user, project: project).represent(function)
end
2018-12-06 13:08:49 -05:00
end
end
end