Class: FlippRubyKafka::Utils::PlatformTopicValidation

Inherits:
Object
  • Object
show all
Defined in:
lib/flipp_ruby_kafka/utils/platform_topic_validation.rb

Overview

Generates the Microservice Platform topic validation file. Use rake flipp_ruby_kafka:topic_validation my_service to run it from command line.

Class Method Summary collapse

Class Method Details

.generate_config(service_name) ⇒ Hash

Parameters:

  • service_name (String)

Returns:

  • (Hash)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/flipp_ruby_kafka/utils/platform_topic_validation.rb', line 21

def generate_config(service_name)
  acls = []
  Deimos.config.producer_objects.each do |k|
    next if k.topic.blank?

    acls.push(topic: k.topic, role: 'producer')
  end
  Deimos.config.consumer_objects.each do |k|
    next if k.topic.blank?

    acls.push(topic: k.topic, role: 'consumer')
  end
  {
    service: service_name,
    acls: acls
  }
end

.save_config_to_file(service_name) ⇒ Object

Parameters:

  • service_name (String)


12
13
14
15
16
17
# File 'lib/flipp_ruby_kafka/utils/platform_topic_validation.rb', line 12

def save_config_to_file(service_name)
  config = generate_config(service_name)
  File.open("#{Rails.root}/topic-validation.json", 'w') do |f|
    f.write(config.to_json)
  end
end