debian-mirror-gitlab/app/controllers/projects/serverless/functions_controller.rb

66 lines
1.5 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# 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
2019-09-04 21:01:54 +05:30
render json: {
knative_installed: finder.knative_installed,
functions: serialize_function(functions)
}.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
@service = serialize_function(finder.service(params[:environment_id], params[:id]))
2019-07-07 11:18:12 +05:30
@prometheus = finder.has_prometheus?(params[:environment_id])
2019-03-02 22:35:43 +05:30
return not_found if @service.nil?
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
2019-02-15 15:39:39 +05:30
end
end
end