Class: Hooks::Core::ConfigValidator
- Inherits:
-
Object
- Object
- Hooks::Core::ConfigValidator
- Defined in:
- lib/hooks/core/config_validator.rb
Overview
Validates configuration using Dry::Schema
Defined Under Namespace
Classes: ValidationError
Constant Summary collapse
- GLOBAL_CONFIG_SCHEMA =
Global configuration schema
Dry::Schema.Params do required(:handler_plugin_dir).filled(:string) optional(:auth_plugin_dir).maybe(:string) optional(:lifecycle_plugin_dir).maybe(:string) optional(:instruments_plugin_dir).maybe(:string) required(:log_level).filled(:string, included_in?: %w[debug info warn error]) optional(:request_limit).filled(:integer, gt?: 0) optional(:request_timeout).filled(:integer, gt?: 0) required(:root_path).filled(:string) optional(:health_path).filled(:string) optional(:version_path).filled(:string) required(:environment).filled(:string, included_in?: %w[development production]) optional(:endpoints_dir).filled(:string) optional(:use_catchall_route).filled(:bool) optional(:normalize_headers).filled(:bool) optional(:default_format).filled(:symbol, included_in?: %i[json txt xml any]) optional(:ip_filtering).hash do optional(:ip_header).filled(:string) optional(:allowlist).array(:string) optional(:blocklist).array(:string) end end
- ENDPOINT_CONFIG_SCHEMA =
Endpoint configuration schema
Dry::Schema.Params do required(:path).filled(:string) required(:handler).filled(:string) optional(:method).filled(:string, included_in?: %w[get post put patch delete head options]) optional(:auth).hash do required(:type).filled(:string) optional(:secret_env_key).filled(:string) optional(:header).filled(:string) optional(:algorithm).filled(:string) optional(:timestamp_header).filled(:string) optional(:timestamp_tolerance).filled(:integer, gt?: 0) optional(:format).filled(:string) optional(:version_prefix).filled(:string) optional(:payload_template).filled(:string) optional(:header_format).filled(:string) optional(:signature_key).filled(:string) optional(:timestamp_key).filled(:string) optional(:structured_header_separator).filled(:string) optional(:key_value_separator).filled(:string) end optional(:ip_filtering).hash do optional(:ip_header).filled(:string) optional(:allowlist).array(:string) optional(:blocklist).array(:string) end optional(:opts).hash end
Class Method Summary collapse
-
.validate_endpoint_config(config) ⇒ Hash
Validate endpoint configuration with additional security checks.
-
.validate_endpoints(endpoints) ⇒ Array<Hash>
Validate array of endpoint configurations.
-
.validate_global_config(config) ⇒ Hash
Validate global configuration.
Class Method Details
.validate_endpoint_config(config) ⇒ Hash
Validate endpoint configuration with additional security checks
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/hooks/core/config_validator.rb', line 90 def self.validate_endpoint_config(config) result = ENDPOINT_CONFIG_SCHEMA.call(config) if result.failure? raise ValidationError, "Invalid endpoint configuration: #{result.errors.to_h}" end validated_config = result.to_h # Security: Additional validation for handler name handler_name = validated_config[:handler] unless valid_handler_name?(handler_name) raise ValidationError, "Invalid handler name: #{handler_name}" end validated_config end |
.validate_endpoints(endpoints) ⇒ Array<Hash>
Validate array of endpoint configurations
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/hooks/core/config_validator.rb', line 113 def self.validate_endpoints(endpoints) validated_endpoints = [] endpoints.each_with_index do |endpoint, index| begin validated_endpoints << validate_endpoint_config(endpoint) rescue ValidationError => e raise ValidationError, "Endpoint #{index}: #{e.}" end end validated_endpoints end |
.validate_global_config(config) ⇒ Hash
Validate global configuration
75 76 77 78 79 80 81 82 83 |
# File 'lib/hooks/core/config_validator.rb', line 75 def self.validate_global_config(config) result = GLOBAL_CONFIG_SCHEMA.call(config) if result.failure? raise ValidationError, "Invalid global configuration: #{result.errors.to_h}" end result.to_h end |