Module: Rdkafka::Helpers::OAuth

Included in:
Admin, Consumer, Producer
Defined in:
lib/rdkafka/helpers/oauth.rb

Instance Method Summary collapse

Instance Method Details

#oauthbearer_set_token(token:, lifetime_ms:, principal_name:, extensions: nil) ⇒ Integer

Set the OAuthBearer token

Parameters:

  • token (String)

    the mandatory token value to set, often (but not necessarily) a JWS compact serialization as per tools.ietf.org/html/rfc7515#section-3.1.

  • lifetime_ms (Integer)

    when the token expires, in terms of the number of milliseconds since the epoch. See currentmillis.com/.

  • principal_name (String)

    the mandatory Kafka principal name associated with the token.

  • extensions (Hash) (defaults to: nil)

    optional SASL extensions key-value pairs to be communicated to the broker as additional key-value pairs during the initial client response as per tools.ietf.org/html/rfc7628#section-3.1.

Returns:

  • (Integer)

    0 on success



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rdkafka/helpers/oauth.rb', line 13

def oauthbearer_set_token(token:, lifetime_ms:, principal_name:, extensions: nil)
  error_buffer = FFI::MemoryPointer.from_string(" " * 256)

  response = @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_oauthbearer_set_token(
      inner, token, lifetime_ms, principal_name,
      flatten_extensions(extensions), extension_size(extensions), error_buffer, 256
    )
  end

  return response if response.zero?

  oauthbearer_set_token_failure("Failed to set token: #{error_buffer.read_string}")

  response
end

#oauthbearer_set_token_failure(reason) ⇒ Object

Marks failed oauth token acquire in librdkafka

Parameters:

  • reason (String)

    human readable error reason for failing to acquire token



33
34
35
36
37
38
39
40
# File 'lib/rdkafka/helpers/oauth.rb', line 33

def oauthbearer_set_token_failure(reason)
  @native_kafka.with_inner do |inner|
    Rdkafka::Bindings.rd_kafka_oauthbearer_set_token_failure(
      inner,
      reason
    )
  end
end