class

Shellmin::ConfigManager

Inherits Reference < Object

Configuration and connection management for Shellmin

This class handles all configuration operations and provides thread-safe access to configuration data and connection management.

Thread Safety

All operations are thread-safe using mutex synchronization to prevent race conditions when accessing shared configuration state.

Configuration File

Configuration is stored in YAML format at ~/.shellmin/config.yaml:

hosts:
  - name: web-host
    host: 192.168.1.100
    user: admin

Modern configuration manager with advanced caching

Constructors

new(connection_manager : Shellmin::ConnectionManager | Nil = nil)

Modern constructor with dependency injection

Source

Instance methods

config
Source
config=(new_config : Hash(String, YAML::Any)) : Hash(String, YAML::Any)

Set new configuration (thread-safe)

Replaces the entire configuration with a new one.

Source
connection_manager

Get the connection manager instance

Source
default_config_path
Source
get_distro_facts(os_id : String) : Hash(String, String)
Source
global_config_dir
Source
load_config

Load configuration from file with multiple format support

Attempts to load configuration from the default path or SHELLMIN_CONFIG. Supports YAML, JSON, and TOML formats with automatic detection. Returns true on success, false on failure.

Error Handling

  • YAML::ParseException: Invalid YAML syntax
  • JSON::ParseException: Invalid JSON syntax
  • File::Error: File access issues
Source
load_context

Load all configuration layers (The "Onion" Model)

Source
project_config_dir
Source
save_config

Save current configuration to file

Writes the current configuration to the default path. Creates parent directories if they don't exist.

Source
update_config

Update configuration atomically

Provides a thread-safe way to modify configuration using a block. The block receives the current config and should return the new config.

config_manager.update_config do |config|
  config["new_key"] = YAML.parse("new_value")
  config
end
Source

Nested types