Merge branch '21762-flaky-search-test'
[arvados.git] / services / api / app / controllers / arvados / v1 / management_controller.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class Arvados::V1::ManagementController < ApplicationController
6   skip_before_action :catch_redirect_hint
7   skip_before_action :find_objects_for_index
8   skip_before_action :find_object_by_uuid
9   skip_before_action :load_filters_param
10   skip_before_action :load_limit_offset_order_params
11   skip_before_action :load_select_param
12   skip_before_action :load_read_auths
13   skip_before_action :load_where_param
14   skip_before_action :render_404_if_no_object
15   skip_before_action :require_auth_scope
16
17   before_action :check_auth_header
18
19   def check_auth_header
20     mgmt_token = Rails.configuration.ManagementToken
21     auth_header = request.headers['Authorization']
22
23     if mgmt_token == ""
24       send_json ({"errors" => "disabled"}), status: 404
25     elsif !auth_header
26       send_json ({"errors" => "authorization required"}), status: 401
27     elsif auth_header != 'Bearer '+mgmt_token
28       send_json ({"errors" => "authorization error"}), status: 403
29     end
30   end
31
32   def metrics
33     render content_type: 'text/plain', plain: <<~EOF
34 # HELP arvados_config_load_timestamp_seconds Time when config file was loaded.
35 # TYPE arvados_config_load_timestamp_seconds gauge
36 arvados_config_load_timestamp_seconds{sha256="#{Rails.configuration.SourceSHA256}"} #{Rails.configuration.LoadTimestamp.to_f}
37 # HELP arvados_config_source_timestamp_seconds Timestamp of config file when it was loaded.
38 # TYPE arvados_config_source_timestamp_seconds gauge
39 arvados_config_source_timestamp_seconds{sha256="#{Rails.configuration.SourceSHA256}"} #{Rails.configuration.SourceTimestamp.to_f}
40 # HELP arvados_version_running Indicated version is running.
41 # TYPE arvados_version_running gauge
42 arvados_version_running{version="#{AppVersion.package_version}"} 1
43 EOF
44   end
45
46   def health
47     case params[:check]
48     when 'ping'
49       resp = {"health" => "OK"}
50       send_json resp
51     else
52       send_json ({"errors" => "not found"}), status: 404
53     end
54   end
55 end