Merge branch 'master' into 2290-user-activity
[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     params[:service_host] ||= request.env['REMOTE_ADDR']
17     if not @object.ping params
18       return render_not_found "object not found"
19     end
20     # Render the :superuser view (i.e., include the ping_secret) even
21     # if !current_user.is_admin. This is safe because @object.ping's
22     # success implies the ping_secret was already known by the client.
23     render json: @object.as_api_response(:superuser)
24   end
25
26   def find_objects_for_index
27     # all users can list all keep disks
28     @objects = model_class.where('1=1')
29     super
30   end
31
32   def find_object_by_uuid
33     @object = KeepDisk.where(uuid: (params[:id] || params[:uuid])).first
34     if !@object && current_user.andand.is_admin
35       # Create a new KeepDisk and ping it.
36       @object = KeepDisk.new(filesystem_uuid: params[:filesystem_uuid])
37       @object.save!
38
39       # In the first ping from this new filesystem_uuid, we can't
40       # expect the keep node to know the ping_secret so we made sure
41       # we got an admin token. Here we add ping_secret to params so
42       # KeepNode.ping() understands this update is properly
43       # authenticated.
44       params[:ping_secret] = @object.ping_secret
45     end
46   end
47 end