3 class Arvados::V1::CollectionsController < ApplicationController
5 if resource_attrs[:uuid] and (loc = Keep::Locator.parse(resource_attrs[:uuid]))
6 resource_attrs[:portable_data_hash] = loc.to_s
7 resource_attrs.delete :uuid
12 def find_object_by_uuid
13 if loc = Keep::Locator.parse(params[:id])
15 if c = Collection.readable_by(*@read_users).where({ portable_data_hash: loc.to_s }).limit(1).first
17 uuid: c.portable_data_hash,
18 portable_data_hash: c.portable_data_hash,
19 manifest_text: c.manifest_text,
29 sign_manifests(@object[:manifest_text])
30 if @object.is_a? Collection
31 render json: @object.as_api_response
38 sign_manifests(*@objects.map { |c| c[:manifest_text] })
42 def script_param_edges(visited, sp)
46 script_param_edges(visited, v)
50 script_param_edges(visited, v)
54 if loc = Keep::Locator.parse(sp)
55 search_edges(visited, loc.to_s, :search_up)
60 def search_edges(visited, uuid, direction)
61 if uuid.nil? or uuid.empty? or visited[uuid]
65 if loc = Keep::Locator.parse(uuid)
67 return if visited[loc.to_s]
70 logger.debug "visiting #{uuid}"
73 # uuid is a portable_data_hash
74 if c = Collection.readable_by(*@read_users).where(portable_data_hash: loc.to_s).limit(1).first
76 portable_data_hash: c.portable_data_hash,
80 if direction == :search_up
81 # Search upstream for jobs where this locator is the output of some job
82 Job.readable_by(*@read_users).where(output: loc.to_s).each do |job|
83 search_edges(visited, job.uuid, :search_up)
86 Job.readable_by(*@read_users).where(log: loc.to_s).each do |job|
87 search_edges(visited, job.uuid, :search_up)
89 elsif direction == :search_down
90 if loc.to_s == "d41d8cd98f00b204e9800998ecf8427e+0"
91 # Special case, don't follow the empty collection.
95 # Search downstream for jobs where this locator is in script_parameters
96 Job.readable_by(*@read_users).where(["jobs.script_parameters like ?", "%#{loc.to_s}%"]).each do |job|
97 search_edges(visited, job.uuid, :search_down)
101 # uuid is a regular Arvados UUID
102 rsc = ArvadosModel::resource_class_for_uuid uuid
104 Job.readable_by(*@read_users).where(uuid: uuid).each do |job|
105 visited[uuid] = job.as_api_response
106 if direction == :search_up
107 # Follow upstream collections referenced in the script parameters
108 script_param_edges(visited, job.script_parameters)
109 elsif direction == :search_down
110 # Follow downstream job output
111 search_edges(visited, job.output, direction)
114 elsif rsc == Collection
115 if c = Collection.readable_by(*@read_users).where(uuid: uuid).limit(1).first
116 search_edges(visited, c.portable_data_hash, direction)
117 visited[c.portable_data_hash] = c.as_api_response
120 rsc.where(uuid: uuid).each do |r|
121 visited[uuid] = r.as_api_response
126 if direction == :search_up
127 # Search for provenance links pointing to the current uuid
128 Link.readable_by(*@read_users).
129 where(head_uuid: uuid, link_class: "provenance").
131 visited[link.uuid] = link.as_api_response
132 search_edges(visited, link.tail_uuid, direction)
134 elsif direction == :search_down
135 # Search for provenance links emanating from the current uuid
136 Link.readable_by(current_user).
137 where(tail_uuid: uuid, link_class: "provenance").
139 visited[link.uuid] = link.as_api_response
140 search_edges(visited, link.head_uuid, direction)
147 search_edges(visited, @object[:uuid] || @object[:portable_data_hash], :search_up)
153 search_edges(visited, @object[:uuid] || @object[:portable_data_hash], :search_down)
160 if action_name == 'index'
161 # Omit manifest_text from index results unless expressly selected.
162 @select ||= model_class.api_accessible_attributes(:user).
163 map { |attr_spec| attr_spec.first.to_s } - ["manifest_text"]
168 def sign_manifests(*manifests)
169 if current_api_client_authorization
171 key: Rails.configuration.blob_signing_key,
172 api_token: current_api_client_authorization.api_token,
173 ttl: Rails.configuration.blob_signing_ttl,
175 manifests.each do |text|
176 Collection.munge_manifest_locators(text) do |loc|
177 Blob.sign_locator(loc.to_s, signing_opts)