Skip to content

Commit

Permalink
[CLIENT] Cluster name is variable in cloud id
Browse files Browse the repository at this point in the history
  • Loading branch information
estolfo committed Jul 19, 2019
1 parent 07a48b3 commit 4962fda
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def perform_request(method, path, params={}, body=nil, headers=nil)

def extract_cloud_creds(arguments)
return unless arguments[:cloud_id]
cloud_url, elasticsearch_instance = Base64.decode64(arguments[:cloud_id].gsub('name:', '')).split('$')
name = arguments[:cloud_id].split(':')[0]
cloud_url, elasticsearch_instance = Base64.decode64(arguments[:cloud_id].gsub("#{name}:", '')).split('$')
[ { scheme: 'https',
user: arguments[:user],
password: arguments[:password],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,30 @@
expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elastic:changeme@abcd.localhost:9200')
end
end

context 'when the cluster has alternate names' do

let(:client) do
described_class.new(cloud_id: 'myCluster:bG9jYWxob3N0JGFiY2QkZWZnaA==', user: 'elasticfantastic', password: 'tobechanged')
end

let(:hosts) do
client.transport.hosts
end

it 'extracts the cloud credentials' do
expect(hosts[0][:host]).to eq('abcd.localhost')
expect(hosts[0][:protocol]).to eq('https')
expect(hosts[0][:user]).to eq('elasticfantastic')
expect(hosts[0][:password]).to eq('tobechanged')
expect(hosts[0][:port]).to eq(9243)
end

it 'creates the correct full url' do
expect(client.transport.__full_url(client.transport.hosts[0])).to eq('https://elasticfantastic:tobechanged@abcd.localhost:9243')
end

end
end

shared_examples_for 'a client that extracts hosts' do
Expand Down

0 comments on commit 4962fda

Please sign in to comment.