# frozen_string_literal: true require 'json' class JsonFileResolver def initialize(path) @path = path begin file = File.read(@path) @json_object = JSON.parse(file) rescue Errno::ENOENT raise "Configuration file #{@path} not found. Please check your configuration file." end end def get_license_key @json_object["licenseKey"] || (raise "License key not found in configuration file. Please check your configuration file.") end def get_runtimes @json_object["runtimes"] end def get_runtime(runtime_name, config_name) runtimes = get_runtimes if runtimes.key?(runtime_name) runtime = runtimes[runtime_name] if runtime.is_a?(Array) return runtime.find { |item| item["name"] == config_name } elsif runtime["name"] == config_name return runtime end end raise "Runtime config #{config_name} not found in configuration file for runtime #{runtime_name}. Please check your configuration file." end def get_channel(runtime_name, config_name) runtime = get_runtime(runtime_name, config_name) runtime["channel"] || (raise "Channel key not found in configuration file for config #{config_name}. Please check your configuration file.") end def get_channel_type(runtime_name, config_name) channel = get_channel(runtime_name, config_name) channel["type"] || (raise "Channel type not found in configuration file for config #{config_name}. Please check your configuration file.") end def get_channel_host(runtime_name, config_name) channel = get_channel(runtime_name, config_name) channel["host"] || (raise "Channel host not found in configuration file for config #{config_name}. Please check your configuration file.") end def get_channel_port(runtime_name, config_name) channel = get_channel(runtime_name, config_name) channel["port"] || (raise "Channel port not found in configuration file for config #{config_name}. Please check your configuration file.") end def get_modules(runtime_name, config_name) runtime = get_runtime(runtime_name, config_name) if runtime.key?('modules') return runtime['modules'] end "" end end