diff --git a/lib/logstash/outputs/kusto.rb b/lib/logstash/outputs/kusto.rb index dfc244a..e916fb0 100755 --- a/lib/logstash/outputs/kusto.rb +++ b/lib/logstash/outputs/kusto.rb @@ -155,7 +155,7 @@ def register max_queue: upload_queue_size, fallback_policy: :caller_runs) - @ingestor = Ingestor.new(ingest_url, app_id, app_key, app_tenant, managed_identity, database, table, final_mapping, delete_temp_files, proxy_host, proxy_port,proxy_protocol, @logger, executor) + @ingestor = Ingestor.new(ingest_url, app_id, app_key, app_tenant, managed_identity, database, table, final_mapping, delete_temp_files, proxy_host, proxy_port, proxy_protocol, proxy_aad_only, @logger, executor) # send existing files recover_past_files if recovery diff --git a/lib/logstash/outputs/kusto/ingestor.rb b/lib/logstash/outputs/kusto/ingestor.rb index d61bbab..3a8dcab 100755 --- a/lib/logstash/outputs/kusto/ingestor.rb +++ b/lib/logstash/outputs/kusto/ingestor.rb @@ -52,7 +52,7 @@ def initialize(ingest_url, app_id, app_key, app_tenant, managed_identity_id, dat ## TODO : this needs work!!!!! write one more if else when uploading and work on it if it is expired if use_access_token @logger.info('Using proxy for AAD only, switching to accessToken authentication') - kusto_java.data.auth.ConnectionStringBuilder.createWithAadAccessTokenAuthentication(ingest_url,) + kusto_java.data.auth.ConnectionStringBuilder.createWithAadAccessTokenAuthentication(ingest_url,'') else @logger.info('Using AAD authentication') kusto_java.data.auth.ConnectionStringBuilder.createWithAadApplicationCredentials(ingest_url, app_id, app_key.value, app_tenant) @@ -91,7 +91,8 @@ def initialize(ingest_url, app_id, app_key, app_tenant, managed_identity_id, dat def validate_config(database, table, json_mapping, proxy_protocol, app_id, app_key, managed_identity_id) # Add an additional validation and fail this upfront - if app_id.nil? && app_key.nil? && managed_identity_id.nil? + is_managed_identity = (app_id.nil? || app_id.empty?) && (app_key.nil? || app_key.empty?) + if is_managed_identity && (managed_identity_id.nil? || managed_identity_id.empty?) @logger.error('managed_identity_id is not provided and app_id/app_key is empty.') raise LogStash::ConfigurationError.new('managed_identity_id is not provided and app_id/app_key is empty.') end diff --git a/spec/outputs/kusto/ingestor_spec.rb b/spec/outputs/kusto/ingestor_spec.rb index cc0263c..997e97d 100755 --- a/spec/outputs/kusto/ingestor_spec.rb +++ b/spec/outputs/kusto/ingestor_spec.rb @@ -15,6 +15,7 @@ let(:proxy_host) { "localhost" } let(:proxy_port) { 80 } let(:proxy_protocol) { "http" } + let(:proxy_aad_only) { false } let(:json_mapping) { "mymapping" } let(:delete_local) { false } let(:logger) { spy('logger') } @@ -25,7 +26,7 @@ # note that this will cause an internal error since connection is being tried. # however we still want to test that all the java stuff is working as expected expect { - ingestor = described_class.new(ingest_url, app_id, app_key, app_tenant, managed_identity, database, table, json_mapping, delete_local, proxy_host, proxy_port,proxy_protocol, logger) + ingestor = described_class.new(ingest_url, app_id, app_key, app_tenant, managed_identity, database, table, json_mapping, delete_local, proxy_host, proxy_port,proxy_protocol, proxy_aad_only, logger) ingestor.stop }.not_to raise_error end @@ -36,7 +37,7 @@ dynamic_name_array.each do |test_database| it "with database: #{test_database}" do expect { - ingestor = described_class.new(ingest_url, app_id, app_key, app_tenant, managed_identity, test_database, table, json_mapping, delete_local, proxy_host, proxy_port,proxy_protocol,logger) + ingestor = described_class.new(ingest_url, app_id, app_key, app_tenant, managed_identity, test_database, table, json_mapping, delete_local, proxy_host, proxy_port,proxy_protocol, proxy_aad_only, logger) ingestor.stop }.to raise_error(LogStash::ConfigurationError) end @@ -47,7 +48,7 @@ dynamic_name_array.each do |test_table| it "with database: #{test_table}" do expect { - ingestor = described_class.new(ingest_url, app_id, app_key, app_tenant, managed_identity,database, test_table, json_mapping, delete_local, proxy_host, proxy_port,proxy_protocol,logger) + ingestor = described_class.new(ingest_url, app_id, app_key, app_tenant, managed_identity,database, test_table, json_mapping, delete_local, proxy_host, proxy_port,proxy_protocol, proxy_aad_only,logger) ingestor.stop }.to raise_error(LogStash::ConfigurationError) end @@ -58,7 +59,7 @@ dynamic_name_array.each do |json_mapping| it "with database: #{json_mapping}" do expect { - ingestor = described_class.new(ingest_url, app_id, app_key, app_tenant, managed_identity,database, table, json_mapping, delete_local, proxy_host, proxy_port,proxy_protocol,logger) + ingestor = described_class.new(ingest_url, app_id, app_key, app_tenant, managed_identity,database, table, json_mapping, delete_local, proxy_host, proxy_port,proxy_protocol, proxy_aad_only,logger) ingestor.stop }.to raise_error(LogStash::ConfigurationError) end @@ -68,7 +69,7 @@ context 'proxy protocol has to be http or https' do it "with proxy protocol: socks" do expect { - ingestor = described_class.new(ingest_url, app_id, app_key, app_tenant, managed_identity,database, table, json_mapping, delete_local, proxy_host, proxy_port,'socks',logger) + ingestor = described_class.new(ingest_url, app_id, app_key, app_tenant, managed_identity,database, table, json_mapping, delete_local, proxy_host, proxy_port,'socks', proxy_aad_only,logger) ingestor.stop }.to raise_error(LogStash::ConfigurationError) end @@ -77,7 +78,7 @@ context 'one of appid or managedid has to be provided' do it "with empty managed identity and appid" do expect { - ingestor = described_class.new(ingest_url, "", app_key, app_tenant, "",database, table, json_mapping, delete_local, proxy_host, proxy_port,'socks',logger) + ingestor = described_class.new(ingest_url, "", "", app_tenant, "", database, table, json_mapping, delete_local, proxy_host, proxy_port,'https', proxy_aad_only,logger) ingestor.stop }.to raise_error(LogStash::ConfigurationError) end