|
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
17 | 17 |
|
18 | | -require "cgi" |
19 | | -require "multi_json" |
20 | | - |
21 | | -require "elasticsearch/api/version" |
22 | | -require "elasticsearch/api/namespace/common" |
23 | | -require "elasticsearch/api/utils" |
| 18 | +require 'cgi' |
| 19 | +require 'multi_json' |
| 20 | +require 'elasticsearch/api/version' |
| 21 | +require 'elasticsearch/api/utils' |
24 | 22 | require 'elasticsearch/api/response' |
25 | 23 |
|
26 | | -Dir[ File.expand_path('../api/actions/**/*.rb', __FILE__) ].each { |f| require f } |
27 | | -Dir[ File.expand_path('../api/namespace/**/*.rb', __FILE__) ].each { |f| require f } |
| 24 | +Dir[File.expand_path('api/actions/**/*.rb', __dir__)].each { |f| require f } |
28 | 25 |
|
29 | 26 | module Elasticsearch |
30 | 27 | # This is the main module for including all API endpoint functions |
31 | 28 | # It includes the namespace modules from ./api/actions |
32 | 29 | module API |
| 30 | + include Elasticsearch::API::Actions |
33 | 31 | DEFAULT_SERIALIZER = MultiJson |
34 | 32 |
|
35 | 33 | HTTP_GET = 'GET'.freeze |
36 | 34 | HTTP_HEAD = 'HEAD'.freeze |
37 | 35 | HTTP_POST = 'POST'.freeze |
38 | 36 | HTTP_PUT = 'PUT'.freeze |
39 | 37 | HTTP_DELETE = 'DELETE'.freeze |
40 | | - UNDERSCORE_SEARCH = '_search'.freeze |
41 | | - UNDERSCORE_ALL = '_all'.freeze |
42 | | - DEFAULT_DOC = '_doc'.freeze |
43 | 38 |
|
44 | | - # Auto-include all namespaces in the receiver |
| 39 | + module CommonClient |
| 40 | + attr_reader :client |
| 41 | + |
| 42 | + def initialize(client) |
| 43 | + @client = client |
| 44 | + end |
| 45 | + |
| 46 | + def perform_request(method, path, params = {}, body = nil, headers = nil, request_opts = {}) |
| 47 | + client.perform_request(method, path, params, body, headers, request_opts) |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + # Add new namespaces to this constant |
45 | 52 | # |
46 | | - def self.included(base) |
47 | | - base.send :include, |
48 | | - Elasticsearch::API::Common, |
49 | | - Elasticsearch::API::Actions, |
50 | | - Elasticsearch::API::Cluster, |
51 | | - Elasticsearch::API::Nodes, |
52 | | - Elasticsearch::API::Indices, |
53 | | - Elasticsearch::API::Ingest, |
54 | | - Elasticsearch::API::Snapshot, |
55 | | - Elasticsearch::API::Tasks, |
56 | | - Elasticsearch::API::Cat, |
57 | | - Elasticsearch::API::Remote, |
58 | | - Elasticsearch::API::DanglingIndices, |
59 | | - Elasticsearch::API::Features, |
60 | | - Elasticsearch::API::AsyncSearch, |
61 | | - Elasticsearch::API::Autoscaling, |
62 | | - Elasticsearch::API::CrossClusterReplication, |
63 | | - Elasticsearch::API::DataFrameTransformDeprecated, |
64 | | - Elasticsearch::API::Enrich, |
65 | | - Elasticsearch::API::Eql, |
66 | | - Elasticsearch::API::Fleet, |
67 | | - Elasticsearch::API::Graph, |
68 | | - Elasticsearch::API::IndexLifecycleManagement, |
69 | | - Elasticsearch::API::License, |
70 | | - Elasticsearch::API::Logstash, |
71 | | - Elasticsearch::API::Migration, |
72 | | - Elasticsearch::API::MachineLearning, |
73 | | - Elasticsearch::API::SearchableSnapshots, |
74 | | - Elasticsearch::API::Security, |
75 | | - Elasticsearch::API::SnapshotLifecycleManagement, |
76 | | - Elasticsearch::API::SQL, |
77 | | - Elasticsearch::API::SSL, |
78 | | - Elasticsearch::API::TextStructure, |
79 | | - Elasticsearch::API::Transform, |
80 | | - Elasticsearch::API::Watcher, |
81 | | - Elasticsearch::API::XPack, |
82 | | - Elasticsearch::API::SearchApplication, |
83 | | - Elasticsearch::API::Synonyms, |
84 | | - Elasticsearch::API::Esql, |
85 | | - Elasticsearch::API::Inference, |
86 | | - Elasticsearch::API::Simulate, |
87 | | - Elasticsearch::API::Connector, |
88 | | - Elasticsearch::API::QueryRules |
| 53 | + API_NAMESPACES = %i[ |
| 54 | + async_search |
| 55 | + cat |
| 56 | + cluster |
| 57 | + connector |
| 58 | + cross_cluster_replication |
| 59 | + dangling_indices |
| 60 | + enrich |
| 61 | + eql |
| 62 | + esql |
| 63 | + features |
| 64 | + fleet |
| 65 | + graph |
| 66 | + index_lifecycle_management |
| 67 | + indices |
| 68 | + inference |
| 69 | + ingest |
| 70 | + license |
| 71 | + logstash |
| 72 | + machine_learning |
| 73 | + migration |
| 74 | + nodes |
| 75 | + query_rules |
| 76 | + sql |
| 77 | + ssl |
| 78 | + search_application |
| 79 | + searchable_snapshots |
| 80 | + security |
| 81 | + simulate |
| 82 | + snapshot |
| 83 | + snapshot_lifecycle_management |
| 84 | + synonyms |
| 85 | + tasks |
| 86 | + text_structure |
| 87 | + transform |
| 88 | + watcher |
| 89 | + xpack |
| 90 | + ].freeze |
| 91 | + UPPERCASE_APIS = %w[sql ssl].freeze |
| 92 | + |
| 93 | + API_NAMESPACES.each do |namespace| |
| 94 | + name = namespace.to_s |
| 95 | + module_name = if UPPERCASE_APIS.include?(name) |
| 96 | + name.upcase |
| 97 | + elsif name == 'xpack' |
| 98 | + 'XPack' |
| 99 | + else |
| 100 | + name.split('_').map(&:capitalize).join |
| 101 | + end |
| 102 | + class_name = "#{module_name}Client" |
| 103 | + |
| 104 | + klass = Class.new(Object) do |
| 105 | + include CommonClient, Object.const_get("Elasticsearch::API::#{module_name}::Actions") |
| 106 | + end |
| 107 | + Object.const_set(class_name, klass) |
| 108 | + define_method(name) do |
| 109 | + instance_variable_set("@#{name}", klass.new(self)) |
| 110 | + end |
89 | 111 | end |
90 | 112 |
|
| 113 | + alias ml machine_learning |
| 114 | + alias ilm index_lifecycle_management |
| 115 | + |
91 | 116 | # The serializer class |
92 | 117 | # |
93 | 118 | def self.serializer |
|
0 commit comments