Merge branch 'master' of git.clinicalfuture.com:arvados
[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_all, :only => :ping
3
4   def self._ping_requires_parameters
5     {
6       uuid: false,
7       ping_secret: true,
8       node_uuid: false,
9       filesystem_uuid: false,
10       service_host: false,
11       service_port: true,
12       service_ssl_flag: true
13     }
14   end
15   def ping
16     if !@object
17       if current_user.andand.is_admin
18         @object = KeepDisk.new(filesystem_uuid: params[:filesystem_uuid])
19         @object.save!
20
21         # In the first ping from this new filesystem_uuid, we can't
22         # expect the keep node to know the ping_secret so we made sure
23         # we got an admin token. Here we add ping_secret to params so
24         # KeepNode.ping() understands this update is properly
25         # authenticated.
26         params[:ping_secret] = @object.ping_secret
27       else
28         return render_not_found "object not found"
29       end
30     end
31
32     params[:service_host] ||= request.env['REMOTE_ADDR']
33     if not @object.ping params
34       return render_not_found "object not found"
35     end
36     render json: @object.as_api_response(:superuser)
37   end
38
39   def find_objects_for_index
40     # all users can list all keep disks
41     @objects = model_class.where('1=1')
42     super
43   end
44 end