1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class Arvados::V1::SchemaController < ApplicationController
6 skip_before_action :catch_redirect_hint
7 skip_before_action :find_objects_for_index
8 skip_before_action :find_object_by_uuid
9 skip_before_action :load_filters_param
10 skip_before_action :load_limit_offset_order_params
11 skip_before_action :load_select_param
12 skip_before_action :load_read_auths
13 skip_before_action :load_where_param
14 skip_before_action :render_404_if_no_object
15 skip_before_action :require_auth_scope
20 expires_in 24.hours, public: true
21 send_json discovery_doc
27 'destroy' => 'delete',
33 Rails.application.eager_load!
35 Rails.configuration.RemoteClusters.each {|k,v| if k != :"*" then remoteHosts[k] = v["Host"] end }
37 kind: "discovery#restDescription",
38 discoveryVersion: "v1",
42 # format is YYYYMMDD, must be fixed width (needs to be lexically
43 # sortable), updated manually, may be used by clients to
44 # determine availability of API server features.
46 source_version: AppVersion.hash,
47 sourceVersion: AppVersion.hash, # source_version should be deprecated in the future
48 packageVersion: AppVersion.package_version,
49 generatedAt: db_current_time.iso8601,
51 description: "The API to interact with Arvados.",
52 documentationLink: "http://doc.arvados.org/api/index.html",
53 defaultCollectionReplication: Rails.configuration.Collections.DefaultReplication,
55 baseUrl: root_url + "arvados/v1/",
56 basePath: "/arvados/v1/",
58 servicePath: "arvados/v1/",
60 uuidPrefix: Rails.configuration.ClusterID,
61 defaultTrashLifetime: Rails.configuration.Collections.DefaultTrashLifetime,
62 blobSignatureTtl: Rails.configuration.Collections.BlobSigningTTL,
63 maxRequestSize: Rails.configuration.API.MaxRequestSize,
64 maxItemsPerResponse: Rails.configuration.API.MaxItemsPerResponse,
65 dockerImageFormats: Rails.configuration.Containers.SupportedDockerImageFormats.keys,
66 crunchLogUpdatePeriod: Rails.configuration.Containers.Logging.LogUpdatePeriod,
67 crunchLogUpdateSize: Rails.configuration.Containers.Logging.LogUpdateSize,
68 remoteHosts: remoteHosts,
69 remoteHostsViaDNS: Rails.configuration.RemoteClusters["*"].Proxy,
70 websocketUrl: Rails.configuration.Services.Websocket.ExternalURL.to_s,
71 workbenchUrl: Rails.configuration.Services.Workbench1.ExternalURL.to_s,
72 workbench2Url: Rails.configuration.Services.Workbench2.ExternalURL.to_s,
73 keepWebServiceUrl: Rails.configuration.Services.WebDAV.ExternalURL.to_s,
77 description: "Data format for the response.",
83 "Responses with Content-Type of application/json"
89 description: "Selector specifying which fields to include in a partial response.",
94 description: "API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.",
99 description: "OAuth 2.0 token for the current user.",
106 "https://api.arvados.org/auth/arvados" => {
107 description: "View and manage objects"
109 "https://api.arvados.org/auth/arvados.readonly" => {
110 description: "View objects"
119 ActiveRecord::Base.descendants.reject(&:abstract_class?).sort_by(&:to_s).each do |k|
121 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
123 # No controller -> no discovery.
126 object_properties = {}
128 select { |col| k.selectable_attributes.include? col.name }.
130 if k.serialized_attributes.has_key? col.name
131 object_properties[col.name] = {
132 type: k.serialized_attributes[col.name].object_class.to_s
134 elsif k.attribute_types[col.name].is_a? JsonbType::Hash
135 object_properties[col.name] = {
138 elsif k.attribute_types[col.name].is_a? JsonbType::Array
139 object_properties[col.name] = {
143 object_properties[col.name] = {
148 discovery[:schemas][k.to_s + 'List'] = {
150 description: k.to_s + ' list',
155 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
156 default: "arvados##{k.to_s.camelcase(:lower)}List"
160 description: "List version."
164 description: "The list of #{k.to_s.pluralize}.",
171 description: "A link to the next page of #{k.to_s.pluralize}."
175 description: "The page token for the next page of #{k.to_s.pluralize}."
179 description: "A link back to this list."
183 discovery[:schemas][k.to_s] = {
187 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
191 description: "Object ID."
195 description: "Object version."
197 }.merge(object_properties)
199 discovery[:resources][k.to_s.underscore.pluralize] = {
202 id: "arvados.#{k.to_s.underscore.pluralize}.get",
203 path: "#{k.to_s.underscore.pluralize}/{uuid}",
205 description: "Gets a #{k.to_s}'s metadata by UUID.",
209 description: "The UUID of the #{k.to_s} in question.",
221 "https://api.arvados.org/auth/arvados",
222 "https://api.arvados.org/auth/arvados.readonly"
226 id: "arvados.#{k.to_s.underscore.pluralize}.list",
227 path: k.to_s.underscore.pluralize,
230 %|List #{k.to_s.pluralize}.
232 The <code>list</code> method returns a
233 <a href="/api/resources.html">resource list</a> of
234 matching #{k.to_s.pluralize}. For example:
238 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
241 "next_page_token":"",
246 "items_available":745,
248 "request_time":0.157236317
254 "$ref" => "#{k.to_s}List"
257 "https://api.arvados.org/auth/arvados",
258 "https://api.arvados.org/auth/arvados.readonly"
262 id: "arvados.#{k.to_s.underscore.pluralize}.create",
263 path: "#{k.to_s.underscore.pluralize}",
265 description: "Create a new #{k.to_s}.",
270 k.to_s.underscore => {
279 "https://api.arvados.org/auth/arvados"
283 id: "arvados.#{k.to_s.underscore.pluralize}.update",
284 path: "#{k.to_s.underscore.pluralize}/{uuid}",
286 description: "Update attributes of an existing #{k.to_s}.",
290 description: "The UUID of the #{k.to_s} in question.",
298 k.to_s.underscore => {
307 "https://api.arvados.org/auth/arvados"
311 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
312 path: "#{k.to_s.underscore.pluralize}/{uuid}",
313 httpMethod: "DELETE",
314 description: "Delete an existing #{k.to_s}.",
318 description: "The UUID of the #{k.to_s} in question.",
327 "https://api.arvados.org/auth/arvados"
332 # Check for Rails routes that don't match the usual actions
334 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
335 Rails.application.routes.routes.each do |route|
336 action = route.defaults[:action]
337 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
338 method if route.verb.match(method)
341 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize &&
342 ctl_class.action_methods.include?(action)
343 method_name = ActionNameMap[action] || action
344 method_key = method_name.to_sym
345 if !d_methods[method_key]
347 id: "arvados.#{k.to_s.underscore.pluralize}.#{method_name}",
348 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
349 httpMethod: httpMethod,
350 description: "#{method_name} #{k.to_s.underscore.pluralize}",
353 "$ref" => (method_name == 'list' ? "#{k.to_s}List" : k.to_s)
356 "https://api.arvados.org/auth/arvados"
359 route.segment_keys.each do |key|
361 key = :uuid if key == :id
362 method[:parameters][key] = {
371 # We already built a generic method description, but we
372 # might find some more required parameters through
374 method = d_methods[method_key]
376 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
377 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |l, v|
379 method[:parameters][l] = v
381 method[:parameters][l] = {}
383 if !method[:parameters][l][:default].nil?
384 # The JAVA SDK is sensitive to all values being strings
385 method[:parameters][l][:default] = method[:parameters][l][:default].to_s
387 method[:parameters][l][:type] ||= 'string'
388 method[:parameters][l][:description] ||= ''
389 method[:parameters][l][:location] = (route.segment_keys.include?(l) ? 'path' : 'query')
390 if method[:parameters][l][:required].nil?
391 method[:parameters][l][:required] = v != false
395 d_methods[method_key] = method
400 # The 'replace_files' option is implemented in lib/controller,
401 # not Rails -- we just need to add it here so discovery-aware
402 # clients know how to validate it.
403 [:create, :update].each do |action|
404 discovery[:resources]['collections'][:methods][action][:parameters]['replace_files'] = {
406 description: 'Files and directories to initialize/replace with content from other collections.',
410 additionalProperties: {type: 'string'},
414 discovery[:resources]['configs'] = {
417 id: "arvados.configs.get",
420 description: "Get public config",
428 "https://api.arvados.org/auth/arvados",
429 "https://api.arvados.org/auth/arvados.readonly"
435 discovery[:resources]['vocabularies'] = {
438 id: "arvados.vocabularies.get",
441 description: "Get vocabulary definition",
449 "https://api.arvados.org/auth/arvados",
450 "https://api.arvados.org/auth/arvados.readonly"
456 discovery[:resources]['sys'] = {
459 id: "arvados.sys.trash_sweep",
460 path: "sys/trash_sweep",
462 description: "apply scheduled trash and delete operations",
470 "https://api.arvados.org/auth/arvados",
471 "https://api.arvados.org/auth/arvados.readonly"
477 Rails.configuration.API.DisabledAPIs.each do |method, _|
478 ctrl, action = method.to_s.split('.', 2)
479 next if ctrl.in?(['job_tasks', 'jobs', 'keep_disks', 'nodes', 'pipeline_instances', 'pipeline_templates', 'repositories'])
480 discovery[:resources][ctrl][:methods].delete(action.to_sym)