fluent-plugin-ldap-client 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9902fbdbda54619005fea1824cb4a2672cdd4d96976df46b6cda5adac6dbbdb2
4
+ data.tar.gz: 27341af7bbdbfb47cc6e09393a0c699c7030f906d73ab8c3bc02f5fb3b641245
5
+ SHA512:
6
+ metadata.gz: 87cc6a4b5ab92f03af2c9800708cc0f12e73a5bbab177b425a98ce1e4993ff3afaf9fcaf977c0bbda0fe1723bfcf4a8fe6becfca082dc919af5ca24f32da1c3a
7
+ data.tar.gz: 551e6e42443aa50cbf8c1e10b1a6b9efcf2c2ee2e57f5f85aa13866a20f8449c52808a46247f95da38a388da6537496cca0486ca1f7abef97f88cd44992f86b2
data/.rubocop.yml ADDED
@@ -0,0 +1,44 @@
1
+ ---
2
+
3
+ plugins:
4
+ - rubocop-rake
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 2.7
8
+ NewCops: enable
9
+
10
+ Gemspec/DevelopmentDependencies:
11
+ EnforcedStyle: gemspec
12
+
13
+ Metrics/AbcSize:
14
+ Max: 25
15
+
16
+ Metrics/BlockLength:
17
+ Exclude:
18
+ - fluent-plugin-ldap-client.gemspec
19
+ - test/**/*.rb
20
+
21
+ Metrics/ClassLength:
22
+ Exclude:
23
+ - test/**/*.rb
24
+
25
+ Metrics/CyclomaticComplexity:
26
+ Max: 10
27
+
28
+ Metrics/MethodLength:
29
+ Max: 20
30
+
31
+ Metrics/ParameterLists:
32
+ Max: 10
33
+ Exclude:
34
+ - test/helper.rb
35
+
36
+ Metrics/PerceivedComplexity:
37
+ Max: 10
38
+
39
+ Naming/MethodParameterName:
40
+ Exclude:
41
+ - lib/fluent/plugin/filter_ldap_enrich.rb
42
+
43
+ Style/Documentation:
44
+ Enabled: false
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # fluent-plugin-ldap-client
2
+
3
+ [Fluentd](https://fluentd.org/) plugin to link with ldap server.
4
+
5
+ It is plugins that will search data in ldap.
6
+
7
+ ## filter : ldap_enrich
8
+
9
+ To do enrichment on events through ldap search.
10
+
11
+ ### parameters
12
+
13
+ Parameters are :
14
+
15
+ | parameters | mandatory | default | type | purpose |
16
+ |------------|-----------|---------|------|---------|
17
+ | | | | | |
18
+ | | | | | |
19
+ | | | | | |
20
+
21
+ ### examples
22
+
23
+ ``` text
24
+
25
+ ```
26
+
27
+ ## Installation
28
+
29
+ Manual install, by executing:
30
+
31
+ ``` shell
32
+ gem install fluent-plugin-ldap-client
33
+ ```
34
+
35
+ Add to Gemfile with:
36
+
37
+ ``` shell
38
+ bundle add fluent-plugin-ldap-client
39
+ ```
40
+
41
+
42
+ ## Copyright
43
+
44
+ * Copyright(c) 2025-2025 Thomas Tych
45
+ * License
46
+ * Apache License, Version 2.0
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rake/testtask'
7
+
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs.push('lib', 'test')
10
+
11
+ t.test_files = if ENV['TEST_FILE']
12
+ FileList["#{ENV['TEST_FILE']}*",
13
+ "test/**/#{ENV['TEST_FILE']}*"]
14
+ else
15
+ FileList['test/**/test_*.rb', 'test/**/*_test.rb']
16
+ end
17
+ t.verbose = ENV.fetch('VERBOSE', false)
18
+ t.warning = ENV.fetch('WARNING', false)
19
+ end
20
+
21
+ require 'rubocop/rake_task'
22
+
23
+ RuboCop::RakeTask.new
24
+
25
+ require 'bump/tasks'
26
+
27
+ task default: %i[test rubocop]
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright 2025- Thomas Tych
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require 'fluent/plugin/filter'
19
+
20
+ # require 'lru_redux'
21
+
22
+ require_relative 'ldap_client/ldap_client'
23
+ require_relative 'ldap_client/no_cache'
24
+ require_relative 'ldap_client/cache_ttl'
25
+
26
+ module Fluent
27
+ module Plugin
28
+ class LdapEnrichFilter < Fluent::Plugin::Filter
29
+ NAME = 'ldap_enrich'
30
+ Fluent::Plugin.register_filter(NAME, self)
31
+
32
+ DEFAULT_LDAP_HOST = 'localhost'
33
+ DEFAULT_LDAP_PORT = 389
34
+ DEFAULT_LDAP_ENCRYPTION = false
35
+ DEFAULT_LDAP_BASE_DN = ''
36
+ DEFAULT_LDAP_USERNAME = nil
37
+ DEFAULT_LDAP_PASSWORD = nil
38
+
39
+ desc 'ldap host'
40
+ config_param :ldap_host, :string, default: DEFAULT_LDAP_HOST
41
+ desc 'ldap port'
42
+ config_param :ldap_port, :integer, default: DEFAULT_LDAP_PORT
43
+ desc 'ldap encryption'
44
+ config_param :ldap_encryption, :bool, default: DEFAULT_LDAP_ENCRYPTION
45
+ desc 'ldap base DN'
46
+ config_param :ldap_base_dn, :string, default: DEFAULT_LDAP_BASE_DN
47
+ desc 'ldap username'
48
+ config_param :ldap_username, :string, default: DEFAULT_LDAP_USERNAME
49
+ desc 'ldap password'
50
+ config_param :ldap_password, :string, default: DEFAULT_LDAP_PASSWORD, secret: true
51
+
52
+ desc 'CA cert'
53
+ config_param :ca_cert, :string, default: nil
54
+
55
+ DEFAULT_LDAP_ATTRIBUTES = {}.freeze
56
+
57
+ desc 'ldap query'
58
+ config_param :ldap_query, :string, default: nil
59
+ desc 'ldap attributes to inject in record'
60
+ config_param :ldap_attributes, :hash, default: DEFAULT_LDAP_ATTRIBUTES, symbolize_keys: false, value_type: :string
61
+
62
+ DEFAULT_CACHE_ENABLE = true
63
+ DEFAULT_CACHE_SIZE = 1000
64
+ DEFAULT_CACHE_TTL_POSITIVE = 24 * 3600
65
+ DEFAULT_CACHE_TTL_NEGATIVE = 3600
66
+
67
+ desc 'enable cache'
68
+ config_param :cache_enable, :bool, default: DEFAULT_CACHE_ENABLE
69
+ desc 'cache size'
70
+ config_param :cache_size, :integer, default: DEFAULT_CACHE_SIZE
71
+ desc 'cache ttl positive'
72
+ config_param :cache_ttl_positive, :integer, default: DEFAULT_CACHE_TTL_POSITIVE
73
+ desc 'cache ttl negative'
74
+ config_param :cache_ttl_negative, :integer, default: DEFAULT_CACHE_TTL_NEGATIVE
75
+
76
+ def configure(conf)
77
+ super
78
+
79
+ raise Fluent::ConfigError, 'ldap_query should be defined' if !ldap_query || ldap_query.empty?
80
+ raise Fluent::ConfigError, 'ldap_attributes should be defined' if !ldap_attributes || ldap_attributes.empty?
81
+
82
+ true
83
+ end
84
+
85
+ def start
86
+ super
87
+
88
+ @ldap_client = Fluent::Plugin::LdapClient::LdapClient.new(
89
+ host: ldap_host,
90
+ port: ldap_port,
91
+ base_dn: ldap_base_dn,
92
+ username: ldap_username,
93
+ password: ldap_password,
94
+ encryption: ldap_encryption,
95
+ ca_cert: ca_cert,
96
+ log: log
97
+ )
98
+
99
+ @cache = if cache_enable
100
+ Fluent::Plugin::LdapClient::CacheTTL.new(
101
+ size: cache_size,
102
+ ttl_positive: cache_ttl_positive,
103
+ ttl_negative: cache_ttl_negative
104
+ )
105
+ else
106
+ Fluent::Plugin::LdapClient::NoCache.new
107
+ end
108
+ end
109
+
110
+ def shutdown
111
+ @ldap_client.close
112
+
113
+ super
114
+ end
115
+
116
+ def filter(_tag, _time, record)
117
+ return record if !ldap_query || ldap_query.empty?
118
+ return record if !ldap_attributes || ldap_attributes.empty?
119
+
120
+ query_string = interpolate_ldap_query(record)
121
+ return record unless query_string
122
+
123
+ ldap_result = @cache.get(query_string) do |ldap_query_string|
124
+ @ldap_client.search_query(ldap_query_string)
125
+ end
126
+
127
+ if ldap_result
128
+ ldap_attributes.each do |key, record_key|
129
+ record[record_key] = (ldap_result[key.to_sym] || ldap_result[key])&.join(', ')
130
+ end
131
+ end
132
+ record
133
+ end
134
+
135
+ def interpolate_ldap_query(record)
136
+ ldap_query % record.transform_keys(&:to_sym)
137
+ rescue StandardError => e
138
+ log.warn("#{NAME}: while interpolating ldap_query \"#{ldap_query}\", #{e.message}")
139
+ nil
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fluent
4
+ module Plugin
5
+ module LdapClient
6
+ class CacheTTL
7
+ CACHE_SIZE = 1000
8
+ TTL_POSITIVE = 14 * 3600
9
+ TTL_NEGATIVE = 3600
10
+
11
+ attr_reader :size, :ttl_positive, :ttl_negative
12
+
13
+ def initialize(size: CACHE_SIZE, ttl_positive: TTL_POSITIVE, ttl_negative: TTL_NEGATIVE)
14
+ @size = size
15
+ @ttl_positive = ttl_positive
16
+ @ttl_negative = ttl_negative
17
+
18
+ @cache = {}
19
+ @access_order = []
20
+ end
21
+
22
+ def get(key)
23
+ cleanup_expired_entries
24
+
25
+ if @cache.key?(key) && !expired?(@cache[key])
26
+ refresh_access_order(key)
27
+ return @cache[key][:value]
28
+ end
29
+
30
+ result = yield key
31
+ store(key, result)
32
+ result
33
+ end
34
+
35
+ private
36
+
37
+ def store(key, value)
38
+ evict_if_needed
39
+
40
+ ttl = value.nil? ? @ttl_negative : @ttl_positive
41
+ @cache[key] = { value: value, expires_at: Time.now + ttl }
42
+ refresh_access_order(key)
43
+ end
44
+
45
+ def expired?(entry)
46
+ Time.now > entry[:expires_at]
47
+ end
48
+
49
+ def cleanup_expired_entries
50
+ @cache.each_key do |key|
51
+ if expired?(@cache[key])
52
+ @cache.delete(key)
53
+ @access_order.delete(key)
54
+ end
55
+ end
56
+ end
57
+
58
+ def evict_if_needed
59
+ return unless @cache.size > size
60
+
61
+ lru_key = @access_order.shift
62
+ @cache.delete(lru_key)
63
+ end
64
+
65
+ def refresh_access_order(key)
66
+ @access_order.delete(key)
67
+ @access_order << key
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/ldap'
4
+
5
+ module Fluent
6
+ module Plugin
7
+ module LdapClient
8
+ class LdapClient
9
+ CONNECT_TIMEOUT = 10
10
+
11
+ attr_reader :host, :port, :base_dn, :username, :password, :encryption, :ca_cert, :connect_timeout, :log
12
+
13
+ def initialize(host:, port:, base_dn:, username:, password:, encryption: false, ca_cert: nil,
14
+ connect_timeout: CONNECT_TIMEOUT, log: nil)
15
+ @host = host
16
+ @port = port
17
+ @encryption = encryption
18
+ @base_dn = base_dn
19
+ @username = username
20
+ @password = password
21
+
22
+ @ca_cert = ca_cert
23
+ @connect_timeout = connect_timeout
24
+
25
+ @log = log
26
+ end
27
+
28
+ def ldap
29
+ @ldap ||= Net::LDAP.new(
30
+ host: host,
31
+ port: port,
32
+ base: base_dn,
33
+ auth: ldap_auth,
34
+ encryption: ldap_encryption,
35
+ connect_timeout: connect_timeout
36
+ )
37
+ raise "LDAP Client authentication failed: #{@ldap.get_operation_result.message}" unless @ldap.bind
38
+
39
+ @ldap
40
+ rescue StandardError => e
41
+ log&.error "LDAP Client error: #{e.message}"
42
+ @dap = nil
43
+ end
44
+
45
+ def ldap_auth
46
+ return unless username && password
47
+
48
+ { method: :simple,
49
+ username: username,
50
+ password: password }
51
+ end
52
+
53
+ def ldap_encryption
54
+ return unless encryption
55
+
56
+ { method: :simple_tls,
57
+ tls_options: { ca_file: ca_file } }
58
+ end
59
+
60
+ def search_query(query)
61
+ return nil unless ldap && query
62
+
63
+ filter = Net::LDAP::Filter.construct(query)
64
+ search_filter(filter)
65
+ rescue StandardError => e
66
+ log&.warn "LDAP Client error: query failed: #{e.message}"
67
+ nil
68
+ end
69
+
70
+ def search_filter(filter)
71
+ result = ldap.search(base: base_dn, filter: filter)
72
+ log&.debug "LDAP Client: No LDAP results for query \"#{query}\"" if result.nil? || result.empty?
73
+
74
+ result&.first&.to_h
75
+ rescue StandardError => e
76
+ log&.warn "LDAP Client error: query failed: #{e.message}"
77
+ nil
78
+ end
79
+
80
+ def close
81
+ @ldap = nil
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fluent
4
+ module Plugin
5
+ module LdapClient
6
+ class NoCache
7
+ def get(*args, **kvargs)
8
+ yield(*args, **kvargs) if block_given?
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,284 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-ldap-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Tych
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-03-21 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: bump
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 0.10.0
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.10.0
26
+ - !ruby/object:Gem::Dependency
27
+ name: bundler
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.6'
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 2.6.5
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.6'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.6.5
46
+ - !ruby/object:Gem::Dependency
47
+ name: byebug
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '11.1'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 11.1.3
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '11.1'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 11.1.3
66
+ - !ruby/object:Gem::Dependency
67
+ name: mocha
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '2.7'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.7.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.7'
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.7.1
86
+ - !ruby/object:Gem::Dependency
87
+ name: rake
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: '13.2'
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 13.2.1
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '13.2'
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: 13.2.1
106
+ - !ruby/object:Gem::Dependency
107
+ name: reek
108
+ requirement: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '6.4'
113
+ type: :development
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '6.4'
120
+ - !ruby/object:Gem::Dependency
121
+ name: rubocop
122
+ requirement: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: '1.73'
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: 1.73.1
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '1.73'
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: 1.73.1
140
+ - !ruby/object:Gem::Dependency
141
+ name: rubocop-rake
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '0.7'
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: 0.7.1
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - "~>"
155
+ - !ruby/object:Gem::Version
156
+ version: '0.7'
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 0.7.1
160
+ - !ruby/object:Gem::Dependency
161
+ name: simplecov
162
+ requirement: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.22'
167
+ type: :development
168
+ prerelease: false
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.22'
174
+ - !ruby/object:Gem::Dependency
175
+ name: test-unit
176
+ requirement: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '3.6'
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: 3.6.7
184
+ type: :development
185
+ prerelease: false
186
+ version_requirements: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - "~>"
189
+ - !ruby/object:Gem::Version
190
+ version: '3.6'
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: 3.6.7
194
+ - !ruby/object:Gem::Dependency
195
+ name: timecop
196
+ requirement: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - "~>"
199
+ - !ruby/object:Gem::Version
200
+ version: '0.9'
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: 0.9.10
204
+ type: :development
205
+ prerelease: false
206
+ version_requirements: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - "~>"
209
+ - !ruby/object:Gem::Version
210
+ version: '0.9'
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: 0.9.10
214
+ - !ruby/object:Gem::Dependency
215
+ name: fluentd
216
+ requirement: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: 0.14.10
221
+ - - "<"
222
+ - !ruby/object:Gem::Version
223
+ version: '2'
224
+ type: :runtime
225
+ prerelease: false
226
+ version_requirements: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: 0.14.10
231
+ - - "<"
232
+ - !ruby/object:Gem::Version
233
+ version: '2'
234
+ - !ruby/object:Gem::Dependency
235
+ name: net-ldap
236
+ requirement: !ruby/object:Gem::Requirement
237
+ requirements:
238
+ - - "~>"
239
+ - !ruby/object:Gem::Version
240
+ version: '0.19'
241
+ type: :runtime
242
+ prerelease: false
243
+ version_requirements: !ruby/object:Gem::Requirement
244
+ requirements:
245
+ - - "~>"
246
+ - !ruby/object:Gem::Version
247
+ version: '0.19'
248
+ email:
249
+ - thomas.tych@gmail.com
250
+ executables: []
251
+ extensions: []
252
+ extra_rdoc_files: []
253
+ files:
254
+ - ".rubocop.yml"
255
+ - LICENSE
256
+ - README.md
257
+ - Rakefile
258
+ - lib/fluent/plugin/filter_ldap_enrich.rb
259
+ - lib/fluent/plugin/ldap_client/cache_ttl.rb
260
+ - lib/fluent/plugin/ldap_client/ldap_client.rb
261
+ - lib/fluent/plugin/ldap_client/no_cache.rb
262
+ homepage: https://gitlab.com/ttych/fluent-plugin-ldap-client
263
+ licenses:
264
+ - Apache-2.0
265
+ metadata:
266
+ rubygems_mfa_required: 'true'
267
+ rdoc_options: []
268
+ require_paths:
269
+ - lib
270
+ required_ruby_version: !ruby/object:Gem::Requirement
271
+ requirements:
272
+ - - ">="
273
+ - !ruby/object:Gem::Version
274
+ version: 2.7.0
275
+ required_rubygems_version: !ruby/object:Gem::Requirement
276
+ requirements:
277
+ - - ">="
278
+ - !ruby/object:Gem::Version
279
+ version: '0'
280
+ requirements: []
281
+ rubygems_version: 3.6.5
282
+ specification_version: 4
283
+ summary: fluentd plugin to search in ldap
284
+ test_files: []