Class: Karafka::Admin::Configs::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/admin/configs/config.rb

Overview

Represents a single config entry that is related to a resource

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, value:, default: -1,, read_only: -1,, sensitive: -1,, synonym: -1,, synonyms: []) ⇒ Config

Note:

For alter operations only name and value are needed

Creates new config instance either for reading or as part of altering operation

Parameters:

  • name (String)

    config name

  • value (String)

    config value

  • default (Integer) (defaults to: -1,)

    1 if default

  • read_only (Integer) (defaults to: -1,)

    1 if read only

  • sensitive (Integer) (defaults to: -1,)

    1 if sensitive

  • synonym (Integer) (defaults to: -1,)

    1 if synonym

  • synonyms (Array) (defaults to: [])

    given config synonyms (if any)



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/karafka/admin/configs/config.rb', line 41

def initialize(
  name:,
  value:,
  default: -1,
  read_only: -1,
  sensitive: -1,
  synonym: -1,
  synonyms: []
)
  @name = name
  @value = value
  @synonyms = []
  @default = default
  @read_only = read_only
  @sensitive = sensitive
  @synonym = synonym
  @synonyms = synonyms
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/karafka/admin/configs/config.rb', line 8

def name
  @name
end

#synonymsObject (readonly)

Returns the value of attribute synonyms.



8
9
10
# File 'lib/karafka/admin/configs/config.rb', line 8

def synonyms
  @synonyms
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/karafka/admin/configs/config.rb', line 8

def value
  @value
end

Class Method Details

.from_rd_kafka(rd_kafka_config) ⇒ Config

Creates a single config entry from the Rdkafka config result entry

Parameters:

  • rd_kafka_config (Rdkafka::Admin::ConfigBindingResult)

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/karafka/admin/configs/config.rb', line 15

def from_rd_kafka(rd_kafka_config)
  new(
    name: rd_kafka_config.name,
    value: rd_kafka_config.value,
    read_only: rd_kafka_config.read_only,
    default: rd_kafka_config.default,
    sensitive: rd_kafka_config.sensitive,
    synonym: rd_kafka_config.synonym,
    synonyms: rd_kafka_config.synonyms.map do |rd_kafka_synonym|
      from_rd_kafka(rd_kafka_synonym)
    end
  )
end

Instance Method Details

#default?Boolean

Returns Is the config property is set to its default value on the broker.

Returns:

  • (Boolean)

    Is the config property is set to its default value on the broker



61
# File 'lib/karafka/admin/configs/config.rb', line 61

def default? = @default.positive?

#read_only?Boolean

Returns Is the config property is read-only on the broker.

Returns:

  • (Boolean)

    Is the config property is read-only on the broker



64
# File 'lib/karafka/admin/configs/config.rb', line 64

def read_only? = @read_only.positive?

#sensitive?Boolean

Returns if the config property contains sensitive information (such as security configuration.

Returns:

  • (Boolean)

    if the config property contains sensitive information (such as security configuration



68
# File 'lib/karafka/admin/configs/config.rb', line 68

def sensitive? = @sensitive.positive?

#synonym?Boolean

Returns is this entry is a synonym.

Returns:

  • (Boolean)

    is this entry is a synonym



71
# File 'lib/karafka/admin/configs/config.rb', line 71

def synonym? = @synonym.positive?

#to_native_hashHash

Returns hash that we can use to operate with rdkafka.

Returns:

  • (Hash)

    hash that we can use to operate with rdkafka



74
75
76
77
# File 'lib/karafka/admin/configs/config.rb', line 74

def to_native_hash = {
  name: name,
  value: value
}.freeze