From 32cb8dd873ed15cbf403c0c698240cdced66d8e2 Mon Sep 17 00:00:00 2001 From: jamesread Date: Thu, 29 Feb 2024 23:20:48 +0000 Subject: [PATCH] feature: entity filepaths are relative to the config dir --- config.yaml | 4 ++-- internal/entityfiles/entityfiles.go | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/config.yaml b/config.yaml index abd604f..e40185a 100644 --- a/config.yaml +++ b/config.yaml @@ -207,10 +207,10 @@ entities: # will load properly. # # Docs: https://docs.olivetin.app/entities.html - - file: /etc/OliveTin/entities/servers.yaml + - file: entities/servers.yaml name: server - - file: /etc/OliveTin/entities/containers.json + - file: entities/containers.json name: container # Dashboards are a way of taking actions from the default "actions" view, and diff --git a/internal/entityfiles/entityfiles.go b/internal/entityfiles/entityfiles.go index ae96823..08c681a 100644 --- a/internal/entityfiles/entityfiles.go +++ b/internal/entityfiles/entityfiles.go @@ -8,15 +8,30 @@ import ( sv "github.com/OliveTin/OliveTin/internal/stringvariables" "github.com/fsnotify/fsnotify" log "github.com/sirupsen/logrus" + "github.com/spf13/viper" "gopkg.in/yaml.v3" "io/ioutil" + "path/filepath" "strings" ) func SetupEntityFileWatchers(cfg *config.Config) { + configDir := filepath.Dir(viper.ConfigFileUsed()) + for _, ef := range cfg.Entities { - go watch(ef.File, ef.Name) - loadEntityFile(ef.File, ef.Name) + p := ef.File + + if !filepath.IsAbs(p) { + p = filepath.Join(configDir, p) + + log.WithFields(log.Fields{ + "entityFile": p, + }).Debugf("Adding config dir to entity file path") + } + + go watch(p, ef.Name) + + loadEntityFile(p, ef.Name) } }