Merge branch 'master' into 10293-cwl-cr-output
[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 lock
28     @object.lock
29     show
30   end
31
32   def unlock
33     @object.unlock
34     show
35   end
36
37   def current
38     if Thread.current[:api_client_authorization].nil?
39       send_error("Not logged in", status: 401)
40     else
41       c = Container.where(auth_uuid: Thread.current[:api_client_authorization].uuid).first
42       if c.nil?
43         send_error("Token is not associated with a container.", status: 404)
44       else
45         @object = c
46         show
47       end
48     end
49   end
50 end