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

73 lines
1.8 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
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
2019-02-15 15:39:39 +05:30
end
end
end