Skip to content

Commit 4962fda

Browse files
committed
[CLIENT] Cluster name is variable in cloud id
1 parent 07a48b3 commit 4962fda

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

elasticsearch-transport/lib/elasticsearch/transport/client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ def perform_request(method, path, params={}, body=nil, headers=nil)
169169

170170
def extract_cloud_creds(arguments)
171171
return unless arguments[:cloud_id]
172-
cloud_url, elasticsearch_instance = Base64.decode64(arguments[:cloud_id].gsub('name:', '')).split('$')
172+
name = arguments[:cloud_id].split(':')[0]
173+
cloud_url, elasticsearch_instance = Base64.decode64(arguments[:cloud_id].gsub("#{name}:", '')).split('$')
173174
[ { scheme: 'https',
174175
user: arguments[:user],
175176
password: arguments[:password],

elasticsearch-transport/spec/elasticsearch/transport/client_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,30 @@
310310
expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elastic:changeme@abcd.localhost:9200')
311311
end
312312
end
313+
314+
context 'when the cluster has alternate names' do
315+
316+
let(:client) do
317+
described_class.new(cloud_id: 'myCluster:bG9jYWxob3N0JGFiY2QkZWZnaA==', user: 'elasticfantastic', password: 'tobechanged')
318+
end
319+
320+
let(:hosts) do
321+
client.transport.hosts
322+
end
323+
324+
it 'extracts the cloud credentials' do
325+
expect(hosts[0][:host]).to eq('abcd.localhost')
326+
expect(hosts[0][:protocol]).to eq('https')
327+
expect(hosts[0][:user]).to eq('elasticfantastic')
328+
expect(hosts[0][:password]).to eq('tobechanged')
329+
expect(hosts[0][:port]).to eq(9243)
330+
end
331+
332+
it 'creates the correct full url' do
333+
expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elasticfantastic:tobechanged@abcd.localhost:9243')
334+
end
335+
336+
end
313337
end
314338

315339
shared_examples_for 'a client that extracts hosts' do

0 commit comments

Comments
 (0)