# frozen_string_literal: true require 'json' module FlippRubyKafka module Utils # Generates the Microservice Platform topic validation file. # Use rake flipp_ruby_kafka:topic_validation my_service to run it from command line. class PlatformTopicValidation class << self # @param service_name [String] 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 # @param service_name [String] # @return [Hash] 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 end end end end