From 8f38d3d9f4084863652bc3323a1c3e41c53962c1 Mon Sep 17 00:00:00 2001 From: prosolis <5590409+prosolis@users.noreply.github.com> Date: Sun, 24 May 2026 21:05:41 -0700 Subject: [PATCH] Switch config format from YAML to TOML Replaces gopkg.in/yaml.v3 with github.com/BurntSushi/toml. Updates struct tags, default config path, Dockerfile CMD, README, and ships config.example.toml in place of the YAML example. ${ENV_VAR} expansion still runs on the raw file before parsing, so the behavior is unchanged. --- Dockerfile | 2 +- README.md | 8 ++++---- config.example.toml | 43 +++++++++++++++++++++++++++++++++++++++ config.example.yaml | 42 -------------------------------------- go.mod | 2 +- go.sum | 4 ++-- internal/config/config.go | 40 ++++++++++++++++++------------------ main.go | 2 +- 8 files changed, 72 insertions(+), 71 deletions(-) create mode 100644 config.example.toml delete mode 100644 config.example.yaml diff --git a/Dockerfile b/Dockerfile index 67ca357..db3b5e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,4 +18,4 @@ COPY --from=build /out/bellhop /usr/local/bin/bellhop USER bellhop VOLUME ["/app/data"] ENTRYPOINT ["/usr/local/bin/bellhop"] -CMD ["-config", "/app/config.yaml"] +CMD ["-config", "/app/config.toml"] diff --git a/README.md b/README.md index 9caa9d2..ff61e0f 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Any member of an allowlisted room may issue commands. The bot auto-joins on invi ## Configuration -Copy `config.example.yaml` to `config.yaml` and edit. The loader expands `${ENV_VAR}` references at load time, so secrets can come from the environment. +Copy `config.example.toml` to `config.toml` and edit. The loader expands `${ENV_VAR}` references at load time, so secrets can come from the environment. Required: @@ -43,7 +43,7 @@ curl -H "X-Api-Key: YOUR_KEY" https://radarr.example.com/api/v3/qualityprofile ```bash go build -tags goolm -o bellhop ./ -./bellhop -config config.yaml +./bellhop -config config.toml ``` The `goolm` tag uses the pure-Go olm implementation so libolm isn't needed. @@ -54,7 +54,7 @@ The `goolm` tag uses the pure-Go olm implementation so libolm isn't needed. docker build -t bellhop . docker run -d \ --name bellhop \ - -v "$PWD/config.yaml:/app/config.yaml:ro" \ + -v "$PWD/config.toml:/app/config.toml:ro" \ -v bellhop-data:/app/data \ bellhop ``` @@ -70,7 +70,7 @@ The bot bootstraps cross-signing on first run and persists Olm/Megolm sessions i ``` main.go internal/ - config/ — YAML loader with ${ENV_VAR} expansion + config/ — TOML loader with ${ENV_VAR} expansion matrix/ — mautrix client: login, device persistence, E2EE, sync loop arr/ — Radarr/Sonarr/Lidarr HTTP clients bot/ — command parser + dispatch + threaded replies diff --git a/config.example.toml b/config.example.toml new file mode 100644 index 0000000..2065ab8 --- /dev/null +++ b/config.example.toml @@ -0,0 +1,43 @@ +# Bellhop config. Values like ${ENV_VAR} are expanded from the environment +# at load time so secrets can stay out of this file. + +[matrix] +homeserver = "https://matrix.example.com" +user_id = "@bellhop:example.com" +password = "${BELLHOP_MATRIX_PASSWORD}" + +# Optional. Defaults shown. +display_name = "Bellhop" +data_dir = "./data" # device.json + crypto.db live here +pickle_key = "${BELLHOP_PICKLE_KEY}" # encrypts the crypto store; pick something stable +command_prefix = "!" + +# Rooms the bot will respond to commands in. Messages anywhere else are +# ignored. The bot auto-joins on invite, but joining alone does not grant +# command access — the room ID must appear here. +allowed_rooms = [ + "!room-id-one:example.com", + "!room-id-two:example.com", +] + +# Configure any subset. Omit a section to disable that command: +# leaving out [services.radarr] makes `!movie` reply "Radarr is not configured". + +[services.radarr] +url = "https://radarr.example.com" +api_key = "${RADARR_API_KEY}" +quality_profile_id = 1 +root_folder = "/movies" + +[services.sonarr] +url = "https://sonarr.example.com" +api_key = "${SONARR_API_KEY}" +quality_profile_id = 1 +root_folder = "/tv" + +[services.lidarr] +url = "https://lidarr.example.com" +api_key = "${LIDARR_API_KEY}" +quality_profile_id = 1 +metadata_profile_id = 1 # required for Lidarr only +root_folder = "/music" diff --git a/config.example.yaml b/config.example.yaml deleted file mode 100644 index 65f60d2..0000000 --- a/config.example.yaml +++ /dev/null @@ -1,42 +0,0 @@ -# Bellhop config. Values like ${ENV_VAR} are expanded from the environment -# at load time so secrets can stay out of this file. - -matrix: - homeserver: https://matrix.example.com - user_id: "@bellhop:example.com" - password: ${BELLHOP_MATRIX_PASSWORD} - - # Optional. Defaults shown. - display_name: Bellhop - data_dir: ./data # device.json + crypto.db live here - pickle_key: ${BELLHOP_PICKLE_KEY} # encrypts the crypto store; pick something stable - command_prefix: "!" - - # Rooms the bot will respond to commands in. Messages anywhere else are - # ignored. The bot auto-joins on invite, but joining alone does not grant - # command access — the room ID must appear here. - allowed_rooms: - - "!room-id-one:example.com" - - "!room-id-two:example.com" - -# Configure any subset. Omit a block to disable that command: -# leaving out `radarr` makes `!movie` reply "Radarr is not configured". -services: - radarr: - url: https://radarr.example.com - api_key: ${RADARR_API_KEY} - quality_profile_id: 1 - root_folder: /movies - - sonarr: - url: https://sonarr.example.com - api_key: ${SONARR_API_KEY} - quality_profile_id: 1 - root_folder: /tv - - lidarr: - url: https://lidarr.example.com - api_key: ${LIDARR_API_KEY} - quality_profile_id: 1 - metadata_profile_id: 1 # required for Lidarr only - root_folder: /music diff --git a/go.mod b/go.mod index d53ef71..42242de 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module bellhop go 1.25.0 require ( - gopkg.in/yaml.v3 v3.0.1 + github.com/BurntSushi/toml v1.6.0 maunium.net/go/mautrix v0.28.0 ) diff --git a/go.sum b/go.sum index 4edd1ee..1d8a8f2 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo= filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc= +github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk= +github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU= github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -41,8 +43,6 @@ golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ= golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc= golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= maunium.net/go/mautrix v0.28.0 h1:vBakLzf8MAdfED3NzAKiMeKQbc3AQ4EAS03NC+TVMXQ= diff --git a/internal/config/config.go b/internal/config/config.go index f95118f..6638f1c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -6,42 +6,42 @@ import ( "os" "regexp" - "gopkg.in/yaml.v3" + "github.com/BurntSushi/toml" ) var envBracketRe = regexp.MustCompile(`\$\{([^}]+)\}`) type Config struct { - Matrix MatrixConfig `yaml:"matrix"` - Services ServicesConfig `yaml:"services"` + Matrix MatrixConfig `toml:"matrix"` + Services ServicesConfig `toml:"services"` } type MatrixConfig struct { - Homeserver string `yaml:"homeserver"` - UserID string `yaml:"user_id"` - Password string `yaml:"password"` - PickleKey string `yaml:"pickle_key"` - DisplayName string `yaml:"display_name"` - DataDir string `yaml:"data_dir"` - CommandPrefix string `yaml:"command_prefix"` + Homeserver string `toml:"homeserver"` + UserID string `toml:"user_id"` + Password string `toml:"password"` + PickleKey string `toml:"pickle_key"` + DisplayName string `toml:"display_name"` + DataDir string `toml:"data_dir"` + CommandPrefix string `toml:"command_prefix"` // AllowedRooms is the set of room IDs the bot listens for commands in. // Messages in any other room are ignored. - AllowedRooms []string `yaml:"allowed_rooms"` + AllowedRooms []string `toml:"allowed_rooms"` } type ServicesConfig struct { - Radarr *ArrConfig `yaml:"radarr"` - Sonarr *ArrConfig `yaml:"sonarr"` - Lidarr *ArrConfig `yaml:"lidarr"` + Radarr *ArrConfig `toml:"radarr"` + Sonarr *ArrConfig `toml:"sonarr"` + Lidarr *ArrConfig `toml:"lidarr"` } type ArrConfig struct { - URL string `yaml:"url"` - APIKey string `yaml:"api_key"` - QualityProfileID int `yaml:"quality_profile_id"` - RootFolder string `yaml:"root_folder"` + URL string `toml:"url"` + APIKey string `toml:"api_key"` + QualityProfileID int `toml:"quality_profile_id"` + RootFolder string `toml:"root_folder"` // MetadataProfileID is required by Lidarr; ignored by Radarr/Sonarr. - MetadataProfileID int `yaml:"metadata_profile_id"` + MetadataProfileID int `toml:"metadata_profile_id"` } func Load(path string) (*Config, error) { @@ -60,7 +60,7 @@ func Load(path string) (*Config, error) { }) var cfg Config - if err := yaml.Unmarshal([]byte(expanded), &cfg); err != nil { + if _, err := toml.Decode(expanded, &cfg); err != nil { return nil, fmt.Errorf("parse config: %w", err) } diff --git a/main.go b/main.go index fe8ef1e..89823be 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( ) func main() { - configPath := flag.String("config", "config.yaml", "path to config file") + configPath := flag.String("config", "config.toml", "path to config file") flag.Parse() slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelInfo})))