debian-mirror-gitlab/app/controllers/projects/environments/prometheus_api_controller.rb

52 lines
1.1 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
class Projects::Environments::PrometheusApiController < Projects::ApplicationController
2019-12-21 20:55:43 +05:30
include RenderServiceResults
2019-07-07 11:18:12 +05:30
before_action :authorize_read_prometheus!
before_action :environment
def proxy
2020-01-01 13:55:28 +05:30
variable_substitution_result =
variable_substitution_service.new(environment, permit_params).execute
if variable_substitution_result[:status] == :error
return error_response(variable_substitution_result)
end
prometheus_result = Prometheus::ProxyService.new(
2019-07-07 11:18:12 +05:30
environment,
2019-07-31 22:56:46 +05:30
proxy_method,
proxy_path,
2020-01-01 13:55:28 +05:30
variable_substitution_result[:params]
2019-07-07 11:18:12 +05:30
).execute
2020-01-01 13:55:28 +05:30
return continue_polling_response if prometheus_result.nil?
return error_response(prometheus_result) if prometheus_result[:status] == :error
2019-12-21 20:55:43 +05:30
2020-01-01 13:55:28 +05:30
success_response(prometheus_result)
2019-07-07 11:18:12 +05:30
end
private
2020-01-01 13:55:28 +05:30
def variable_substitution_service
Prometheus::ProxyVariableSubstitutionService
end
def permit_params
params.permit!
2019-07-31 22:56:46 +05:30
end
2019-07-07 11:18:12 +05:30
def environment
@environment ||= project.environments.find(params[:id])
end
2019-07-31 22:56:46 +05:30
def proxy_method
request.method
end
def proxy_path
params[:proxy_path]
end
2019-07-07 11:18:12 +05:30
end