Class: Msf::MCP::Config::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/core/mcp/config/loader.rb

Class Method Summary collapse

Class Method Details

.load(file_path) ⇒ Hash

Load configuration from YAML file with environment variable overrides

Parameters:

  • file_path (String)

    Path to YAML configuration file

Returns:

  • (Hash)

    Configuration hash with symbolized keys

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/msf/core/mcp/config/loader.rb', line 13

def self.load(file_path)
  unless File.exist?(file_path)
    raise ConfigurationError, "Configuration file not found: #{file_path}"
  end

  begin
    config = YAML.safe_load_file(file_path, symbolize_names: true)
  rescue Psych::SyntaxError => e
    raise ConfigurationError, "Invalid YAML syntax in #{file_path}: #{e.message}"
  end

  unless config.is_a?(Hash)
    raise ConfigurationError, "Configuration file must contain a YAML hash/dictionary"
  end

  apply_defaults(config)
  apply_env_overrides(config)
  config
end

.load_from_hash(config_hash) ⇒ Hash

Load configuration from hash (for testing)

Parameters:

  • config_hash (Hash)

    Configuration hash

Returns:

  • (Hash)

    Configuration hash with defaults and env overrides



37
38
39
40
41
42
# File 'lib/msf/core/mcp/config/loader.rb', line 37

def self.load_from_hash(config_hash)
  config = config_hash.dup
  apply_defaults(config)
  apply_env_overrides(config)
  config
end