class

Shellmin::ConfigAccess

Inherits Reference < Object

Secure Configuration Access for Scripts

Provides controlled access to Shellmin configuration for scripts while maintaining security. Scripts can read configuration values but cannot modify them.

Security Features

  • Read-only access: Scripts can only read configuration, never modify
  • Path validation: Configuration keys must be valid paths
  • Type safety: Values are returned as JSON::Any for safe handling
  • Access logging: All configuration access is logged for audit trails

Usage in Scripts

# Get a configuration value
db_host=$(shellmin config get hosts.web-server.host)

# Check if a configuration key exists
if shellmin config has hosts.web-server.user; then
  echo "User configured"
fi

# Get all configuration as JSON
config_json=$(shellmin config dump)

# Get configuration for current host
my_config=$(shellmin config get hosts.$SHELLMIN_HOST_NAME)

Configuration Paths

Configuration is accessed using dot-notation paths:

  • hosts.web-server.host - Host address
  • hosts.web-server.user - SSH username
  • version - Shellmin version

Security Considerations

  • Configuration access is logged for audit purposes
  • Sensitive values (passwords, keys) are not exposed in logs
  • Path traversal attacks are prevented
  • Only valid configuration keys can be accessed

Constructors

new(config_manager : ConfigManager = Shellmin.config_manager)

Initialize with configuration manager

Source

Instance methods

dump

Get all configuration as JSON string

Source
get(path : String) : YAML::Any | Nil

Get a configuration value by path

Source
get_section(path : String) : String | Nil

Get configuration section as JSON string

Source
has_key?(path : String) : Bool

Check if a configuration path exists

Source
keys(path : String = "") : Array(String)

List available keys at a path

Source