fluent-plugin-kusto 0.0.1.beta → 0.0.2.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +260 -57
- data/lib/fluent/plugin/auth/mi_tokenprovider.rb +7 -6
- data/lib/fluent/plugin/auth/wif_tokenprovider.rb +4 -0
- data/lib/fluent/plugin/conffile.rb +1 -1
- data/lib/fluent/plugin/ingester.rb +5 -3
- data/lib/fluent/plugin/out_kusto.rb +5 -3
- data/test/plugin/e2e_kusto.rb +862 -0
- data/test/plugin/test_e2e_kusto.rb +295 -42
- data/test/plugin/test_mi_tokenprovider.rb +155 -0
- data/test/plugin/test_wif_tokenprovider.rb +136 -0
- metadata +40 -17
@@ -0,0 +1,136 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mocha/test_unit'
|
5
|
+
require_relative '../../lib/fluent/plugin/auth/wif_tokenprovider'
|
6
|
+
|
7
|
+
class DummyConfigForWIF
|
8
|
+
attr_reader :kusto_endpoint, :workload_identity_client_id, :workload_identity_tenant_id, :workload_identity_token_file_path
|
9
|
+
|
10
|
+
def initialize(kusto_endpoint, client_id, tenant_id, token_file_path = nil)
|
11
|
+
@kusto_endpoint = kusto_endpoint
|
12
|
+
@workload_identity_client_id = client_id
|
13
|
+
@workload_identity_tenant_id = tenant_id
|
14
|
+
@workload_identity_token_file_path = token_file_path
|
15
|
+
end
|
16
|
+
|
17
|
+
def logger
|
18
|
+
require 'logger'
|
19
|
+
Logger.new($stdout)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class WorkloadIdentityTest < Test::Unit::TestCase
|
24
|
+
def setup
|
25
|
+
@resource = 'https://kusto.kusto.windows.net'
|
26
|
+
@client_id = '074c3c54-29e2-4230-a81f-333868b8d6ca'
|
27
|
+
@tenant_id = '12345678-1234-1234-1234-123456789abc'
|
28
|
+
@token_file = '/tmp/test-token'
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_initialize_with_custom_token_file
|
32
|
+
config = DummyConfigForWIF.new(@resource, @client_id, @tenant_id, @token_file)
|
33
|
+
provider = WorkloadIdentity.new(config)
|
34
|
+
|
35
|
+
# Verify instance variables are set correctly
|
36
|
+
assert_equal @resource, provider.instance_variable_get(:@kusto_endpoint)
|
37
|
+
assert_equal @client_id, provider.instance_variable_get(:@client_id)
|
38
|
+
assert_equal @tenant_id, provider.instance_variable_get(:@tenant_id)
|
39
|
+
assert_equal @token_file, provider.instance_variable_get(:@token_file)
|
40
|
+
assert_equal "#{@resource}/.default", provider.instance_variable_get(:@scope)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_initialize_with_default_token_file
|
44
|
+
config = DummyConfigForWIF.new(@resource, @client_id, @tenant_id, nil)
|
45
|
+
provider = WorkloadIdentity.new(config)
|
46
|
+
|
47
|
+
# Verify default token file is used
|
48
|
+
expected_default = '/var/run/secrets/azure/tokens/azure-identity-token'
|
49
|
+
assert_equal expected_default, provider.instance_variable_get(:@token_file)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_fetch_token_success
|
53
|
+
config = DummyConfigForWIF.new(@resource, @client_id, @tenant_id, @token_file)
|
54
|
+
provider = WorkloadIdentity.new(config)
|
55
|
+
|
56
|
+
# Mock successful token acquisition
|
57
|
+
mock_response = {
|
58
|
+
'access_token' => 'wif-access-token',
|
59
|
+
'expires_in' => 7200
|
60
|
+
}
|
61
|
+
|
62
|
+
provider.stubs(:acquire_workload_identity_token).returns(mock_response)
|
63
|
+
|
64
|
+
result = provider.send(:fetch_token)
|
65
|
+
assert_equal 'wif-access-token', result[:access_token]
|
66
|
+
assert_equal 7200, result[:expires_in]
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_acquire_workload_identity_token_success
|
70
|
+
config = DummyConfigForWIF.new(@resource, @client_id, @tenant_id, @token_file)
|
71
|
+
provider = WorkloadIdentity.new(config)
|
72
|
+
|
73
|
+
# Mock file read and HTTP request
|
74
|
+
File.stubs(:read).with(@token_file).returns('fake-oidc-token')
|
75
|
+
|
76
|
+
mock_response = mock
|
77
|
+
mock_response.stubs(:is_a?).with(Net::HTTPSuccess).returns(true)
|
78
|
+
mock_response.stubs(:body).returns('{"access_token":"wif-token","expires_in":7200}')
|
79
|
+
|
80
|
+
mock_http = mock
|
81
|
+
mock_http.expects(:use_ssl=).with(true)
|
82
|
+
mock_http.expects(:request).returns(mock_response)
|
83
|
+
|
84
|
+
Net::HTTP.stubs(:new).returns(mock_http)
|
85
|
+
|
86
|
+
result = provider.send(:acquire_workload_identity_token)
|
87
|
+
assert_equal 'wif-token', result['access_token']
|
88
|
+
assert_equal 7200, result['expires_in']
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_acquire_workload_identity_token_failure
|
92
|
+
config = DummyConfigForWIF.new(@resource, @client_id, @tenant_id, @token_file)
|
93
|
+
provider = WorkloadIdentity.new(config)
|
94
|
+
|
95
|
+
# Mock file read and HTTP request failure
|
96
|
+
File.stubs(:read).with(@token_file).returns('fake-oidc-token')
|
97
|
+
|
98
|
+
mock_response = mock
|
99
|
+
mock_response.stubs(:is_a?).with(Net::HTTPSuccess).returns(false)
|
100
|
+
mock_response.stubs(:code).returns(400)
|
101
|
+
mock_response.stubs(:body).returns('Bad Request')
|
102
|
+
|
103
|
+
mock_http = mock
|
104
|
+
mock_http.expects(:use_ssl=).with(true)
|
105
|
+
mock_http.expects(:request).returns(mock_response)
|
106
|
+
|
107
|
+
Net::HTTP.stubs(:new).returns(mock_http)
|
108
|
+
|
109
|
+
assert_raise(RuntimeError, 'Failed to get access token: 400 Bad Request') do
|
110
|
+
provider.send(:acquire_workload_identity_token)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_oauth2_endpoint_formation
|
115
|
+
config = DummyConfigForWIF.new(@resource, @client_id, @tenant_id, @token_file)
|
116
|
+
provider = WorkloadIdentity.new(config)
|
117
|
+
|
118
|
+
# Test that the endpoint is formatted correctly with tenant_id
|
119
|
+
File.stubs(:read).with(@token_file).returns('fake-oidc-token')
|
120
|
+
|
121
|
+
# Mock the rest of the HTTP request to avoid actual network call
|
122
|
+
mock_response = mock
|
123
|
+
mock_response.stubs(:is_a?).with(Net::HTTPSuccess).returns(true)
|
124
|
+
mock_response.stubs(:body).returns('{"access_token":"test","expires_in":3600}')
|
125
|
+
|
126
|
+
mock_http = mock
|
127
|
+
mock_http.expects(:use_ssl=).with(true)
|
128
|
+
mock_http.expects(:request).returns(mock_response)
|
129
|
+
|
130
|
+
Net::HTTP.stubs(:new).returns(mock_http)
|
131
|
+
|
132
|
+
# Just verify it doesn't crash - the important thing is that setup_config was called
|
133
|
+
result = provider.send(:acquire_workload_identity_token)
|
134
|
+
assert_equal 'test', result['access_token']
|
135
|
+
end
|
136
|
+
end
|
metadata
CHANGED
@@ -1,58 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-kusto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Komal Rani
|
8
8
|
- Kusto OSS IDC Team
|
9
|
-
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
|
-
- - "
|
17
|
+
- - ">="
|
19
18
|
- !ruby/object:Gem::Version
|
20
|
-
version: 2.
|
19
|
+
version: '2.0'
|
21
20
|
type: :development
|
22
21
|
prerelease: false
|
23
22
|
version_requirements: !ruby/object:Gem::Requirement
|
24
23
|
requirements:
|
25
|
-
- - "
|
24
|
+
- - ">="
|
26
25
|
- !ruby/object:Gem::Version
|
27
|
-
version: 2.
|
26
|
+
version: '2.0'
|
28
27
|
- !ruby/object:Gem::Dependency
|
29
28
|
name: rake
|
30
29
|
requirement: !ruby/object:Gem::Requirement
|
31
30
|
requirements:
|
32
31
|
- - "~>"
|
33
32
|
- !ruby/object:Gem::Version
|
34
|
-
version: 13.
|
33
|
+
version: '13.0'
|
35
34
|
type: :development
|
36
35
|
prerelease: false
|
37
36
|
version_requirements: !ruby/object:Gem::Requirement
|
38
37
|
requirements:
|
39
38
|
- - "~>"
|
40
39
|
- !ruby/object:Gem::Version
|
41
|
-
version: 13.
|
40
|
+
version: '13.0'
|
42
41
|
- !ruby/object:Gem::Dependency
|
43
42
|
name: test-unit
|
44
43
|
requirement: !ruby/object:Gem::Requirement
|
45
44
|
requirements:
|
46
45
|
- - "~>"
|
47
46
|
- !ruby/object:Gem::Version
|
48
|
-
version: 3.
|
47
|
+
version: '3.0'
|
49
48
|
type: :development
|
50
49
|
prerelease: false
|
51
50
|
version_requirements: !ruby/object:Gem::Requirement
|
52
51
|
requirements:
|
53
52
|
- - "~>"
|
54
53
|
- !ruby/object:Gem::Version
|
55
|
-
version: 3.
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fluentd
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '2'
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1.0'
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2'
|
56
75
|
- !ruby/object:Gem::Dependency
|
57
76
|
name: fluentd
|
58
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,21 +145,23 @@ files:
|
|
126
145
|
- lib/fluent/plugin/kusto_query.rb
|
127
146
|
- lib/fluent/plugin/out_kusto.rb
|
128
147
|
- test/helper.rb
|
148
|
+
- test/plugin/e2e_kusto.rb
|
129
149
|
- test/plugin/test_azcli_tokenprovider.rb
|
130
150
|
- test/plugin/test_e2e_kusto.rb
|
151
|
+
- test/plugin/test_mi_tokenprovider.rb
|
131
152
|
- test/plugin/test_out_kusto_config.rb
|
132
153
|
- test/plugin/test_out_kusto_format.rb
|
133
154
|
- test/plugin/test_out_kusto_process.rb
|
134
155
|
- test/plugin/test_out_kusto_start.rb
|
135
156
|
- test/plugin/test_out_kusto_try_write.rb
|
136
157
|
- test/plugin/test_out_kusto_write.rb
|
158
|
+
- test/plugin/test_wif_tokenprovider.rb
|
137
159
|
homepage: https://github.com/Azure/azure-kusto-fluentd
|
138
160
|
licenses:
|
139
161
|
- Apache-2.0
|
140
162
|
metadata:
|
141
163
|
fluentd_plugin: 'true'
|
142
164
|
fluentd_group: output
|
143
|
-
post_install_message:
|
144
165
|
rdoc_options: []
|
145
166
|
require_paths:
|
146
167
|
- lib
|
@@ -148,24 +169,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
169
|
requirements:
|
149
170
|
- - ">="
|
150
171
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
172
|
+
version: 2.7.0
|
152
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
174
|
requirements:
|
154
|
-
- - "
|
175
|
+
- - ">="
|
155
176
|
- !ruby/object:Gem::Version
|
156
|
-
version:
|
177
|
+
version: '0'
|
157
178
|
requirements: []
|
158
|
-
rubygems_version: 3.
|
159
|
-
signing_key:
|
179
|
+
rubygems_version: 3.7.1
|
160
180
|
specification_version: 4
|
161
181
|
summary: A custom Fluentd output plugin for Azure Kusto ingestion.
|
162
182
|
test_files:
|
163
183
|
- test/helper.rb
|
184
|
+
- test/plugin/e2e_kusto.rb
|
164
185
|
- test/plugin/test_azcli_tokenprovider.rb
|
165
186
|
- test/plugin/test_e2e_kusto.rb
|
187
|
+
- test/plugin/test_mi_tokenprovider.rb
|
166
188
|
- test/plugin/test_out_kusto_config.rb
|
167
189
|
- test/plugin/test_out_kusto_format.rb
|
168
190
|
- test/plugin/test_out_kusto_process.rb
|
169
191
|
- test/plugin/test_out_kusto_start.rb
|
170
192
|
- test/plugin/test_out_kusto_try_write.rb
|
171
193
|
- test/plugin/test_out_kusto_write.rb
|
194
|
+
- test/plugin/test_wif_tokenprovider.rb
|