8784: Fix test for latest firefox.
[arvados.git] / services / api / app / controllers / arvados / v1 / containers_controller.rb
1 class Arvados::V1::ContainersController < ApplicationController
2   accept_attribute_as_json :environment, Hash
3   accept_attribute_as_json :mounts, Hash
4   accept_attribute_as_json :runtime_constraints, Hash
5   accept_attribute_as_json :command, Array
6   accept_attribute_as_json :scheduling_parameters, Hash
7
8   skip_before_filter :find_object_by_uuid, only: [:current]
9   skip_before_filter :render_404_if_no_object, only: [:current]
10
11   def auth
12     if @object.locked_by_uuid != Thread.current[:api_client_authorization].uuid
13       raise ArvadosModel::PermissionDeniedError.new("Not locked by your token")
14     end
15     @object = @object.auth
16     show
17   end
18
19   # Updates use row locking to resolve races between multiple
20   # dispatchers trying to lock the same container.
21   def update
22     @object.with_lock do
23       super
24     end
25   end
26
27   def find_objects_for_index
28     super
29     if action_name == 'lock' || action_name == 'unlock'
30       # Avoid loading more fields than we need
31       @objects = @objects.select(:id, :uuid, :state, :priority, :auth_uuid, :locked_by_uuid)
32       @select = %w(uuid state priority auth_uuid locked_by_uuid)
33     end
34   end
35
36   def lock
37     @object.lock
38     show
39   end
40
41   def unlock
42     @object.unlock
43     show
44   end
45
46   def current
47     if Thread.current[:api_client_authorization].nil?
48       send_error("Not logged in", status: 401)
49     else
50       c = Container.where(auth_uuid: Thread.current[:api_client_authorization].uuid).first
51       if c.nil?
52         send_error("Token is not associated with a container.", status: 404)
53       else
54         @object = c
55         show
56       end
57     end
58   end
59 end