Merge branch '0000-ruby-client-config'
[arvados.git] / services / api / app / controllers / arvados / v1 / keep_disks_controller.rb
index 0da729c79b6982886a0108ab3ed15c3168f66602..47018d4b10eb7ebc6ff27028b93de0e1aed8e84f 100644 (file)
@@ -1,5 +1,5 @@
 class Arvados::V1::KeepDisksController < ApplicationController
-  skip_before_filter :require_auth_scope_all, :only => :ping
+  skip_before_filter :require_auth_scope, :only => :ping
 
   def self._ping_requires_parameters
     {
@@ -12,28 +12,18 @@ class Arvados::V1::KeepDisksController < ApplicationController
       service_ssl_flag: true
     }
   end
-  def ping
-    if !@object
-      if current_user.andand.is_admin
-        @object = KeepDisk.new(filesystem_uuid: params[:filesystem_uuid])
-        @object.save!
 
-        # In the first ping from this new filesystem_uuid, we can't
-        # expect the keep node to know the ping_secret so we made sure
-        # we got an admin token. Here we add ping_secret to params so
-        # KeepNode.ping() understands this update is properly
-        # authenticated.
-        params[:ping_secret] = @object.ping_secret
-      else
+  def ping
+    params[:service_host] ||= request.env['REMOTE_ADDR']
+    act_as_system_user do
+      if not @object.ping params
         return render_not_found "object not found"
       end
+      # Render the :superuser view (i.e., include the ping_secret) even
+      # if !current_user.is_admin. This is safe because @object.ping's
+      # success implies the ping_secret was already known by the client.
+      render json: @object.as_api_response(:superuser)
     end
-
-    params[:service_host] ||= request.env['REMOTE_ADDR']
-    if not @object.ping params
-      return render_not_found "object not found"
-    end
-    render json: @object.as_api_response(:superuser)
   end
 
   def find_objects_for_index
@@ -41,4 +31,20 @@ class Arvados::V1::KeepDisksController < ApplicationController
     @objects = model_class.where('1=1')
     super
   end
+
+  def find_object_by_uuid
+    @object = KeepDisk.where(uuid: (params[:id] || params[:uuid])).first
+    if !@object && current_user.andand.is_admin
+      # Create a new KeepDisk and ping it.
+      @object = KeepDisk.new(filesystem_uuid: params[:filesystem_uuid])
+      @object.save!
+
+      # In the first ping from this new filesystem_uuid, we can't
+      # expect the keep node to know the ping_secret so we made sure
+      # we got an admin token. Here we add ping_secret to params so
+      # KeepNode.ping() understands this update is properly
+      # authenticated.
+      params[:ping_secret] = @object.ping_secret
+    end
+  end
 end