8784: Fix test for latest firefox.
[arvados.git] / services / api / app / controllers / arvados / v1 / keep_disks_controller.rb
1 class Arvados::V1::KeepDisksController < ApplicationController
2   skip_before_filter :require_auth_scope, only: :ping
3   skip_before_filter :render_404_if_no_object, only: :ping
4
5   def self._ping_requires_parameters
6     {
7       uuid: {required: false},
8       ping_secret: {required: true},
9       node_uuid: {required: false},
10       filesystem_uuid: {required: false},
11       service_host: {required: false},
12       service_port: {required: true},
13       service_ssl_flag: {required: true}
14     }
15   end
16
17   def ping
18     params[:service_host] ||= request.env['REMOTE_ADDR']
19     if !params[:uuid] && current_user.andand.is_admin
20       # Create a new KeepDisk and ping it.
21       @object = KeepDisk.new(filesystem_uuid: params[:filesystem_uuid])
22       @object.save!
23
24       # In the first ping from this new filesystem_uuid, we can't
25       # expect the keep node to know the ping_secret so we made sure
26       # we got an admin token. Here we add ping_secret to params so
27       # the ping call below is properly authenticated.
28       params[:ping_secret] = @object.ping_secret
29     end
30     act_as_system_user do
31       if !@object.andand.ping(params)
32         return render_not_found "object not found"
33       end
34       # Render the :superuser view (i.e., include the ping_secret) even
35       # if !current_user.is_admin. This is safe because @object.ping's
36       # success implies the ping_secret was already known by the client.
37       send_json @object.as_api_response(:superuser)
38     end
39   end
40
41   def find_objects_for_index
42     # all users can list all keep disks
43     @objects = model_class.where('1=1')
44     super
45   end
46 end