Module: A2A::Configuration::Validator
- Included in:
- A2A::Configuration
- Defined in:
- lib/a2a/configuration/validator.rb
Overview
Module for configuration validation
Instance Method Summary collapse
-
#validate! ⇒ Object
Validate the configuration.
-
#validate_basic_config ⇒ Object
private
Validation methods.
- #validate_boolean_options ⇒ Object private
- #validate_environment_config ⇒ Object private
-
#validate_log_level ⇒ Object
private
Validate log level with proper string/symbol handling.
-
#validate_protocol_version ⇒ Object
private
Validate protocol version with proper nil/blank handling.
- #validate_rails_config ⇒ Object private
- #validate_redis_config ⇒ Object private
- #validate_timeout_values ⇒ Object private
- #validate_transport_config ⇒ Object private
Instance Method Details
#validate! ⇒ Object
Validate the configuration
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/a2a/configuration/validator.rb', line 9 def validate! errors = [] begin validate_basic_config rescue A2A::Errors::ConfigurationError => e errors << e. end begin validate_transport_config rescue A2A::Errors::ConfigurationError => e errors << e. end if rails_integration begin validate_rails_config rescue A2A::Errors::ConfigurationError => e errors << e. end end begin validate_redis_config rescue A2A::Errors::ConfigurationError => e errors << e. end begin validate_environment_config rescue A2A::Errors::ConfigurationError => e errors << e. end begin validate_timeout_values rescue A2A::Errors::ConfigurationError => e errors << e. end begin rescue A2A::Errors::ConfigurationError => e errors << e. end unless errors.empty? raise A2A::Errors::ConfigurationError, "Configuration validation failed:\n - #{errors.join("\n - ")}" end true end |
#validate_basic_config ⇒ Object (private)
Validation methods
67 68 69 70 71 72 |
# File 'lib/a2a/configuration/validator.rb', line 67 def validate_basic_config raise A2A::Errors::ConfigurationError, "default_timeout must be positive" if default_timeout <= 0 validate_log_level validate_protocol_version end |
#validate_boolean_options ⇒ Object (private)
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/a2a/configuration/validator.rb', line 156 def = { streaming_enabled: streaming_enabled, push_notifications_enabled: push_notifications_enabled, rails_integration: rails_integration, auto_mount: auto_mount, middleware_enabled: middleware_enabled, authentication_required: authentication_required, cors_enabled: cors_enabled, rate_limiting_enabled: rate_limiting_enabled, logging_enabled: logging_enabled, webhook_authentication_required: webhook_authentication_required } .each do |option, value| next if value.nil? next if [true, false].include?(value) raise A2A::Errors::ConfigurationError, "#{option} must be true or false, got: #{value.inspect}" end end |
#validate_environment_config ⇒ Object (private)
138 139 140 141 142 143 144 145 146 147 |
# File 'lib/a2a/configuration/validator.rb', line 138 def validate_environment_config return if environment.nil? raise A2A::Errors::ConfigurationError, "environment must be a string" unless environment.is_a?(String) valid_environments = %w[development test production staging] return if valid_environments.include?(environment) logger&.warn("Unknown environment: #{environment}. Valid environments: #{valid_environments.join(', ')}") end |
#validate_log_level ⇒ Object (private)
Validate log level with proper string/symbol handling
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/a2a/configuration/validator.rb', line 75 def validate_log_level return if log_level.nil? # Accept both string and symbol log levels, normalize to symbol normalized_level = log_level.to_s.downcase valid_levels = %w[debug info warn error fatal] unless valid_levels.include?(normalized_level) raise A2A::Errors::ConfigurationError, "log_level must be one of: #{valid_levels.join(', ')}. Got: #{log_level.inspect}" end # Normalize to symbol for internal use @log_level = normalized_level.to_sym end |
#validate_protocol_version ⇒ Object (private)
Validate protocol version with proper nil/blank handling
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/a2a/configuration/validator.rb', line 92 def validate_protocol_version return if protocol_version.nil? if protocol_version.respond_to?(:strip) && protocol_version.strip.empty? raise A2A::Errors::ConfigurationError, "protocol_version cannot be blank" elsif protocol_version.respond_to?(:empty?) && protocol_version.empty? raise A2A::Errors::ConfigurationError, "protocol_version cannot be empty" end end |
#validate_rails_config ⇒ Object (private)
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/a2a/configuration/validator.rb', line 119 def validate_rails_config raise A2A::Errors::ConfigurationError, "mount_path must start with '/'" if mount_path && !mount_path.start_with?("/") # Only validate Rails version if Rails is available and version checking is needed return unless rails_available? && rails_version_requires_validation? current_version = rails_version raise A2A::Errors::ConfigurationError, "Rails integration requires Rails 6.0 or higher. Current version: #{current_version}" end |
#validate_redis_config ⇒ Object (private)
130 131 132 133 134 135 136 |
# File 'lib/a2a/configuration/validator.rb', line 130 def validate_redis_config raise A2A::Errors::ConfigurationError, "redis_config must be a hash" if redis_config && !redis_config.is_a?(Hash) return unless redis_config && redis_config[:url] && !redis_config[:url].is_a?(String) raise A2A::Errors::ConfigurationError, "redis_config[:url] must be a string" end |
#validate_timeout_values ⇒ Object (private)
149 150 151 152 153 154 |
# File 'lib/a2a/configuration/validator.rb', line 149 def validate_timeout_values return unless default_timeout && (!default_timeout.is_a?(Numeric) || default_timeout <= 0) raise A2A::Errors::ConfigurationError, "default_timeout must be a positive number, got: #{default_timeout.inspect}" end |
#validate_transport_config ⇒ Object (private)
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/a2a/configuration/validator.rb', line 104 def validate_transport_config valid_transports = %w[JSONRPC GRPC HTTP+JSON] unless valid_transports.include?(default_transport) raise A2A::Errors::ConfigurationError, "default_transport must be one of: #{valid_transports.join(', ')}" end unless default_input_modes.is_a?(Array) && default_input_modes.all?(String) raise A2A::Errors::ConfigurationError, "default_input_modes must be an array of strings" end return if default_output_modes.is_a?(Array) && default_output_modes.all?(String) raise A2A::Errors::ConfigurationError, "default_output_modes must be an array of strings" end |