Skip to content

Commit b9c08c2

Browse files
committed
[API] Refactors namespace and requiring API code
Based on the code written in the Elasticsearch Serverless client, this change makes the creation of the namespace clients dynamic, removing all the files that were under `namespace` before. Some outdated and deprecated code was removed too, like unnecessary namespaces.
1 parent 4cc6d8f commit b9c08c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+68
-1542
lines changed

elasticsearch-api/lib/elasticsearch/api.rb

Lines changed: 68 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -37,55 +37,76 @@ module API
3737
HTTP_POST = 'POST'.freeze
3838
HTTP_PUT = 'PUT'.freeze
3939
HTTP_DELETE = 'DELETE'.freeze
40-
UNDERSCORE_SEARCH = '_search'.freeze
41-
UNDERSCORE_ALL = '_all'.freeze
42-
DEFAULT_DOC = '_doc'.freeze
4340

44-
# Auto-include all namespaces in the receiver
41+
module CommonClient
42+
attr_reader :client
43+
44+
def initialize(client)
45+
@client = client
46+
end
47+
48+
def perform_request(method, path, params = {}, body = nil, headers = nil, request_opts = {})
49+
client.perform_request(method, path, params, body, headers, request_opts)
50+
end
51+
end
52+
53+
# Add new namespaces to this constant
4554
#
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
55+
API_NAMESPACES = [
56+
:async_search,
57+
:cat,
58+
:cluster,
59+
:common,
60+
:connector,
61+
:cross_cluster_replication, :dangling_indices,
62+
:enrich,
63+
:eql, :esql, :features, :fleet,
64+
:graph,
65+
:index_lifecycle_management,
66+
:indices,
67+
:inference,
68+
:ingest,
69+
:license,
70+
:logstash,
71+
:machine_learning,
72+
:migration,
73+
:nodes,
74+
:query_rules,
75+
:sql,
76+
:ssl,
77+
:search_application,
78+
:searchable_snapshots,
79+
:security,
80+
:simulate,
81+
:snapshot,
82+
:snapshot_lifecycle_management,
83+
:synonyms,
84+
:tasks,
85+
:text_structure,
86+
:transform,
87+
:watcher,
88+
:xpack
89+
].freeze
90+
UPPERCASE_APIS = ['sql', 'ssl'].freeze
91+
92+
API_NAMESPACES.each do |namespace|
93+
name = namespace.to_s
94+
module_name = if UPPERCASE_APIS.include?(name)
95+
name.upcase
96+
elsif name == 'xpack'
97+
'XPack'
98+
else
99+
name.split('_').map(&:capitalize).join
100+
end
101+
class_name = "#{module_name}Client"
102+
103+
klass = Class.new(Object) do
104+
include CommonClient, Object.const_get("Elasticsearch::API::#{module_name}::Actions")
105+
end
106+
Object.const_set(class_name, klass)
107+
define_method(name) do
108+
instance_variable_set("@#{name}", klass.new(self))
109+
end
89110
end
90111

91112
# The serializer class

elasticsearch-api/lib/elasticsearch/api/namespace/async_search.rb

Lines changed: 0 additions & 36 deletions
This file was deleted.

elasticsearch-api/lib/elasticsearch/api/namespace/autoscaling.rb

Lines changed: 0 additions & 36 deletions
This file was deleted.

elasticsearch-api/lib/elasticsearch/api/namespace/cat.rb

Lines changed: 0 additions & 36 deletions
This file was deleted.

elasticsearch-api/lib/elasticsearch/api/namespace/cluster.rb

Lines changed: 0 additions & 37 deletions
This file was deleted.

elasticsearch-api/lib/elasticsearch/api/namespace/common.rb

Lines changed: 0 additions & 42 deletions
This file was deleted.

elasticsearch-api/lib/elasticsearch/api/namespace/connector.rb

Lines changed: 0 additions & 36 deletions
This file was deleted.

elasticsearch-api/lib/elasticsearch/api/namespace/cross_cluster_replication.rb

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)