+
+ def find_usable_token(token_list)
+ # Iterate over every given token to make it the current token and
+ # yield the given block.
+ # If the block succeeds, return the token it used.
+ # Otherwise, render an error response based on the most specific
+ # error we encounter, and return nil.
+ most_specific_error = [401]
+ token_list.each do |api_token|
+ begin
+ using_specific_api_token(api_token) do
+ yield
+ return api_token
+ end
+ rescue ArvadosApiClient::ApiError => error
+ if error.api_status >= most_specific_error.first
+ most_specific_error = [error.api_status, error]
+ end
+ end
+ end
+ case most_specific_error.shift
+ when 401, 403
+ redirect_to_login
+ when 404
+ render_not_found(*most_specific_error)
+ end
+ return nil
+ end
+
+ def file_enumerator(opts)
+ FileStreamer.new opts
+ end
+