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.
This commit is contained in:
@@ -18,4 +18,4 @@ COPY --from=build /out/bellhop /usr/local/bin/bellhop
|
|||||||
USER bellhop
|
USER bellhop
|
||||||
VOLUME ["/app/data"]
|
VOLUME ["/app/data"]
|
||||||
ENTRYPOINT ["/usr/local/bin/bellhop"]
|
ENTRYPOINT ["/usr/local/bin/bellhop"]
|
||||||
CMD ["-config", "/app/config.yaml"]
|
CMD ["-config", "/app/config.toml"]
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ Any member of an allowlisted room may issue commands. The bot auto-joins on invi
|
|||||||
|
|
||||||
## Configuration
|
## 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:
|
Required:
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ curl -H "X-Api-Key: YOUR_KEY" https://radarr.example.com/api/v3/qualityprofile
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
go build -tags goolm -o bellhop ./
|
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.
|
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 build -t bellhop .
|
||||||
docker run -d \
|
docker run -d \
|
||||||
--name bellhop \
|
--name bellhop \
|
||||||
-v "$PWD/config.yaml:/app/config.yaml:ro" \
|
-v "$PWD/config.toml:/app/config.toml:ro" \
|
||||||
-v bellhop-data:/app/data \
|
-v bellhop-data:/app/data \
|
||||||
bellhop
|
bellhop
|
||||||
```
|
```
|
||||||
@@ -70,7 +70,7 @@ The bot bootstraps cross-signing on first run and persists Olm/Megolm sessions i
|
|||||||
```
|
```
|
||||||
main.go
|
main.go
|
||||||
internal/
|
internal/
|
||||||
config/ — YAML loader with ${ENV_VAR} expansion
|
config/ — TOML loader with ${ENV_VAR} expansion
|
||||||
matrix/ — mautrix client: login, device persistence, E2EE, sync loop
|
matrix/ — mautrix client: login, device persistence, E2EE, sync loop
|
||||||
arr/ — Radarr/Sonarr/Lidarr HTTP clients
|
arr/ — Radarr/Sonarr/Lidarr HTTP clients
|
||||||
bot/ — command parser + dispatch + threaded replies
|
bot/ — command parser + dispatch + threaded replies
|
||||||
|
|||||||
43
config.example.toml
Normal file
43
config.example.toml
Normal file
@@ -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"
|
||||||
@@ -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
|
|
||||||
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module bellhop
|
|||||||
go 1.25.0
|
go 1.25.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
github.com/BurntSushi/toml v1.6.0
|
||||||
maunium.net/go/mautrix v0.28.0
|
maunium.net/go/mautrix v0.28.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,5 +1,7 @@
|
|||||||
filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo=
|
filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo=
|
||||||
filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc=
|
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 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
|
||||||
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
|
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=
|
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/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 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
|
||||||
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
|
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 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
maunium.net/go/mautrix v0.28.0 h1:vBakLzf8MAdfED3NzAKiMeKQbc3AQ4EAS03NC+TVMXQ=
|
maunium.net/go/mautrix v0.28.0 h1:vBakLzf8MAdfED3NzAKiMeKQbc3AQ4EAS03NC+TVMXQ=
|
||||||
|
|||||||
@@ -6,42 +6,42 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"github.com/BurntSushi/toml"
|
||||||
)
|
)
|
||||||
|
|
||||||
var envBracketRe = regexp.MustCompile(`\$\{([^}]+)\}`)
|
var envBracketRe = regexp.MustCompile(`\$\{([^}]+)\}`)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Matrix MatrixConfig `yaml:"matrix"`
|
Matrix MatrixConfig `toml:"matrix"`
|
||||||
Services ServicesConfig `yaml:"services"`
|
Services ServicesConfig `toml:"services"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MatrixConfig struct {
|
type MatrixConfig struct {
|
||||||
Homeserver string `yaml:"homeserver"`
|
Homeserver string `toml:"homeserver"`
|
||||||
UserID string `yaml:"user_id"`
|
UserID string `toml:"user_id"`
|
||||||
Password string `yaml:"password"`
|
Password string `toml:"password"`
|
||||||
PickleKey string `yaml:"pickle_key"`
|
PickleKey string `toml:"pickle_key"`
|
||||||
DisplayName string `yaml:"display_name"`
|
DisplayName string `toml:"display_name"`
|
||||||
DataDir string `yaml:"data_dir"`
|
DataDir string `toml:"data_dir"`
|
||||||
CommandPrefix string `yaml:"command_prefix"`
|
CommandPrefix string `toml:"command_prefix"`
|
||||||
// AllowedRooms is the set of room IDs the bot listens for commands in.
|
// AllowedRooms is the set of room IDs the bot listens for commands in.
|
||||||
// Messages in any other room are ignored.
|
// Messages in any other room are ignored.
|
||||||
AllowedRooms []string `yaml:"allowed_rooms"`
|
AllowedRooms []string `toml:"allowed_rooms"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServicesConfig struct {
|
type ServicesConfig struct {
|
||||||
Radarr *ArrConfig `yaml:"radarr"`
|
Radarr *ArrConfig `toml:"radarr"`
|
||||||
Sonarr *ArrConfig `yaml:"sonarr"`
|
Sonarr *ArrConfig `toml:"sonarr"`
|
||||||
Lidarr *ArrConfig `yaml:"lidarr"`
|
Lidarr *ArrConfig `toml:"lidarr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArrConfig struct {
|
type ArrConfig struct {
|
||||||
URL string `yaml:"url"`
|
URL string `toml:"url"`
|
||||||
APIKey string `yaml:"api_key"`
|
APIKey string `toml:"api_key"`
|
||||||
QualityProfileID int `yaml:"quality_profile_id"`
|
QualityProfileID int `toml:"quality_profile_id"`
|
||||||
RootFolder string `yaml:"root_folder"`
|
RootFolder string `toml:"root_folder"`
|
||||||
// MetadataProfileID is required by Lidarr; ignored by Radarr/Sonarr.
|
// 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) {
|
func Load(path string) (*Config, error) {
|
||||||
@@ -60,7 +60,7 @@ func Load(path string) (*Config, error) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
var cfg Config
|
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)
|
return nil, fmt.Errorf("parse config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
configPath := flag.String("config", "config.yaml", "path to config file")
|
configPath := flag.String("config", "config.toml", "path to config file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelInfo})))
|
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelInfo})))
|
||||||
|
|||||||
Reference in New Issue
Block a user