@@ -163,6 +163,316 @@ def delete_topic(topic_name)
163163 delete_topic_handle
164164 end
165165
166+ # Create acl
167+ # @param resource_type - values of type rd_kafka_ResourceType_t
168+ # https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L7307
169+ # valid values are:
170+ # RD_KAFKA_RESOURCE_TOPIC = 2
171+ # RD_KAFKA_RESOURCE_GROUP = 3
172+ # RD_KAFKA_RESOURCE_BROKER = 4
173+ # @param resource_pattern_type - values of type rd_kafka_ResourcePatternType_t
174+ # https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L7320
175+ # valid values are:
176+ # RD_KAFKA_RESOURCE_PATTERN_MATCH = 2
177+ # RD_KAFKA_RESOURCE_PATTERN_LITERAL = 3
178+ # RD_KAFKA_RESOURCE_PATTERN_PREFIXED = 4
179+ # @param operation - values of type rd_kafka_AclOperation_t
180+ # https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L8403
181+ # valid values are:
182+ # RD_KAFKA_ACL_OPERATION_ALL = 2
183+ # RD_KAFKA_ACL_OPERATION_READ = 3
184+ # RD_KAFKA_ACL_OPERATION_WRITE = 4
185+ # RD_KAFKA_ACL_OPERATION_CREATE = 5
186+ # RD_KAFKA_ACL_OPERATION_DELETE = 6
187+ # RD_KAFKA_ACL_OPERATION_ALTER = 7
188+ # RD_KAFKA_ACL_OPERATION_DESCRIBE = 8
189+ # RD_KAFKA_ACL_OPERATION_CLUSTER_ACTION = 9
190+ # RD_KAFKA_ACL_OPERATION_DESCRIBE_CONFIGS = 10
191+ # RD_KAFKA_ACL_OPERATION_ALTER_CONFIGS = 11
192+ # RD_KAFKA_ACL_OPERATION_IDEMPOTENT_WRITE = 12
193+ # @param permission_type - values of type rd_kafka_AclPermissionType_t
194+ # https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L8435
195+ # valid values are:
196+ # RD_KAFKA_ACL_PERMISSION_TYPE_DENY = 2
197+ # RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW = 3
198+ # @raise [RdkafkaError]
199+ #
200+ # @return [CreateAclHandle] Create acl handle that can be used to wait for the result of creating the acl
201+ def create_acl ( resource_type :, resource_name :, resource_pattern_type :, principal :, host :, operation :, permission_type :)
202+ closed_admin_check ( __method__ )
203+
204+ # Create a rd_kafka_AclBinding_t representing the new acl
205+ error_buffer = FFI ::MemoryPointer . from_string ( " " * 256 )
206+ new_acl_ptr = Rdkafka ::Bindings . rd_kafka_AclBinding_new (
207+ resource_type ,
208+ FFI ::MemoryPointer . from_string ( resource_name ) ,
209+ resource_pattern_type ,
210+ FFI ::MemoryPointer . from_string ( principal ) ,
211+ FFI ::MemoryPointer . from_string ( host ) ,
212+ operation ,
213+ permission_type ,
214+ error_buffer ,
215+ 256
216+ )
217+ if new_acl_ptr . null?
218+ raise Rdkafka ::Config ::ConfigError . new ( error_buffer . read_string )
219+ end
220+
221+ # Note that rd_kafka_CreateAcls can create more than one acl at a time
222+ pointer_array = [ new_acl_ptr ]
223+ acls_array_ptr = FFI ::MemoryPointer . new ( :pointer )
224+ acls_array_ptr . write_array_of_pointer ( pointer_array )
225+
226+ # Get a pointer to the queue that our request will be enqueued on
227+ queue_ptr = @native_kafka . with_inner do |inner |
228+ Rdkafka ::Bindings . rd_kafka_queue_get_background ( inner )
229+ end
230+
231+ if queue_ptr . null?
232+ Rdkafka ::Bindings . rd_kafka_AclBinding_destroy ( new_acl_ptr )
233+ raise Rdkafka ::Config ::ConfigError . new ( "rd_kafka_queue_get_background was NULL" )
234+ end
235+
236+ # Create and register the handle that we will return to the caller
237+ create_acl_handle = CreateAclHandle . new
238+ create_acl_handle [ :pending ] = true
239+ create_acl_handle [ :response ] = -1
240+ CreateAclHandle . register ( create_acl_handle )
241+
242+ admin_options_ptr = @native_kafka . with_inner do |inner |
243+ Rdkafka ::Bindings . rd_kafka_AdminOptions_new ( inner , Rdkafka ::Bindings ::RD_KAFKA_ADMIN_OP_CREATEACLS )
244+ end
245+
246+ Rdkafka ::Bindings . rd_kafka_AdminOptions_set_opaque ( admin_options_ptr , create_acl_handle . to_ptr )
247+
248+ begin
249+ @native_kafka . with_inner do |inner |
250+ Rdkafka ::Bindings . rd_kafka_CreateAcls (
251+ inner ,
252+ acls_array_ptr ,
253+ 1 ,
254+ admin_options_ptr ,
255+ queue_ptr
256+ )
257+ end
258+ rescue Exception
259+ CreateAclHandle . remove ( create_acl_handle . to_ptr . address )
260+ raise
261+ ensure
262+ Rdkafka ::Bindings . rd_kafka_AdminOptions_destroy ( admin_options_ptr )
263+ Rdkafka ::Bindings . rd_kafka_queue_destroy ( queue_ptr )
264+ Rdkafka ::Bindings . rd_kafka_AclBinding_destroy ( new_acl_ptr )
265+ end
266+
267+ create_acl_handle
268+ end
269+
270+ # Delete acl
271+ #
272+ # @param resource_type - values of type rd_kafka_ResourceType_t
273+ # https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L7307
274+ # valid values are:
275+ # RD_KAFKA_RESOURCE_TOPIC = 2
276+ # RD_KAFKA_RESOURCE_GROUP = 3
277+ # RD_KAFKA_RESOURCE_BROKER = 4
278+ # @param resource_pattern_type - values of type rd_kafka_ResourcePatternType_t
279+ # https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L7320
280+ # valid values are:
281+ # RD_KAFKA_RESOURCE_PATTERN_MATCH = 2
282+ # RD_KAFKA_RESOURCE_PATTERN_LITERAL = 3
283+ # RD_KAFKA_RESOURCE_PATTERN_PREFIXED = 4
284+ # @param operation - values of type rd_kafka_AclOperation_t
285+ # https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L8403
286+ # valid values are:
287+ # RD_KAFKA_ACL_OPERATION_ALL = 2
288+ # RD_KAFKA_ACL_OPERATION_READ = 3
289+ # RD_KAFKA_ACL_OPERATION_WRITE = 4
290+ # RD_KAFKA_ACL_OPERATION_CREATE = 5
291+ # RD_KAFKA_ACL_OPERATION_DELETE = 6
292+ # RD_KAFKA_ACL_OPERATION_ALTER = 7
293+ # RD_KAFKA_ACL_OPERATION_DESCRIBE = 8
294+ # RD_KAFKA_ACL_OPERATION_CLUSTER_ACTION = 9
295+ # RD_KAFKA_ACL_OPERATION_DESCRIBE_CONFIGS = 10
296+ # RD_KAFKA_ACL_OPERATION_ALTER_CONFIGS = 11
297+ # RD_KAFKA_ACL_OPERATION_IDEMPOTENT_WRITE = 12
298+ # @param permission_type - values of type rd_kafka_AclPermissionType_t
299+ # https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L8435
300+ # valid values are:
301+ # RD_KAFKA_ACL_PERMISSION_TYPE_DENY = 2
302+ # RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW = 3
303+ # @raise [RdkafkaError]
304+ #
305+ # @return [DeleteAclHandle] Delete acl handle that can be used to wait for the result of deleting the acl
306+ def delete_acl ( resource_type :, resource_name :, resource_pattern_type :, principal :, host :, operation :, permission_type :)
307+ closed_admin_check ( __method__ )
308+
309+ # Create a rd_kafka_AclBinding_t representing the acl to be deleted
310+ error_buffer = FFI ::MemoryPointer . from_string ( " " * 256 )
311+
312+ delete_acl_ptr = Rdkafka ::Bindings . rd_kafka_AclBindingFilter_new (
313+ resource_type ,
314+ resource_name ? FFI ::MemoryPointer . from_string ( resource_name ) : nil ,
315+ resource_pattern_type ,
316+ principal ? FFI ::MemoryPointer . from_string ( principal ) : nil ,
317+ host ? FFI ::MemoryPointer . from_string ( host ) : nil ,
318+ operation ,
319+ permission_type ,
320+ error_buffer ,
321+ 256
322+ )
323+
324+ if delete_acl_ptr . null?
325+ raise Rdkafka ::Config ::ConfigError . new ( error_buffer . read_string )
326+ end
327+
328+ # Note that rd_kafka_DeleteAcls can delete more than one acl at a time
329+ pointer_array = [ delete_acl_ptr ]
330+ acls_array_ptr = FFI ::MemoryPointer . new ( :pointer )
331+ acls_array_ptr . write_array_of_pointer ( pointer_array )
332+
333+ # Get a pointer to the queue that our request will be enqueued on
334+ queue_ptr = @native_kafka . with_inner do |inner |
335+ Rdkafka ::Bindings . rd_kafka_queue_get_background ( inner )
336+ end
337+
338+ if queue_ptr . null?
339+ Rdkafka ::Bindings . rd_kafka_AclBinding_destroy ( new_acl_ptr )
340+ raise Rdkafka ::Config ::ConfigError . new ( "rd_kafka_queue_get_background was NULL" )
341+ end
342+
343+ # Create and register the handle that we will return to the caller
344+ delete_acl_handle = DeleteAclHandle . new
345+ delete_acl_handle [ :pending ] = true
346+ delete_acl_handle [ :response ] = -1
347+ DeleteAclHandle . register ( delete_acl_handle )
348+
349+ admin_options_ptr = @native_kafka . with_inner do |inner |
350+ Rdkafka ::Bindings . rd_kafka_AdminOptions_new ( inner , Rdkafka ::Bindings ::RD_KAFKA_ADMIN_OP_DELETEACLS )
351+ end
352+
353+ Rdkafka ::Bindings . rd_kafka_AdminOptions_set_opaque ( admin_options_ptr , delete_acl_handle . to_ptr )
354+
355+ begin
356+ @native_kafka . with_inner do |inner |
357+ Rdkafka ::Bindings . rd_kafka_DeleteAcls (
358+ inner ,
359+ acls_array_ptr ,
360+ 1 ,
361+ admin_options_ptr ,
362+ queue_ptr
363+ )
364+ end
365+ rescue Exception
366+ DeleteAclHandle . remove ( delete_acl_handle . to_ptr . address )
367+ raise
368+ ensure
369+ Rdkafka ::Bindings . rd_kafka_AdminOptions_destroy ( admin_options_ptr )
370+ Rdkafka ::Bindings . rd_kafka_queue_destroy ( queue_ptr )
371+ Rdkafka ::Bindings . rd_kafka_AclBinding_destroy ( delete_acl_ptr )
372+ end
373+
374+ delete_acl_handle
375+ end
376+
377+ # Describe acls
378+ #
379+ # @param resource_type - values of type rd_kafka_ResourceType_t
380+ # https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L7307
381+ # valid values are:
382+ # RD_KAFKA_RESOURCE_TOPIC = 2
383+ # RD_KAFKA_RESOURCE_GROUP = 3
384+ # RD_KAFKA_RESOURCE_BROKER = 4
385+ # @param resource_pattern_type - values of type rd_kafka_ResourcePatternType_t
386+ # https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L7320
387+ # valid values are:
388+ # RD_KAFKA_RESOURCE_PATTERN_MATCH = 2
389+ # RD_KAFKA_RESOURCE_PATTERN_LITERAL = 3
390+ # RD_KAFKA_RESOURCE_PATTERN_PREFIXED = 4
391+ # @param operation - values of type rd_kafka_AclOperation_t
392+ # https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L8403
393+ # valid values are:
394+ # RD_KAFKA_ACL_OPERATION_ALL = 2
395+ # RD_KAFKA_ACL_OPERATION_READ = 3
396+ # RD_KAFKA_ACL_OPERATION_WRITE = 4
397+ # RD_KAFKA_ACL_OPERATION_CREATE = 5
398+ # RD_KAFKA_ACL_OPERATION_DELETE = 6
399+ # RD_KAFKA_ACL_OPERATION_ALTER = 7
400+ # RD_KAFKA_ACL_OPERATION_DESCRIBE = 8
401+ # RD_KAFKA_ACL_OPERATION_CLUSTER_ACTION = 9
402+ # RD_KAFKA_ACL_OPERATION_DESCRIBE_CONFIGS = 10
403+ # RD_KAFKA_ACL_OPERATION_ALTER_CONFIGS = 11
404+ # RD_KAFKA_ACL_OPERATION_IDEMPOTENT_WRITE = 12
405+ # @param permission_type - values of type rd_kafka_AclPermissionType_t
406+ # https://github.com/confluentinc/librdkafka/blob/292d2a66b9921b783f08147807992e603c7af059/src/rdkafka.h#L8435
407+ # valid values are:
408+ # RD_KAFKA_ACL_PERMISSION_TYPE_DENY = 2
409+ # RD_KAFKA_ACL_PERMISSION_TYPE_ALLOW = 3
410+ # @raise [RdkafkaError]
411+ #
412+ # @return [DescribeAclHandle] Describe acl handle that can be used to wait for the result of fetching acls
413+ def describe_acl ( resource_type :, resource_name :, resource_pattern_type :, principal :, host :, operation :, permission_type :)
414+ closed_admin_check ( __method__ )
415+
416+ # Create a rd_kafka_AclBinding_t with the filters to fetch existing acls
417+ error_buffer = FFI ::MemoryPointer . from_string ( " " * 256 )
418+ describe_acl_ptr = Rdkafka ::Bindings . rd_kafka_AclBindingFilter_new (
419+ resource_type ,
420+ resource_name ? FFI ::MemoryPointer . from_string ( resource_name ) : nil ,
421+ resource_pattern_type ,
422+ principal ? FFI ::MemoryPointer . from_string ( principal ) : nil ,
423+ host ? FFI ::MemoryPointer . from_string ( host ) : nil ,
424+ operation ,
425+ permission_type ,
426+ error_buffer ,
427+ 256
428+ )
429+ if describe_acl_ptr . null?
430+ raise Rdkafka ::Config ::ConfigError . new ( error_buffer . read_string )
431+ end
432+
433+ # Get a pointer to the queue that our request will be enqueued on
434+ queue_ptr = @native_kafka . with_inner do |inner |
435+ Rdkafka ::Bindings . rd_kafka_queue_get_background ( inner )
436+ end
437+
438+ if queue_ptr . null?
439+ Rdkafka ::Bindings . rd_kafka_AclBinding_destroy ( new_acl_ptr )
440+ raise Rdkafka ::Config ::ConfigError . new ( "rd_kafka_queue_get_background was NULL" )
441+ end
442+
443+ # Create and register the handle that we will return to the caller
444+ describe_acl_handle = DescribeAclHandle . new
445+ describe_acl_handle [ :pending ] = true
446+ describe_acl_handle [ :response ] = -1
447+ DescribeAclHandle . register ( describe_acl_handle )
448+
449+ admin_options_ptr = @native_kafka . with_inner do |inner |
450+ Rdkafka ::Bindings . rd_kafka_AdminOptions_new ( inner , Rdkafka ::Bindings ::RD_KAFKA_ADMIN_OP_DESCRIBEACLS )
451+ end
452+
453+ Rdkafka ::Bindings . rd_kafka_AdminOptions_set_opaque ( admin_options_ptr , describe_acl_handle . to_ptr )
454+
455+ begin
456+ @native_kafka . with_inner do |inner |
457+ Rdkafka ::Bindings . rd_kafka_DescribeAcls (
458+ inner ,
459+ describe_acl_ptr ,
460+ admin_options_ptr ,
461+ queue_ptr
462+ )
463+ end
464+ rescue Exception
465+ DescribeAclHandle . remove ( describe_acl_handle . to_ptr . address )
466+ raise
467+ ensure
468+ Rdkafka ::Bindings . rd_kafka_AdminOptions_destroy ( admin_options_ptr )
469+ Rdkafka ::Bindings . rd_kafka_queue_destroy ( queue_ptr )
470+ Rdkafka ::Bindings . rd_kafka_AclBinding_destroy ( describe_acl_ptr )
471+ end
472+
473+ describe_acl_handle
474+ end
475+
166476 private
167477 def closed_admin_check ( method )
168478 raise Rdkafka ::ClosedAdminError . new ( method ) if closed?
0 commit comments