Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions x-pack/lib/license_checker/license_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

require 'logstash/logging/logger'
require 'logstash/outputs/elasticsearch'
require 'logstash/json'
require 'json'

module LogStash
module LicenseChecker
Expand All @@ -17,8 +15,7 @@ class LicenseReader
def initialize(settings, feature, options)
@namespace = "xpack.#{feature}"
@settings = settings
@es_options = options
@es_options.merge!("resurrect_delay" => 30)
@es_options = options.merge('resurrect_delay' => 30)
end

##
Expand Down Expand Up @@ -62,8 +59,10 @@ def client
# # log originate from the `ElasticsearchSource`
def build_client
es = LogStash::Outputs::ElasticSearch.new(@es_options)
new_logger = logger
es.instance_eval { @logger = new_logger }
es.instance_variable_set :@logger, logger
es.fill_hosts_from_cloud_id
es.fill_user_password_from_cloud_auth
es.setup_hosts
es.build_client
end

Expand Down
37 changes: 32 additions & 5 deletions x-pack/spec/license_checker/license_reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
# you may not use this file except in compliance with the Elastic License.

require "spec_helper"
require "logstash/json"
require 'support/helpers'
require "license_checker/license_reader"
require "helpers/elasticsearch_options"
require "monitoring/monitoring"
require "stud/temporary"


describe LogStash::LicenseChecker::LicenseReader do
let(:elasticsearch_url) { ["https://localhost:9898"] }
let(:elasticsearch_url) { "https://localhost:9898" }
let(:elasticsearch_username) { "elastictest" }
let(:elasticsearch_password) { "testchangeme" }
let(:extension) { LogStash::MonitoringExtension.new }
Expand All @@ -25,7 +23,7 @@
let(:settings) do
{
"xpack.monitoring.enabled" => true,
"xpack.monitoring.elasticsearch.hosts" => elasticsearch_url,
"xpack.monitoring.elasticsearch.hosts" => [ elasticsearch_url ],
"xpack.monitoring.elasticsearch.username" => elasticsearch_username,
"xpack.monitoring.elasticsearch.password" => elasticsearch_password,
}
Expand Down Expand Up @@ -101,4 +99,33 @@
end
end
end

it "builds ES client" do
expect( subject.client.options[:hosts].size ).to eql 1
expect( subject.client.options[:hosts][0].to_s ).to eql elasticsearch_url # URI#to_s
expect( subject.client.options ).to include(:user => elasticsearch_username, :password => elasticsearch_password)
end

context 'with cloud_id' do
let(:cloud_id) do
'westeurope-1:d2VzdGV1cm9wZS5henVyZS5lbGFzdGljLWNsb3VkLmNvbTo5MjQzJGUxZTYzMTIwMWZiNjRkNTVhNzVmNDMxZWI2MzQ5NTg5JDljYzYwMGUwMGQwYjRhMThiNmY2NmU2ZTcyMTQwODA3'
end
let(:cloud_auth) do
'elastic:LnWMLeK3EQPTf3G3F1IBdFvO'
end

let(:settings) do
{
"xpack.monitoring.enabled" => true,
"xpack.monitoring.elasticsearch.cloud_id" => cloud_id,
"xpack.monitoring.elasticsearch.cloud_auth" => cloud_auth
}
end

it "builds ES client" do
expect( subject.client.options[:hosts].size ).to eql 1
expect( subject.client.options[:hosts][0].to_s ).to eql 'https://e1e631201fb64d55a75f431eb6349589.westeurope.azure.elastic-cloud.com:9243'
expect( subject.client.options ).to include(:user => 'elastic', :password => 'LnWMLeK3EQPTf3G3F1IBdFvO')
end
end
end