Implement server-side configuration management with validation and storage layout
Add the ServerConfig struct to the pwr-server crate, controlling all
aspects of the daemon’s operation. The configuration specifies the TCP
bind address and port (defaulting to 0.0.0.0:9742), the filesystem root
for project storage (defaulting to /srv/pwr/projects), paths to the TLS
certificate and private key files, the hex-encoded 256-bit pre-shared
authentication token that clients must present during the handshake, and
operational limits including maximum concurrent connections (default 32),
maximum project size in gigabytes (default 500), and an idle timeout for
authenticated connections (default 300 seconds).
Validation is performed at load time: the port must be non-zero, the auth
token must be non-empty, and both max_project_size_gb and max_connections
must be positive. The validate method returns a plain String error so the
caller can present it directly to the user without depending on the
shared pwr-core error types, keeping the server crate’s dependency
surface minimal during early development.
A config file search strategy checks four locations in order: an explicit
–config CLI path, the current working directory (for development), the
XDG config directory under ~/.config/pwr/, and the system-wide
/etc/pwr/server.toml. Helper methods compute derived paths:
project_dir returns the per-UUID storage subdirectory, registry_path
returns the JSON index file location, and bind_addr formats the socket
address for TcpListener::bind.
Seven tests cover default validation, empty-token rejection, zero-port
rejection, bind address formatting, project directory path generation,
registry path naming, and a full save-load round-trip through TOML
serialization and deserialization.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.