Skip to content

Commit

Permalink
* Fix tests and logic for the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ag-ramachandran committed Dec 11, 2023
1 parent ce169a1 commit 63ee256
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/logstash/outputs/kusto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/logstash/outputs/kusto/ingestor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions spec/outputs/kusto/ingestor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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') }
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 63ee256

Please sign in to comment.