File tree Expand file tree Collapse file tree 2 files changed +56
-3
lines changed
lib/elasticsearch/transport
spec/elasticsearch/transport Expand file tree Collapse file tree 2 files changed +56
-3
lines changed Original file line number Diff line number Diff line change @@ -190,17 +190,25 @@ def set_api_key
190
190
end
191
191
192
192
def extract_cloud_creds ( arguments )
193
- return unless arguments [ :cloud_id ]
193
+ return unless arguments [ :cloud_id ] && ! arguments [ :cloud_id ] . empty?
194
194
195
195
name = arguments [ :cloud_id ] . split ( ':' ) [ 0 ]
196
196
cloud_url , elasticsearch_instance = Base64 . decode64 ( arguments [ :cloud_id ] . gsub ( "#{ name } :" , '' ) ) . split ( '$' )
197
+
198
+ if cloud_url . include? ( ':' )
199
+ url , port = cloud_url . split ( ':' )
200
+ host = "#{ elasticsearch_instance } .#{ url } "
201
+ else
202
+ host = "#{ elasticsearch_instance } .#{ cloud_url } "
203
+ port = arguments [ :port ] || DEFAULT_CLOUD_PORT
204
+ end
197
205
[
198
206
{
199
207
scheme : 'https' ,
200
208
user : arguments [ :user ] ,
201
209
password : arguments [ :password ] ,
202
- host : " #{ elasticsearch_instance } . #{ cloud_url } " ,
203
- port : arguments [ : port] || DEFAULT_CLOUD_PORT
210
+ host : host ,
211
+ port : port . to_i
204
212
}
205
213
]
206
214
end
Original file line number Diff line number Diff line change 433
433
) . to eq ( 'https://elasticfantastic:[email protected] :9243' )
434
434
end
435
435
end
436
+
437
+ context 'when the cloud host provides a port' do
438
+ let ( :client ) do
439
+ described_class . new (
440
+ cloud_id : 'name:ZWxhc3RpY19zZXJ2ZXI6OTI0MyRlbGFzdGljX2lk' ,
441
+ user : 'elastic' ,
442
+ password : 'changeme'
443
+ )
444
+ end
445
+
446
+ let ( :hosts ) do
447
+ client . transport . hosts
448
+ end
449
+
450
+ it 'creates the correct full url' do
451
+ expect ( hosts [ 0 ] [ :host ] ) . to eq ( 'elastic_id.elastic_server' )
452
+ expect ( hosts [ 0 ] [ :protocol ] ) . to eq ( 'https' )
453
+ expect ( hosts [ 0 ] [ :user ] ) . to eq ( 'elastic' )
454
+ expect ( hosts [ 0 ] [ :password ] ) . to eq ( 'changeme' )
455
+ expect ( hosts [ 0 ] [ :port ] ) . to eq ( 9243 )
456
+ end
457
+ end
458
+
459
+ context 'when the cloud host provides a port and the port is also specified' do
460
+ let ( :client ) do
461
+ described_class . new (
462
+ cloud_id : 'name:ZWxhc3RpY19zZXJ2ZXI6OTI0MyRlbGFzdGljX2lk' ,
463
+ user : 'elastic' ,
464
+ password : 'changeme' ,
465
+ port : 9200
466
+ )
467
+ end
468
+
469
+ let ( :hosts ) do
470
+ client . transport . hosts
471
+ end
472
+
473
+ it 'creates the correct full url' do
474
+ expect ( hosts [ 0 ] [ :host ] ) . to eq ( 'elastic_id.elastic_server' )
475
+ expect ( hosts [ 0 ] [ :protocol ] ) . to eq ( 'https' )
476
+ expect ( hosts [ 0 ] [ :user ] ) . to eq ( 'elastic' )
477
+ expect ( hosts [ 0 ] [ :password ] ) . to eq ( 'changeme' )
478
+ expect ( hosts [ 0 ] [ :port ] ) . to eq ( 9243 )
479
+ end
480
+ end
436
481
end
437
482
438
483
shared_examples_for 'a client that extracts hosts' do
You can’t perform that action at this time.
0 commit comments