rom-ldap 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +251 -0
  3. data/CONTRIBUTING.md +18 -0
  4. data/README.md +172 -0
  5. data/TODO.md +33 -0
  6. data/config/responses.yml +328 -0
  7. data/lib/dry/monitor/ldap/colorizers/default.rb +17 -0
  8. data/lib/dry/monitor/ldap/colorizers/rouge.rb +31 -0
  9. data/lib/dry/monitor/ldap/logger.rb +58 -0
  10. data/lib/rom-ldap.rb +1 -0
  11. data/lib/rom/ldap.rb +22 -0
  12. data/lib/rom/ldap/alias.rb +30 -0
  13. data/lib/rom/ldap/associations.rb +6 -0
  14. data/lib/rom/ldap/associations/core.rb +23 -0
  15. data/lib/rom/ldap/associations/many_to_many.rb +18 -0
  16. data/lib/rom/ldap/associations/many_to_one.rb +22 -0
  17. data/lib/rom/ldap/associations/one_to_many.rb +32 -0
  18. data/lib/rom/ldap/associations/one_to_one.rb +19 -0
  19. data/lib/rom/ldap/associations/self_ref.rb +35 -0
  20. data/lib/rom/ldap/attribute.rb +327 -0
  21. data/lib/rom/ldap/client.rb +185 -0
  22. data/lib/rom/ldap/client/authentication.rb +118 -0
  23. data/lib/rom/ldap/client/operations.rb +233 -0
  24. data/lib/rom/ldap/commands.rb +6 -0
  25. data/lib/rom/ldap/commands/create.rb +41 -0
  26. data/lib/rom/ldap/commands/delete.rb +17 -0
  27. data/lib/rom/ldap/commands/update.rb +35 -0
  28. data/lib/rom/ldap/constants.rb +193 -0
  29. data/lib/rom/ldap/dataset.rb +286 -0
  30. data/lib/rom/ldap/dataset/conversion.rb +62 -0
  31. data/lib/rom/ldap/dataset/dsl.rb +299 -0
  32. data/lib/rom/ldap/dataset/persistence.rb +44 -0
  33. data/lib/rom/ldap/directory.rb +126 -0
  34. data/lib/rom/ldap/directory/capabilities.rb +71 -0
  35. data/lib/rom/ldap/directory/entry.rb +200 -0
  36. data/lib/rom/ldap/directory/env.rb +155 -0
  37. data/lib/rom/ldap/directory/operations.rb +282 -0
  38. data/lib/rom/ldap/directory/password.rb +122 -0
  39. data/lib/rom/ldap/directory/root.rb +187 -0
  40. data/lib/rom/ldap/directory/tokenization.rb +66 -0
  41. data/lib/rom/ldap/directory/transactions.rb +31 -0
  42. data/lib/rom/ldap/directory/vendors/active_directory.rb +129 -0
  43. data/lib/rom/ldap/directory/vendors/apache_ds.rb +27 -0
  44. data/lib/rom/ldap/directory/vendors/e_directory.rb +16 -0
  45. data/lib/rom/ldap/directory/vendors/open_directory.rb +12 -0
  46. data/lib/rom/ldap/directory/vendors/open_dj.rb +25 -0
  47. data/lib/rom/ldap/directory/vendors/open_ldap.rb +35 -0
  48. data/lib/rom/ldap/directory/vendors/three_eight_nine.rb +16 -0
  49. data/lib/rom/ldap/directory/vendors/unknown.rb +22 -0
  50. data/lib/rom/ldap/dsl.rb +76 -0
  51. data/lib/rom/ldap/errors.rb +47 -0
  52. data/lib/rom/ldap/expression.rb +77 -0
  53. data/lib/rom/ldap/expression_encoder.rb +174 -0
  54. data/lib/rom/ldap/extensions.rb +50 -0
  55. data/lib/rom/ldap/extensions/active_support_notifications.rb +26 -0
  56. data/lib/rom/ldap/extensions/compatibility.rb +11 -0
  57. data/lib/rom/ldap/extensions/dsml.rb +165 -0
  58. data/lib/rom/ldap/extensions/msgpack.rb +23 -0
  59. data/lib/rom/ldap/extensions/optimised_json.rb +25 -0
  60. data/lib/rom/ldap/extensions/rails_log_subscriber.rb +38 -0
  61. data/lib/rom/ldap/formatter.rb +26 -0
  62. data/lib/rom/ldap/functions.rb +207 -0
  63. data/lib/rom/ldap/gateway.rb +145 -0
  64. data/lib/rom/ldap/ldif.rb +74 -0
  65. data/lib/rom/ldap/ldif/exporter.rb +77 -0
  66. data/lib/rom/ldap/ldif/importer.rb +95 -0
  67. data/lib/rom/ldap/mapper_compiler.rb +19 -0
  68. data/lib/rom/ldap/matchers.rb +69 -0
  69. data/lib/rom/ldap/message_queue.rb +7 -0
  70. data/lib/rom/ldap/oid.rb +101 -0
  71. data/lib/rom/ldap/parsers/abstract_syntax.rb +91 -0
  72. data/lib/rom/ldap/parsers/attribute.rb +290 -0
  73. data/lib/rom/ldap/parsers/filter_syntax.rb +133 -0
  74. data/lib/rom/ldap/pdu.rb +285 -0
  75. data/lib/rom/ldap/plugin/pagination.rb +145 -0
  76. data/lib/rom/ldap/plugins.rb +7 -0
  77. data/lib/rom/ldap/projection_dsl.rb +38 -0
  78. data/lib/rom/ldap/relation.rb +135 -0
  79. data/lib/rom/ldap/relation/exporting.rb +72 -0
  80. data/lib/rom/ldap/relation/reading.rb +461 -0
  81. data/lib/rom/ldap/relation/writing.rb +64 -0
  82. data/lib/rom/ldap/responses.rb +17 -0
  83. data/lib/rom/ldap/restriction_dsl.rb +45 -0
  84. data/lib/rom/ldap/schema.rb +123 -0
  85. data/lib/rom/ldap/schema/attributes_inferrer.rb +59 -0
  86. data/lib/rom/ldap/schema/dsl.rb +13 -0
  87. data/lib/rom/ldap/schema/inferrer.rb +50 -0
  88. data/lib/rom/ldap/schema/type_builder.rb +133 -0
  89. data/lib/rom/ldap/scope.rb +19 -0
  90. data/lib/rom/ldap/search_request.rb +249 -0
  91. data/lib/rom/ldap/socket.rb +210 -0
  92. data/lib/rom/ldap/tasks/ldap.rake +103 -0
  93. data/lib/rom/ldap/tasks/ldif.rake +80 -0
  94. data/lib/rom/ldap/transaction.rb +29 -0
  95. data/lib/rom/ldap/type_map.rb +88 -0
  96. data/lib/rom/ldap/types.rb +158 -0
  97. data/lib/rom/ldap/version.rb +17 -0
  98. data/lib/rom/plugins/relation/ldap/active_directory.rb +182 -0
  99. data/lib/rom/plugins/relation/ldap/auto_restrictions.rb +69 -0
  100. data/lib/rom/plugins/relation/ldap/e_directory.rb +27 -0
  101. data/lib/rom/plugins/relation/ldap/instrumentation.rb +35 -0
  102. data/lib/rouge/lexers/ldap.rb +72 -0
  103. data/lib/rouge/themes/ldap.rb +49 -0
  104. metadata +231 -0
