|
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::Rollup, |
74 | | - Elasticsearch::API::SearchableSnapshots, |
75 | | - Elasticsearch::API::Security, |
76 | | - Elasticsearch::API::SnapshotLifecycleManagement, |
77 | | - Elasticsearch::API::SQL, |
78 | | - Elasticsearch::API::SSL, |
79 | | - Elasticsearch::API::TextStructure, |
80 | | - Elasticsearch::API::Transform, |
81 | | - Elasticsearch::API::Watcher, |
82 | | - Elasticsearch::API::XPack, |
83 | | - Elasticsearch::API::SearchApplication, |
84 | | - Elasticsearch::API::Synonyms, |
85 | | - Elasticsearch::API::Esql, |
86 | | - Elasticsearch::API::Inference, |
87 | | - Elasticsearch::API::Simulate, |
88 | | - Elasticsearch::API::Connector, |
89 | | - Elasticsearch::API::QueryRules |
| 53 | + API_NAMESPACES = [:async_search, |
| 54 | + :cat, |
| 55 | + :cross_cluster_replication, |
| 56 | + :cluster, |
| 57 | + :connector, |
| 58 | + :dangling_indices, |
| 59 | + :enrich, |
| 60 | + :eql, |
| 61 | + :esql, |
| 62 | + :features, |
| 63 | + :fleet, |
| 64 | + :graph, |
| 65 | + :index_lifecycle_management, |
| 66 | + :indices, |
| 67 | + :inference, |
| 68 | + :ingest, |
| 69 | + :license, |
| 70 | + :logstash, |
| 71 | + :migration, |
| 72 | + :machine_learning, |
| 73 | + :nodes, |
| 74 | + :query_rules, |
| 75 | + :search_application, |
| 76 | + :searchable_snapshots, |
| 77 | + :security, |
| 78 | + :simulate, |
| 79 | + :snapshot_lifecycle_management, |
| 80 | + :snapshot, |
| 81 | + :sql, |
| 82 | + :ssl, |
| 83 | + :synonyms, |
| 84 | + :tasks, |
| 85 | + :text_structure, |
| 86 | + :transform, |
| 87 | + :watcher, |
| 88 | + :xpack].freeze |
| 89 | + |
| 90 | + UPPERCASE_APIS = ['sql', 'ssl'].freeze |
| 91 | + API_NAMESPACES.each do |namespace| |
| 92 | + name = namespace.to_s |
| 93 | + module_name = if UPPERCASE_APIS.include?(name) |
| 94 | + name.upcase |
| 95 | + elsif name == 'xpack' |
| 96 | + 'XPack' |
| 97 | + else |
| 98 | + name.split('_').map(&:capitalize).join |
| 99 | + end |
| 100 | + class_name = "#{module_name}Client" |
| 101 | + |
| 102 | + klass = Class.new(Object) do |
| 103 | + include CommonClient, Object.const_get("Elasticsearch::API::#{module_name}::Actions") |
| 104 | + end |
| 105 | + Object.const_set(class_name, klass) |
| 106 | + define_method(name) do |
| 107 | + instance_variable_set("@#{name}", klass.new(self)) |
| 108 | + end |
90 | 109 | end |
91 | 110 |
|
| 111 | + alias ml machine_learning |
| 112 | + alias ilm index_lifecycle_management |
| 113 | + |
92 | 114 | # The serializer class |
93 | 115 | # |
94 | 116 | def self.serializer |
|
0 commit comments