Add 'apps/arv-web/' from commit 'f9732ad8460d013c2f28363655d0d1b91894dca5'
[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
4   def self._ping_requires_parameters
5     {
6       uuid: {required: false},
7       ping_secret: {required: true},
8       node_uuid: {required: false},
9       filesystem_uuid: {required: false},
10       service_host: {required: false},
11       service_port: {required: true},
12       service_ssl_flag: {required: true}
13     }
14   end
15
16   def ping
17     params[:service_host] ||= request.env['REMOTE_ADDR']
18     act_as_system_user do
19       if not @object.ping params
20         return render_not_found "object not found"
21       end
22       # Render the :superuser view (i.e., include the ping_secret) even
23       # if !current_user.is_admin. This is safe because @object.ping's
24       # success implies the ping_secret was already known by the client.
25       render json: @object.as_api_response(:superuser)
26     end
27   end
28
29   def find_objects_for_index
30     # all users can list all keep disks
31     @objects = model_class.where('1=1')
32     super
33   end
34
35   def find_object_by_uuid
36     @object = KeepDisk.where(uuid: (params[:id] || params[:uuid])).first
37     if !@object && current_user.andand.is_admin
38       # Create a new KeepDisk and ping it.
39       @object = KeepDisk.new(filesystem_uuid: params[:filesystem_uuid])
40       @object.save!
41
42       # In the first ping from this new filesystem_uuid, we can't
43       # expect the keep node to know the ping_secret so we made sure
44       # we got an admin token. Here we add ping_secret to params so
45       # KeepNode.ping() understands this update is properly
46       # authenticated.
47       params[:ping_secret] = @object.ping_secret
48     end
49   end
50 end