data/TODO.md ADDED
@@ -0,0 +1,33 @@
1
+ # TODO
2
+
3
+ 1. **Time out limit and retry in client.**
4
+ Test timeout expiration and retry in client methods.
5
+
6
+ 2. **SSL connections.**
7
+ Hand secure connections; also some vendors only permit certain functions through a secure connection.
8
+
9
+ 3. **Rouge lexer for LDAP filters.**
10
+ Custom terminal syntax for LDAP similar to rom-sql.
11
+
12
+ 4. **Paged results.**
13
+ Use a real paged request instead of chunking all results
14
+
15
+ 5. **Transactions.**
16
+ Rollback failed actions on compatible LDAP servers.
17
+ <https://www.port389.org/docs/389ds/design/exop-plugin-transactions.html>
18
+
19
+ 6. **Associated relations - preload_assoc and transproc.**
20
+ Build LDAP to LDAP relation associations automatically.
21
+ Simple rudimentary RDMS.
22
+ <https://www.openldap.org/doc/admin24/intro.html#LDAP%20vs%20RDBMS>
23
+
24
+ 7. Directory instrumentation using dry-monitor to replace debug logging.
25
+
26
+ 8. `rom/devtools` integration.
27
+
28
+
29
+ ## ONGOING
30
+
31
+ - Improve Rspec coverage, currently 90% complete @ v0.1.0
32
+ - Improve Yard docs, currently 72% complete @ v0.1.0
33
+ - Ensure Rubocop style compliance
@@ -0,0 +1,328 @@
1
+ ---
2
+ # Detailed responses from LDAP server.
3
+ # @see https://ldapwiki.com/wiki/LDAP%20Result%20Codes
4
+ #
5
+ :success:
6
+ - Success
7
+ - Indicates the requested client operation completed successfully.
8
+ - LDAP_SUCCESS:0x00
9
+ :operations_error:
10
+ - Operations Error
11
+ - >
12
+ Indicates an internal error.
13
+ The server is unable to respond with a more specific error and is also unable to properly respond to a request.
14
+ It does not indicate that the client has sent an erroneous message.
15
+ - LDAP_OPERATIONS_ERROR:0x01
16
+ :protocol_error:
17
+ - Protocol Error
18
+ - Indicates that the server has received an invalid or malformed request from the client.
19
+ - LDAP_PROTOCOL_ERROR:0x02
20
+ :time_limit_exceeded:
21
+ - Time Limit Exceeded
22
+ - >
23
+ Indicates the operation's time limit specified by either the client or the server has been exceeded.
24
+ On search operations, incomplete results are returned.
25
+ - LDAP_TIMELIMIT_EXCEEDED:0x03
26
+ :size_limit_exceeded:
27
+ - Size Limit Exceeded
28
+ - >
29
+ Indicates in a search operation, the size limit specified by the client or the server has been exceeded.
30
+ Incomplete results are returned.
31
+ - LDAP_SIZELIMIT_EXCEEDED:0x04
32
+ :compare_false:
33
+ - False Comparison
34
+ - >
35
+ Does not indicate an error condition.
36
+ Indicates that the results of a compare operation are false.
37
+ - LDAP_COMPARE_FALSE:0x05
38
+ :compare_true:
39
+ - True Comparison
40
+ - >
41
+ Does not indicate an error condition.
42
+ Indicates that the results of a compare operation are true.
43
+ - LDAP_COMPARE_TRUE:0x06
44
+ :auth_method_not_supported:
45
+ - Authentication Method Not Supported
46
+ - Indicates during a bind operation the client requested an authentication method not supported by the LDAP server.
47
+ - LDAP_AUTH_METHOD_NOT_SUPPORTED:0x07
48
+ :stronger_auth_required:
49
+ - Stronger Authentication Needed
50
+ - >
51
+ Indicates one of the following:
52
+ In bind requests, the LDAP server accepts only strong authentication.
53
+ In a client request, the client requested an operation such as delete that requires strong authentication.
54
+ In an unsolicited notice of disconnection, the LDAP server discovers the security protecting the communication between the client and server has unexpectedly failed or been compromised.
55
+ - LDAP_STRONG_AUTH_REQUIRED:0x08
56
+ :reserved:
57
+ - Reserved
58
+ - Reserved.
59
+ - Reserved:0x09
60
+ :referral:
61
+ - Referral
62
+ - >
63
+ Does not indicate an error condition.
64
+ In LDAPv3, indicates that the server does not hold the target entry of the request, but that the servers in the referral field may.
65
+ - LDAP_REFERRAL:0x0A
66
+ :admin_limit_exceeded:
67
+ - Admin Limit Exceeded
68
+ - Indicates an LDAP server limit set by an administrative authority has been exceeded.
69
+ - LDAP_ADMINLIMIT_EXCEEDED:0x0B
70
+ :unavailable_critical_extension:
71
+ - Unavailable Critical Extension
72
+ - >
73
+ Indicates the LDAP server was unable to satisfy a request because one or more critical extensions were not available.
74
+ Either the server does not support the control or the control is not appropriate for the operation type.
75
+ - LDAP_UNAVAILABLE_CRITICAL_EXTENSION:0x0C
76
+ :confidentiality_required:
77
+ - Confidentiality Required
78
+ - Indicates the session is not protected by a protocol such as Transport Layer Security (TLS), which provides session confidentiality.
79
+ - LDAP_CONFIDENTIALITY_REQUIRED:0x0D
80
+ :sasl_bind_in_progress:
81
+ - SASL Bind In Progress
82
+ - >
83
+ Does not indicate an error condition, but indicates the server is ready for the next step in the process.
84
+ The client must send the server the same SASL mechanism to continue the process.
85
+ - LDAP_SASL_BIND_IN_PROGRESS:0x0E
86
+ :not_used:
87
+ - Not Used
88
+ - Not used.
89
+ - NotUsed:0x0F
90
+ :no_such_attribute:
91
+ - No Such Attribute
92
+ - Indicates the attribute specified in the modify or compare operation does not exist in the entry.
93
+ - LDAP_NO_SUCH_ATTRIBUTE:0x10
94
+ :undefined_attribute_type:
95
+ - Undefined Attribute Type
96
+ - Indicates the attribute specified in the modify or add operation does not exist in the LDAP server's schema.
97
+ - LDAP_UNDEFINED_TYPE:0x11
98
+ :inappropriate_matching:
99
+ - Inappropriate Matching
100
+ - Indicates the matching rule specified in the search filter does not match a rule defined for the attribute's syntax.
101
+ - LDAP_INAPPROPRIATE_MATCHING:0x12
102
+ :constraint_violation:
103
+ - Constraint Violation
104
+ - >
105
+ Indicates the attribute value specified in a modify, add, or modify DN operation violates constraints placed on the attribute.
106
+ The constraint can be one of size or content (string only, no binary).
107
+ - LDAP_CONSTRAINT_VIOLATION:0x13
108
+ :attribute_or_value_exists:
109
+ - Attribute or Value Exists
110
+ - Indicates the attribute value specified in a modify or add operation already exists as a value for that attribute.
111
+ - LDAP_TYPE_OR_VALUE_EXISTS:0x14
112
+ :invalid_attribute_syntax:
113
+ - Invalid Attribute Syntax
114
+ - Indicates the attribute value specified in an add, compare, or modify operation is an unrecognized or invalid syntax for the attribute.
115
+ - LDAP_INVALID_SYNTAX:0x15
116
+ #
117
+ # 22..31 - Not used.
118
+ #
119
+ :no_such_object:
120
+ - No Such Object
121
+ - >
122
+ Indicates the target object cannot be found.
123
+ This code is not returned on following operations:
124
+ Search operations that find the search base but cannot find any entries that match the search filter.
125
+ Bind operations.
126
+ - LDAP_NO_SUCH_OBJECT:0x20
127
+ :alias_problem:
128
+ - Alias Problem
129
+ - Indicates an error occurred when an alias was dereferenced.
130
+ - LDAP_ALIAS_PROBLEM:0x21
131
+ :invalid_dn_syntax:
132
+ - Invalid DN Syntax
133
+ - >
134
+ Indicates the syntax of the DN is incorrect.
135
+ If the DN syntax is correct, but the LDAP server's structure rules do not permit the operation, the server returns LDAP_UNWILLING_TO_PERFORM.
136
+ - LDAP_INVALID_DN_SYNTAX:0x22
137
+ :ldap_is_leaf:
138
+ - Failed On Leaf
139
+ - >
140
+ Indicates the specified operation cannot be performed on a leaf entry.
141
+ This code is not currently in the LDAP specifications, but is reserved for this constant.
142
+ - LDAP_IS_LEAF:0x23
143
+ :alias_dereferencing_problem:
144
+ - Alias Dereferencing Problem
145
+ - Indicates during a search operation, either the client does not have access rights to read the aliased object's name or dereferencing is not allowed.
146
+ - LDAP_ALIAS_DEREF_PROBLEM:0x24
147
+ #
148
+ # 37..47 - Not used.
149
+ #
150
+ :inappropriate_authentication:
151
+ - Inappropriate Authentication
152
+ - >
153
+ Indicates during a bind operation, the client is attempting to use an authentication method that the client cannot use correctly.
154
+ For example, either of the following cause this error:
155
+ The client returns simple credentials when strong credentials are required.
156
+ The client returns a DN and a password for a simple bind when the entry does not have a password defined.
157
+ - LDAP_INAPPROPRIATE_AUTH:0x30
158
+ :invalid_credentials:
159
+ - Invalid Credentials
160
+ - >
161
+ Indicates during a bind operation one of the following occurred:
162
+ The client passed either an incorrect DN or password.
163
+ The password is incorrect because it has expired, intruder detection has locked the account, or some other similar reason.
164
+ - LDAP_INVALID_CREDENTIALS:0x31
165
+ :insufficient_access_rights:
166
+ - Insufficient Access Rights
167
+ - Indicates the caller does not have sufficient rights to perform the requested operation.
168
+ - LDAP_INSUFFICIENT_ACCESS:0x32
169
+ :busy:
170
+ - Busy
171
+ - Indicates the LDAP server is too busy to process the client request at this time but if the client waits and resubmits the request, the server may be able to process it then.
172
+ - LDAP_BUSY:0x33
173
+ :unavailable:
174
+ - Unavailable
175
+ - Indicates the LDAP server cannot process the client's bind request, usually because it is shutting down.
176
+ - LDAP_UNAVAILABLE:0x34
177
+ :unwilling_to_perform:
178
+ - Unwilling To Perform
179
+ - >
180
+ Indicates the LDAP server cannot process the request because of server-defined restrictions.
181
+ This error is returned for the following reasons:
182
+ The add entry request violates the server's structure rules.
183
+ The modify attribute request specifies attributes that users cannot modify.
184
+ Password restrictions prevent the action.
185
+ Connection restrictions prevent the action.
186
+ - LDAP_UNWILLING_TO_PERFORM:0x35
187
+ :loop_detected:
188
+ - Referral Loop Detected
189
+ - Indicates the client discovered an alias or referral loop, and is thus unable to complete this request.
190
+ - LDAP_LOOP_DETECT:0x36
191
+ #
192
+ # 55..63 - Not used.
193
+ #
194
+ :naming_violation:
195
+ - Naming Violation
196
+ - >
197
+ Indicates the add or modify DN operation violates the schema's structure rules. For example,
198
+ The request places the entry subordinate to an alias.
199
+ The request places the entry subordinate to a container that is forbidden by the containment rules.
200
+ The RDN for the entry uses a forbidden attribute type.
201
+ LDAP_NAMING_VIOLATION:0x40
202
+ :object_class_violation:
203
+ - Object Class Violation
204
+ - >
205
+ Indicates the add, modify, or modify DN operation violates the object class rules for the entry.
206
+ For example, the following types of request return this error:
207
+ The add or modify operation tries to add an entry without a value for a required attribute.
208
+ The add or modify operation tries to add an entry with a value for an attribute which the class definition does not contain.
209
+ The modify operation tries to remove a required attribute without removing the auxiliary class that defines the attribute as required.
210
+ - LDAP_OBJECT_CLASS_VIOLATION:0x41
211
+ :not_allowed_on_non_leaf:
212
+ - Not Allowed On Non-Leaf
213
+ - >
214
+ Indicates the requested operation is permitted only on leaf entries.
215
+ For example, the following types of requests return this error:
216
+ The client requests a delete operation on a parent entry.
217
+ The client request a modify DN operation on a parent entry.
218
+ - LDAP_NOT_ALLOWED_ON_NONLEAF:0x42
219
+ :not_allowed_on_rdn:
220
+ - Not Allowed On RDN
221
+ - Indicates the modify operation attempted to remove an attribute value that forms the entry's relative distinguished name.
222
+ - LDAP_NOT_ALLOWED_ON_RDN:0x43
223
+ :entry_already_exists:
224
+ - Entry Already Exists
225
+ - Indicates the add operation attempted to add an entry that already exists, or that the modify operation attempted to rename an entry to the name of an entry that already exists.
226
+ - LDAP_ALREADY_EXISTS:0x44
227
+ :object_class_mods_prohibited:
228
+ - ObjectClass Modifications Prohibited
229
+ - Indicates the modify operation attempted to modify the structure rules of an object class.
230
+ - LDAP_NO_OBJECT_CLASS_MODS:0x45
231
+ :reserved_for_cldap:
232
+ - Reserved for CLDAP
233
+ -
234
+ - LDAP_RESULTS_TOO_LARGE:0x46
235
+ :affects_multiple_dsas:
236
+ - Affects Multiple DSAs
237
+ - Indicates the modify DN operation moves the entry from one LDAP server to another and thus requires more than one LDAP server.
238
+ - LDAP_AFFECTS_MULTIPLE_DSAS:0x47
239
+ #
240
+ # 72..79 - Not used.
241
+ #
242
+ :other:
243
+ - Other
244
+ - >
245
+ Indicates an unknown error condition.
246
+ This is the default value for NDS error codes which do not map to other LDAP error codes.
247
+ - LDAP_OTHER:0x50
248
+ :server_down:
249
+ - Server Down
250
+ - Indicates the LDAP client cannot establish a connection with, or lost the connection to, the LDAP server.
251
+ - LDAP_SERVER_DOWN:0x51
252
+ :local_error:
253
+ - Local Client Error
254
+ - Indicates an error occurred in the LDAP client.
255
+ - LDAP_LOCAL_ERROR:0x52
256
+ :encoding_error:
257
+ - Encoding Error
258
+ - Indicates the LDAP client encountered an error when encoding the LDAP request to be sent to the server.
259
+ - LDAP_ENCODING_ERROR:0x53
260
+ :decoding_error:
261
+ - Decoding Error
262
+ - Indicates the LDAP client encountered an error when decoding the LDAP response received from the server.
263
+ - LDAP_DECODING_ERROR:0x54
264
+ :timeout:
265
+ - Timeout
266
+ - >
267
+ Indicates the LDAP client timed out while waiting for a response from the server.
268
+ The specified timeout period has been exceeded and the server has not responded.
269
+ - LDAP_TIMEOUT:0x55
270
+ :auth_method_unknown:
271
+ - Unknown Authentication Method
272
+ - Indicates an unknown authentication method was specified.
273
+ - LDAP_AUTH_UNKNOWN:0x56
274
+ :filter_error:
275
+ - Filter Error
276
+ - Indicates an error occurred when specifying the search filter.
277
+ - LDAP_FILTER_ERROR:0x57
278
+ :user_cancelled:
279
+ - User Cancelled
280
+ - Indicates the user cancelled the LDAP operation
281
+ - LDAP_USER_CANCELLED:0x58
282
+ :param_error:
283
+ - Invalid Parameter
284
+ - Indicates that an invalid parameter was specified.
285
+ - LDAP_PARAM_ERROR:0x59
286
+ :no_memory:
287
+ - No Memory
288
+ - >
289
+ Indicates that no memory is available.
290
+ For example, when creating an LDAP request or an LDAP control.
291
+ - LDAP_NO_MEMORY:0x5a
292
+ :connect_error:
293
+ - Connection Error
294
+ - Indicates the LDAP client cannot establish a connection, or has lost the connection, with the LDAP server.
295
+ - LDAP_CONNECT_ERROR:0x5b
296
+ :not_supported:
297
+ - Not Supported
298
+ - >
299
+ Indicates that the LDAP client is attempting to use functionality that is not supported.
300
+ For example, the client identifies itself as an LDAPv2 client, and attempt to use functionality only available in LDAPv3.
301
+ - LDAP_NOT_SUPPORTED:0x5c
302
+ :control_not_found:
303
+ - Control Not Found
304
+ - >
305
+ Indicates a requested LDAP control was not found.
306
+ This result code is set when the client parsing a server response for controls and not finding the requested controls
307
+ - LDAP_CONTROL_NOT_FOUND:0x5d
308
+ :no_results_returned:
309
+ - No Results returned
310
+ - Indicates no results were returned from the server.
311
+ - LDAP_NO_RESULTS_RETURNED:0x5e
312
+ :more_results:
313
+ - More Results To Return
314
+ - >
315
+ Indicates there are more results in the chain of results.
316
+ This result code is returned when additional result codes are available from the LDAP server.
317
+ - LDAP_MORE_RESULTS_TO_RETURN:0x5f
318
+ :client_loop:
319
+ - Client Loop
320
+ - Indicates the LDAP client detected a loop, for example, when following referrals.
321
+ - LDAP_CLIENT_LOOP:0x60
322
+ :referral_limit:
323
+ - Referral Limit Exceeded
324
+ - >
325
+ Indicates that the referral hop limit was exceeded.
326
+ This result code is if the client is referred to other servers more times than allowed by the referral hop limit.
327
+ - LDAP_REFERRAL_LIMIT_EXCEEDED:0x61
328
+
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module Monitor
5
+ module LDAP
6
+ module Colorizers
7
+ class Default
8
+ def initialize(_theme); end
9
+
10
+ def call(string)
11
+ string
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ require 'rouge/util'
2
+ require 'rouge/token'
3
+ require 'rouge/theme'
4
+ require 'rouge/themes/gruvbox'
5
+ require 'rouge/formatter'
6
+ require 'rouge/formatters/terminal256'
7
+ require 'rouge/lexer'
8
+ require 'rouge/regex_lexer'
9
+ require 'rouge/lexers/ldap'
10
+
11
+ module Dry
12
+ module Monitor
13
+ module LDAP
14
+ module Colorizers
15
+ class Rouge
16
+ attr_reader :formatter
17
+ attr_reader :lexer
18
+
19
+ def initialize(theme)
20
+ @formatter = ::Rouge::Formatters::Terminal256.new(theme || ::Rouge::Themes::Gruvbox.new)
21
+ @lexer = ::Rouge::Lexers::LDAP.new
22
+ end
23
+
24
+ def call(string)
25
+ formatter.format(lexer.lex(string))
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,58 @@
1
+ require 'dry-configurable'
2
+ require 'dry/core/extensions'
3
+ require 'dry/monitor/notifications'
4
+
5
+ Dry::Monitor::Notifications.register_event(:ldap)
6
+
7
+ module Dry
8
+ module Monitor
9
+ module LDAP
10
+ class Logger
11
+ extend Dry::Core::Extensions
12
+ extend Dry::Configurable
13
+
14
+ register_extension(:default_colorizer) do
15
+ require_relative './colorizers/default'
16
+
17
+ def colorizer
18
+ @colorizer ||= Colorizers::Default.new(config.theme)
19
+ end
20
+ end
21
+
22
+ register_extension(:rouge_colorizer) do
23
+ require_relative './colorizers/rouge'
24
+
25
+ def colorizer
26
+ @colorizer ||= Colorizers::Rouge.new(config.theme)
27
+ end
28
+ end
29
+
30
+ setting :theme, nil
31
+ setting :message_template, %( Loaded %s in %sms %s).freeze
32
+
33
+ attr_reader :config
34
+ attr_reader :logger
35
+ attr_reader :template
36
+
37
+ load_extensions(:default_colorizer)
38
+ load_extensions(:rouge_colorizer)
39
+
40
+ def initialize(logger, config = self.class.config)
41
+ @logger = logger
42
+ @config = config
43
+ @template = config.message_template
44
+ end
45
+
46
+ def subscribe(notifications)
47
+ notifications.subscribe(:ldap) do |time:, name:, query:|
48
+ log_query(time, name, query)
49
+ end
50
+ end
51
+
52
+ def log_query(time, name, query)
53
+ logger.info template % [name.inspect, time, colorizer.call(query)]
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end