Class: Gritz::Compat::Gruf::ConfigConverter

Inherits:
Object
  • Object
show all
Defined in:
/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/compat/gruf/config_converter.rb

Overview

Converts a deliberately small, literal-only subset of Gruf.configure.

Constant Summary collapse

ARGUMENTS =
{
  "grpc.max_receive_message_length" => [:max_receive_message_size, 1],
  "grpc.max_send_message_length" => [:max_send_message_size, 1],
  "grpc.max_metadata_size" => [:max_metadata_size, 1],
  "grpc.max_connection_age_ms" => [:max_connection_age, 1000.0],
  "grpc.max_connection_age_grace_ms" => [:max_connection_age_grace, 1000.0],
  "grpc.keepalive_time_ms" => [:keepalive_time, 1000.0]
}.freeze

Instance Method Summary collapse

Instance Method Details

#convert(source) ⇒ String

Returns Gritz configuration requiring manual review before use.

Parameters:

  • source (String) —

    Ruby source containing one static Gruf.configure block

Returns:

  • (String) —

    Gritz configuration requiring manual review before use

Raises:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File '/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/compat/gruf/config_converter.rb', line 24

def convert(source)
  settings = assignments(source)
  output = { workers: 0 }
  settings.each do |name, value|
    case name
    when "server_binding_url" then output[:bind] = value
    when "rpc_server_options" then server_options(value, output)
    when "use_ssl", "ssl_crt_file", "ssl_key_file" then next
    when "default_client_host", "default_channel_credentials"
      unsupported("#{name}: configure Gritz::Client.define manually")
    else unsupported("#{name}: manual migration required; see migrating-from-gruf.md")
    end
  end
  config = Gritz::Configuration.new
  output.each { |name, value| config.public_send("#{name}=", value) }
  config.validate!
  tls = tls_options(settings)
  output[:tls] = tls unless tls.empty?
  ["# Review controller registration, interceptors and fork safety before starting.",
   'require "gritz/compat/gruf"', "", *output.map { |name, value| "#{name}(#{value.inspect})" }, "",
   "# register_controller YourMigratedController", ""].join("\n")
end