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?
|
2018-12-17 02:31:38 -05:00
|
|
|
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
|
2018-12-17 02:31:38 -05:00
|
|
|
|
|
|
|
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])
|
|
|
|
|
2018-12-17 02:31:38 -05:00
|
|
|
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
|
|
|
|
|
2018-12-17 02:31:38 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def finder
|
2019-04-05 22:02:39 -04:00
|
|
|
Projects::Serverless::FunctionsFinder.new(project)
|
2018-12-17 02:31:38 -05:00
|
|
|
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
|