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_read_auths
12 skip_before_action :load_where_param
13 skip_before_action :render_404_if_no_object
14 skip_before_action :require_auth_scope
19 expires_in 24.hours, public: true
20 send_json discovery_doc
26 Rails.cache.fetch 'arvados_v1_rest_discovery' do
27 Rails.application.eager_load!
29 Rails.configuration.RemoteClusters.each {|k,v| if k != :"*" then remoteHosts[k] = v["Host"] end }
31 kind: "discovery#restDescription",
32 discoveryVersion: "v1",
36 # format is YYYYMMDD, must be fixed with (needs to be linearly
37 # sortable), updated manually, may be used by clients to
38 # determine availability of API server features.
40 source_version: AppVersion.hash,
41 sourceVersion: AppVersion.hash, # source_version should be deprecated in the future
42 packageVersion: AppVersion.package_version,
43 generatedAt: db_current_time.iso8601,
45 description: "The API to interact with Arvados.",
46 documentationLink: "http://doc.arvados.org/api/index.html",
47 defaultCollectionReplication: Rails.configuration.Collections.DefaultReplication,
49 baseUrl: root_url + "arvados/v1/",
50 basePath: "/arvados/v1/",
52 servicePath: "arvados/v1/",
54 uuidPrefix: Rails.configuration.ClusterID,
55 defaultTrashLifetime: Rails.configuration.Collections.DefaultTrashLifetime,
56 blobSignatureTtl: Rails.configuration.Collections.BlobSigningTTL,
57 maxRequestSize: Rails.configuration.API.MaxRequestSize,
58 maxItemsPerResponse: Rails.configuration.API.MaxItemsPerResponse,
59 dockerImageFormats: Rails.configuration.Containers.SupportedDockerImageFormats.keys,
60 crunchLogBytesPerEvent: Rails.configuration.Containers.Logging.LogBytesPerEvent,
61 crunchLogSecondsBetweenEvents: Rails.configuration.Containers.Logging.LogSecondsBetweenEvents,
62 crunchLogThrottlePeriod: Rails.configuration.Containers.Logging.LogThrottlePeriod,
63 crunchLogThrottleBytes: Rails.configuration.Containers.Logging.LogThrottleBytes,
64 crunchLogThrottleLines: Rails.configuration.Containers.Logging.LogThrottleLines,
65 crunchLimitLogBytesPerJob: Rails.configuration.Containers.Logging.LimitLogBytesPerJob,
66 crunchLogPartialLineThrottlePeriod: Rails.configuration.Containers.Logging.LogPartialLineThrottlePeriod,
67 crunchLogUpdatePeriod: Rails.configuration.Containers.Logging.LogUpdatePeriod,
68 crunchLogUpdateSize: Rails.configuration.Containers.Logging.LogUpdateSize,
69 remoteHosts: remoteHosts,
70 remoteHostsViaDNS: Rails.configuration.RemoteClusters["*"].Proxy,
71 websocketUrl: Rails.configuration.Services.Websocket.ExternalURL.to_s,
72 workbenchUrl: Rails.configuration.Services.Workbench1.ExternalURL.to_s,
73 workbench2Url: Rails.configuration.Services.Workbench2.ExternalURL.to_s,
74 keepWebServiceUrl: Rails.configuration.Services.WebDAV.ExternalURL.to_s,
75 gitUrl: Rails.configuration.Services.GitHTTP.ExternalURL.to_s,
79 description: "Data format for the response.",
85 "Responses with Content-Type of application/json"
91 description: "Selector specifying which fields to include in a partial response.",
96 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.",
101 description: "OAuth 2.0 token for the current user.",
108 "https://api.curoverse.com/auth/arvados" => {
109 description: "View and manage objects"
111 "https://api.curoverse.com/auth/arvados.readonly" => {
112 description: "View objects"
121 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
123 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
125 # No controller -> no discovery.
128 object_properties = {}
130 select { |col| col.name != 'id' && !col.name.start_with?('secret_') }.
132 if k.serialized_attributes.has_key? col.name
133 object_properties[col.name] = {
134 type: k.serialized_attributes[col.name].object_class.to_s
136 elsif k.attribute_types[col.name].is_a? JsonbType::Hash
137 object_properties[col.name] = {
140 elsif k.attribute_types[col.name].is_a? JsonbType::Array
141 object_properties[col.name] = {
145 object_properties[col.name] = {
150 discovery[:schemas][k.to_s + 'List'] = {
152 description: k.to_s + ' list',
157 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
158 default: "arvados##{k.to_s.camelcase(:lower)}List"
162 description: "List version."
166 description: "The list of #{k.to_s.pluralize}.",
173 description: "A link to the next page of #{k.to_s.pluralize}."
177 description: "The page token for the next page of #{k.to_s.pluralize}."
181 description: "A link back to this list."
185 discovery[:schemas][k.to_s] = {
189 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
193 description: "Object ID."
197 description: "Object version."
199 }.merge(object_properties)
201 discovery[:resources][k.to_s.underscore.pluralize] = {
204 id: "arvados.#{k.to_s.underscore.pluralize}.get",
205 path: "#{k.to_s.underscore.pluralize}/{uuid}",
207 description: "Gets a #{k.to_s}'s metadata by UUID.",
211 description: "The UUID of the #{k.to_s} in question.",
223 "https://api.curoverse.com/auth/arvados",
224 "https://api.curoverse.com/auth/arvados.readonly"
228 id: "arvados.#{k.to_s.underscore.pluralize}.index",
229 path: k.to_s.underscore.pluralize,
232 %|Index #{k.to_s.pluralize}.
234 The <code>index</code> method returns a
235 <a href="/api/resources.html">resource list</a> of
236 matching #{k.to_s.pluralize}. For example:
240 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
243 "next_page_token":"",
248 "items_available":745,
250 "request_time":0.157236317
256 "$ref" => "#{k.to_s}List"
259 "https://api.curoverse.com/auth/arvados",
260 "https://api.curoverse.com/auth/arvados.readonly"
264 id: "arvados.#{k.to_s.underscore.pluralize}.create",
265 path: "#{k.to_s.underscore.pluralize}",
267 description: "Create a new #{k.to_s}.",
272 k.to_s.underscore => {
281 "https://api.curoverse.com/auth/arvados"
285 id: "arvados.#{k.to_s.underscore.pluralize}.update",
286 path: "#{k.to_s.underscore.pluralize}/{uuid}",
288 description: "Update attributes of an existing #{k.to_s}.",
292 description: "The UUID of the #{k.to_s} in question.",
300 k.to_s.underscore => {
309 "https://api.curoverse.com/auth/arvados"
313 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
314 path: "#{k.to_s.underscore.pluralize}/{uuid}",
315 httpMethod: "DELETE",
316 description: "Delete an existing #{k.to_s}.",
320 description: "The UUID of the #{k.to_s} in question.",
329 "https://api.curoverse.com/auth/arvados"
334 # Check for Rails routes that don't match the usual actions
336 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
337 Rails.application.routes.routes.each do |route|
338 action = route.defaults[:action]
339 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
340 method if route.verb.match(method)
343 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
344 ctl_class.action_methods.include? action
345 if !d_methods[action.to_sym]
347 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
348 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
349 httpMethod: httpMethod,
350 description: "#{action} #{k.to_s.underscore.pluralize}",
353 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
356 "https://api.curoverse.com/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[action.to_sym]
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[action.to_sym] = method
398 list_method = method.dup
399 list_method[:id].sub!('index', 'list')
400 list_method[:description].sub!('Index', 'List')
401 list_method[:description].sub!('index', 'list')
402 d_methods[:list] = list_method
408 discovery[:resources]['configs'] = {
411 id: "arvados.configs.get",
414 description: "Get public config",
422 "https://api.curoverse.com/auth/arvados",
423 "https://api.curoverse.com/auth/arvados.readonly"
429 Rails.configuration.API.DisabledAPIs.each do |method, _|
430 ctrl, action = method.to_s.split('.', 2)
431 discovery[:resources][ctrl][:methods].delete(action.to_sym)